#3297: newforms: Implement FileField and ImageField
---------------------------------------+------------------------------------
Reporter: [EMAIL PROTECTED] | Owner: russellm
Status: new | Component: django.newforms
Version: SVN | Resolution:
Keywords: newforms | Stage: Accepted
Has_patch: 1 | Needs_docs: 0
Needs_tests: 0 | Needs_better_patch: 1
---------------------------------------+------------------------------------
Changes (by Fidel Ramos):
* cc: [EMAIL PROTECTED] (added)
Comment:
There's a bug in
[attachment:filefield_with_newforms_admin_integration_cleaner.diff this
patch]. The clean method of ImageField is defined as:
{{{
class ImageField(FileField):
def clean(self, data):
"""
Checks that the file-upload field data contains a valid image
(GIF, JPG,
PNG, possibly others -- whatever the Python Imaging Library
supports).
"""
f = super(ImageField, self).clean(data)
from PIL import Image
from cStringIO import StringIO
try:
Image.open(StringIO(f.content))
except IOError: # Python Imaging Library doesn't recognize it as
an image
raise ValidationError(gettext(u"Upload a valid image. The file
you uploaded was either not an image or a corrupted image."))
return f
}}}
I have a newforms with a not required ImageField, but if it's validated
without uploading a file it fails with the following exception:
{{{
Exception Type: AttributeError
Exception Value: 'NoneType' object has no attribute 'content'
Exception Location: /usr/lib/python2.4/site-
packages/django/newforms/fields.py in clean, line 396
}}}
The fix is checking that we have a file before passing it to PIL. My
colleague Manuel Saelices has just uploaded an
[attachment:filefield_with_newforms_admin_integration_cleaner_updated_and_corrected.2.diff
updated patch] where this bug is fixed. Note there are some minor problems
when applying the patch to django trunk, because it was made in the
newforms-admin branch, to keep compatibility with previous patches.
--
Ticket URL: <http://code.djangoproject.net/ticket/3297#comment:60>
Django Code <http://code.djangoproject.com/>
The web framework for perfectionists with deadlines
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---