This is probably all just a result of lack of experience, poor
programming practices and knowledge, but I thought I'd share this
little bit of information.

My code to validate picture data posted below.
My quick commentary on it is that it works 100% for fire fox, safari.
But images won't validate with IE.  I thought this might have to do
with the accept-chartype.  But I was dead wrong.
On the split of image and sub --- IE calls jpegs, pjpeg!!!
PJPEG?!!!

So I added that as one of my allowable file types and it works now,
the validation doesn't ping off.  Are there other image file types
that are named awkwardly like this?


        def clean_photo(self):
                if self.clean_data.get('photo'):
                        photo_data = self.clean_data['photo']
                        if 'error' in photo_data:
                                raise forms.ValidationError(_('Upload a valid 
image.  The file you
uploaded was either not an image or a corrupted image'))

                        content_type = photo_data.get('content-type')
                        if content_type:
                                main,sub = content_type.split('/')
                                if not (main == 'image' and sub in 
['jpeg','gif','png','jpg']):
                                        raise 
forms.ValidationError(_('JPEG,GIF,PNG only.'))

                        size = len(photo_data['content'])
                        if size > settings.MAX_PHOTO_UPLOAD_SIZE * 1024:
                                raise forms.ValidationError(_('Image too big'))

                        width, height = photo_data['dimensions']
                        if width > settings.MAX_PHOTO_WIDTH:
                                raise forms.ValidationError(_('Max width is %s' 
%
settings.MAX_PHOTO_WIDTH))
                        if height > settings.MAX_PHOTO_HEIGHT:
                                raise forms.ValidationError(_('Max height is 
%s' %
settings.MAX_PHOTO_HEIGHT))
                return self.clean_data['photo']



--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to