Mercurial > public > sg101
comparison bio/forms.py @ 1011:164a39d985ef
Perform SSL image_check on profile text fields.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Fri, 27 Nov 2015 15:45:05 -0600 |
parents | 4f265f61874b |
children | 21c592cac71c |
comparison
equal
deleted
inserted
replaced
1010:9afe0610aae5 | 1011:164a39d985ef |
---|---|
12 from django.contrib.auth.models import User | 12 from django.contrib.auth.models import User |
13 | 13 |
14 import pytz | 14 import pytz |
15 | 15 |
16 from bio.models import UserProfile | 16 from bio.models import UserProfile |
17 from core.html import image_check | |
18 from core.html import ImageCheckError | |
19 from core.images.utils import parse_image, downscale_image_square | |
20 from core.markup import site_markup | |
17 from core.widgets import AutoCompleteUserInput | 21 from core.widgets import AutoCompleteUserInput |
18 from core.images.utils import parse_image, downscale_image_square | |
19 | 22 |
20 | 23 |
21 class EditUserForm(forms.ModelForm): | 24 class EditUserForm(forms.ModelForm): |
22 """Form for editing the fields of the User model.""" | 25 """Form for editing the fields of the User model.""" |
23 email = forms.EmailField(label='Email', required=True) | 26 email = forms.EmailField(label='Email', required=True) |
57 settings.GPP_THIRD_PARTY_JS['jquery-ui'] + | 60 settings.GPP_THIRD_PARTY_JS['jquery-ui'] + |
58 ['js/bio.js', 'js/timezone.js']) | 61 ['js/bio.js', 'js/timezone.js']) |
59 | 62 |
60 def clean_time_zone(self): | 63 def clean_time_zone(self): |
61 """Ensure the timezone is valid and will work with pytz. | 64 """Ensure the timezone is valid and will work with pytz. |
62 | 65 |
63 A blank (empty) value is allowed. | 66 A blank (empty) value is allowed. |
64 """ | 67 """ |
65 | 68 |
66 tz = self.cleaned_data['time_zone'].strip() | 69 tz = self.cleaned_data['time_zone'].strip() |
67 if tz: | 70 if tz: |
69 pytz.timezone(tz) | 72 pytz.timezone(tz) |
70 except pytz.UnknownTimeZoneError: | 73 except pytz.UnknownTimeZoneError: |
71 raise forms.ValidationError('Invalid timezone') | 74 raise forms.ValidationError('Invalid timezone') |
72 | 75 |
73 return tz | 76 return tz |
77 | |
78 def _image_check(self, field_name): | |
79 text = self.cleaned_data[field_name] | |
80 if text: | |
81 html = site_markup(text) | |
82 try: | |
83 image_check(html) | |
84 except ImageCheckError as ex: | |
85 raise forms.ValidationError(str(ex)) | |
86 return text | |
87 | |
88 def clean_profile_text(self): | |
89 return self._image_check('profile_text') | |
90 | |
91 def clean_signature(self): | |
92 return self._image_check('signature') | |
74 | 93 |
75 | 94 |
76 class UploadAvatarForm(forms.Form): | 95 class UploadAvatarForm(forms.Form): |
77 """Form used to change a user's avatar""" | 96 """Form used to change a user's avatar""" |
78 avatar_file = forms.ImageField(required=False) | 97 avatar_file = forms.ImageField(required=False) |