Commit 47e92d08e06bcc0111db0536c109d19bbab8e1eb

Authored by Zambom
1 parent 9daae87c

Fixing bugs in image validation

users/forms.py
@@ -12,8 +12,9 @@ class Validation(forms.ModelForm): @@ -12,8 +12,9 @@ class Validation(forms.ModelForm):
12 image = self.cleaned_data.get('image', False) 12 image = self.cleaned_data.get('image', False)
13 13
14 if image: 14 if image:
15 - if image._size > self.MAX_UPLOAD_SIZE:  
16 - raise forms.ValidationError(_("The image is too large. It should have less than 2MB.")) 15 + if hasattr(image, '_size'):
  16 + if image._size > self.MAX_UPLOAD_SIZE:
  17 + raise forms.ValidationError(_("The image is too large. It should have less than 2MB."))
17 18
18 return image 19 return image
19 20
users/models.py
@@ -10,8 +10,9 @@ from django.contrib.staticfiles.templatetags.staticfiles import static @@ -10,8 +10,9 @@ from django.contrib.staticfiles.templatetags.staticfiles import static
10 def validate_img_extension(value): 10 def validate_img_extension(value):
11 valid_formats = ['image/jpeg','image/x-citrix-jpeg','image/png','image/x-citrix-png','image/x-png'] 11 valid_formats = ['image/jpeg','image/x-citrix-jpeg','image/png','image/x-citrix-png','image/x-png']
12 12
13 - if not value.file.content_type in valid_formats:  
14 - raise ValidationError(_('File not supported.')) 13 + if hasattr(value.file, 'content_type'):
  14 + if not value.file.content_type in valid_formats:
  15 + raise ValidationError(_('File not supported.'))
15 16
16 class User(AbstractBaseUser, PermissionsMixin): 17 class User(AbstractBaseUser, PermissionsMixin):
17 18
users/templates/users/profile.html
@@ -54,10 +54,12 @@ @@ -54,10 +54,12 @@
54 </div> 54 </div>
55 </div> 55 </div>
56 </div> 56 </div>
  57 + <br clear="all" />
  58 + <hr />
57 <div class="row-fluid"> 59 <div class="row-fluid">
58 <label class="control-form">{% trans 'Description' %}:</label> 60 <label class="control-form">{% trans 'Description' %}:</label>
59 <div class="col-md-12"> 61 <div class="col-md-12">
60 - {{ user.description|default:_("Not Informed")|linebreaks }} 62 + {{ user.description|default:_("Not Informed") }}
61 </div> 63 </div>
62 </div> 64 </div>
63 </div> 65 </div>