From 47e92d08e06bcc0111db0536c109d19bbab8e1eb Mon Sep 17 00:00:00 2001 From: Zambom Date: Fri, 23 Dec 2016 14:52:18 -0200 Subject: [PATCH] Fixing bugs in image validation --- users/forms.py | 5 +++-- users/models.py | 5 +++-- users/templates/users/profile.html | 4 +++- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/users/forms.py b/users/forms.py index 1195ed0..2fa24ed 100644 --- a/users/forms.py +++ b/users/forms.py @@ -12,8 +12,9 @@ class Validation(forms.ModelForm): image = self.cleaned_data.get('image', False) if image: - if image._size > self.MAX_UPLOAD_SIZE: - raise forms.ValidationError(_("The image is too large. It should have less than 2MB.")) + if hasattr(image, '_size'): + if image._size > self.MAX_UPLOAD_SIZE: + raise forms.ValidationError(_("The image is too large. It should have less than 2MB.")) return image diff --git a/users/models.py b/users/models.py index 0f6587a..c540c64 100644 --- a/users/models.py +++ b/users/models.py @@ -10,8 +10,9 @@ from django.contrib.staticfiles.templatetags.staticfiles import static def validate_img_extension(value): valid_formats = ['image/jpeg','image/x-citrix-jpeg','image/png','image/x-citrix-png','image/x-png'] - if not value.file.content_type in valid_formats: - raise ValidationError(_('File not supported.')) + if hasattr(value.file, 'content_type'): + if not value.file.content_type in valid_formats: + raise ValidationError(_('File not supported.')) class User(AbstractBaseUser, PermissionsMixin): diff --git a/users/templates/users/profile.html b/users/templates/users/profile.html index 6dda048..1d39726 100644 --- a/users/templates/users/profile.html +++ b/users/templates/users/profile.html @@ -54,10 +54,12 @@ +
+
- {{ user.description|default:_("Not Informed")|linebreaks }} + {{ user.description|default:_("Not Informed") }}
-- libgit2 0.21.2