Exemplo n.º 1
0
 def clean_image(self,
                 fieldname="image",
                 maxsizemb=settings.EVENT_IMAGE_MAX_SIZE_MB):
     img = self.cleaned_data.get(fieldname, None)
     if img:
         if hasattr(img, 'name'):
             fname, ext = os.path.splitext(img.name)
             if not ext:
                 raise forms.ValidationError(
                     _(u'The file you have uploaded does not have an extension. Only JPEG and PNG images with the file extensions .jpeg, .jpg, or .png are accepted.'
                       ))
             if not (ext.lower() in ('.jpeg', '.png', '.jpg')
                     and get_image_format(img) in ('JPEG', 'PNG')):
                 raise forms.ValidationError(
                     _(u'The file you have uploaded is not an acceptable image. Only JPEG and PNG images are accepted.'
                       ))
             if img.size > maxsizemb * 1000000:
                 sz = img.size / 1000000
                 raise forms.ValidationError(
                     _(u"The image file you have uploaded is too big. Please upload a file under %s MB."
                       ) % int(maxsizemb))
             if img.size == 0:
                 raise forms.ValidationError(
                     _(u"The image file you have uploaded is empty. Please upload a real image."
                       ))
     return img
Exemplo n.º 2
0
 def clean_image(self, fieldname="image", maxsizemb=settings.EVENT_IMAGE_MAX_SIZE_MB):
     img = self.cleaned_data.get(fieldname, None)
     if img:
         if hasattr(img, "name"):
             fname, ext = os.path.splitext(img.name)
             if not ext:
                 raise forms.ValidationError(
                     _(
                         u"The file you have uploaded does not have an extension. Only JPEG and PNG images with the file extensions .jpeg, .jpg, or .png are accepted."
                     )
                 )
             if not (ext.lower() in (".jpeg", ".png", ".jpg") and get_image_format(img) in ("JPEG", "PNG")):
                 raise forms.ValidationError(
                     _(
                         u"The file you have uploaded is not an acceptable image. Only JPEG and PNG images are accepted."
                     )
                 )
             if img.size > maxsizemb * 1000000:
                 sz = img.size / 1000000
                 raise forms.ValidationError(
                     _(u"The image file you have uploaded is too big. Please upload a file under %s MB.")
                     % int(maxsizemb)
                 )
             if img.size == 0:
                 raise forms.ValidationError(
                     _(u"The image file you have uploaded is empty. Please upload a real image.")
                 )
     return img
Exemplo n.º 3
0
 def clean_image(self):
     img = self.cleaned_data["image"]
     if img and hasattr(img, 'name'):
         fname, ext = os.path.splitext(img.name)
         if not ext:
             raise forms.ValidationError(_(u'The file you have uploaded does not have an extension. Only JPEG and PNG images with the file extensions .jpeg, .jpg, or .png are accepted.'))
         if not (ext.lower() in ('.jpeg', '.png', '.jpg') and get_image_format(img) in ('JPEG', 'PNG')):
             raise forms.ValidationError(_(u'The file you have uploaded is not an acceptable image. Only JPEG and PNG images are accepted.'))
         if img.size > settings.PHOTO_MAX_SIZE_MB*1000000:
             sz = img.size / 1000000
             raise forms.ValidationError(_(u"The image file you have uploaded is too big. Please upload a file under %s MB.") % int(settings.PHOTO_MAX_SIZE_MB))
         if img.size == 0:
             raise forms.ValidationError(_(u"The image file you have uploaded is empty. Please upload a real image."))
     return img
Exemplo n.º 4
0
 def clean_image(self):
     img = self.cleaned_data["image"]
     if hasattr(img, 'name'):
         fname, ext = os.path.splitext(img.name)
         if not ext:
             raise forms.ValidationError(_(u'The file you have uploaded does not have an extension. Only JPEG and PNG images with the file extensions .jpeg, .jpg, or .png are accepted.'))
         if not (ext.lower() in ('.jpeg', '.png', '.jpg') and get_image_format(img) in ('JPEG', 'PNG')):
             raise forms.ValidationError(_(u'The file you have uploaded is not an acceptable image. Only JPEG and PNG images are accepted.'))
         if img.size > settings.CAMPAIGN_IMAGE_MAX_SIZE_MB*1000000:
             sz = img.size / 1000000
             raise forms.ValidationError(_(u"The image file you have uploaded is too big. Please upload a file under %s MB.") % int(settings.CAMPAIGN_IMAGE_MAX_SIZE_MB))
         aspect = get_image_aspect(img)
         if aspect != 'landscape':
             raise forms.ValidationError(_(u"A %s format image like this one doesn't work well with campaign badges. Please upload a landscape format image (width > height)." % aspect))
     return img
Exemplo n.º 5
0
 def clean_image(self):
     img = self.cleaned_data.get("image", None)
     if img and hasattr(img, 'name'):
         fname, ext = os.path.splitext(img.name)
         if not ext:
             raise forms.ValidationError(
                 _(u'The file you have uploaded does not have an extension. Only JPEG and PNG images with the file extensions .jpeg, .jpg, or .png are accepted.'
                   ))
         if not (ext.lower() in ('.jpeg', '.png', '.jpg')
                 and get_image_format(img) in ('JPEG', 'PNG')):
             raise forms.ValidationError(
                 _(u'The file you have uploaded is not an acceptable image. Only JPEG and PNG images are accepted.'
                   ))
         if img.size > settings.AVATAR_IMAGE_MAX_SIZE_MB * 1000000:
             sz = img.size / 1000000
             raise forms.ValidationError(
                 _(u"The profile image file you have uploaded is too big. Please upload a file under %s MB."
                   ) % int(settings.AVATAR_IMAGE_MAX_SIZE_MB))
         if img.size == 0:
             raise forms.ValidationError(
                 _(u"The uploaded profile image file seems to have been corrupted. Please try again."
                   ))
     return img
Exemplo n.º 6
0
 def clean_image(self):
     img = self.cleaned_data["image"]
     if hasattr(img, 'name'):
         fname, ext = os.path.splitext(img.name)
         if not ext:
             raise forms.ValidationError(
                 _(u'The file you have uploaded does not have an extension. Only JPEG and PNG images with the file extensions .jpeg, .jpg, or .png are accepted.'
                   ))
         if not (ext.lower() in ('.jpeg', '.png', '.jpg')
                 and get_image_format(img) in ('JPEG', 'PNG')):
             raise forms.ValidationError(
                 _(u'The file you have uploaded is not an acceptable image. Only JPEG and PNG images are accepted.'
                   ))
         if img.size > settings.CAMPAIGN_IMAGE_MAX_SIZE_MB * 1000000:
             sz = img.size / 1000000
             raise forms.ValidationError(
                 _(u"The image file you have uploaded is too big. Please upload a file under %s MB."
                   ) % int(settings.CAMPAIGN_IMAGE_MAX_SIZE_MB))
         aspect = get_image_aspect(img)
         if aspect != 'landscape':
             raise forms.ValidationError(
                 _(u"A %s format image like this one doesn't work well with campaign badges. Please upload a landscape format image (width > height)."
                   % aspect))
     return img