I have a Model with an ImageField, and the use case I am interested in is 
that instead of the user uploading an image file from their computer, they 
will "paste" the contents of their clipboard (e.g. they took a screenshot 
using PrintScreen) into this field.

Using the helpful information at
http://www.taylorsteil.com/?p=17
I was able to get this basic functionality working, using my own defined 
views and handling of POST data.  What I would like to do now is to more 
tightly integrate it into the Django admin framework.

More specifically, what I was able to do right now is present to the user a 
form similar to
http://supa.sourceforge.net/demo.php
where after the user pastes the clipboard contents and presses "upload", I 
create a new object in my database with this image.
In more detail, 
1. When the user presses "paste" the image contents of the clipboard are 
pasted into the Java applet
2. When the user presses "upload", this calls javascript code which extracts 
the bitmap data from from Java applet, and manually constructs an HTTP 
request containing the image encoded in base-64.  This is sent as POST to 
another URL of my choice.
3. The view receiving the request takes the image data from request.FILES, 
uses b64decode, and then creates a ContentFile using this data (see 
taylorsteil's blog post).  I am then able to save this into the database.

So while the above functionality works using my custom views, this doesn't 
help me if I am adding/editing objects through the admin interface.  I've 
figured out how to override the default ImageField widget (which just shows 
a text field + "Browse" buttom) with a widget that also displays a 
thumbnail, and even incorporate the Supa.jar applet and the "paste" 
mechanism (which goes as far as getting the clipboard data into the Java 
applet).  This is all by overriding the "render" method.

But I can't figure out how to incorporate the rest of the flow.  When the 
user presses "Save" to update the object in the admin form, I need to 
extract the image data from the applet, and pass the data through the file 
upload mechanism to the server...  But since I am working within the 
constraints of the admin framework, and not defining my own POST request or 
POST handler, I am not sure how to do this...  Also the solution will have 
to somehow span both javascript and python, since it seems the image data 
from the Java applet can only be accessed through javascript(?).

Any help would be appreciated.  And of course if there are ready solutions 
for all of the above, I would be glad to try them out.

Thanks,
Eran.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to