Mercurial > public > sg101
comparison bio/forms.py @ 612:5be850a66dfc
For BB issue 17, validate timezone values when saving user profiles.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sun, 12 Aug 2012 09:34:56 -0500 |
parents | 678a1a2ef55a |
children | 4f265f61874b |
comparison
equal
deleted
inserted
replaced
611:8b9fc7487222 | 612:5be850a66dfc |
---|---|
8 | 8 |
9 from django import forms | 9 from django import forms |
10 from django.conf import settings | 10 from django.conf import settings |
11 from django.core.files.base import ContentFile | 11 from django.core.files.base import ContentFile |
12 from django.contrib.auth.models import User | 12 from django.contrib.auth.models import User |
13 | |
14 import pytz | |
13 | 15 |
14 from bio.models import UserProfile | 16 from bio.models import UserProfile |
15 from core.widgets import AutoCompleteUserInput | 17 from core.widgets import AutoCompleteUserInput |
16 from core.image import parse_image, downscale_image_square | 18 from core.image import parse_image, downscale_image_square |
17 | 19 |
52 settings.GPP_THIRD_PARTY_CSS['jquery-ui']) | 54 settings.GPP_THIRD_PARTY_CSS['jquery-ui']) |
53 } | 55 } |
54 js = (settings.GPP_THIRD_PARTY_JS['markitup'] + | 56 js = (settings.GPP_THIRD_PARTY_JS['markitup'] + |
55 settings.GPP_THIRD_PARTY_JS['jquery-ui'] + | 57 settings.GPP_THIRD_PARTY_JS['jquery-ui'] + |
56 ['js/bio.js', 'js/timezone.js']) | 58 ['js/bio.js', 'js/timezone.js']) |
59 | |
60 def clean_time_zone(self): | |
61 """Ensure the timezone is valid and will work with pytz. | |
62 | |
63 A blank (empty) value is allowed. | |
64 """ | |
65 | |
66 tz = self.cleaned_data['time_zone'].strip() | |
67 if tz: | |
68 try: | |
69 pytz.timezone(tz) | |
70 except pytz.UnknownTimeZoneError: | |
71 raise forms.ValidationError('Invalid timezone') | |
72 | |
73 return tz | |
57 | 74 |
58 | 75 |
59 class UploadAvatarForm(forms.Form): | 76 class UploadAvatarForm(forms.Form): |
60 """Form used to change a user's avatar""" | 77 """Form used to change a user's avatar""" |
61 avatar_file = forms.ImageField(required=False) | 78 avatar_file = forms.ImageField(required=False) |