|
|
@ -8,7 +8,7 @@ from django.contrib.auth import authenticate |
|
|
|
from django.contrib.auth.models import User |
|
|
|
from hc.accounts.models import REPORT_CHOICES |
|
|
|
from hc.api.models import TokenBucket |
|
|
|
from hc.front.validators import TimezoneValidator |
|
|
|
import pytz |
|
|
|
|
|
|
|
|
|
|
|
class LowercaseEmailField(forms.EmailField): |
|
|
@ -88,7 +88,7 @@ class PasswordLoginForm(forms.Form): |
|
|
|
class ReportSettingsForm(forms.Form): |
|
|
|
reports = forms.ChoiceField(choices=REPORT_CHOICES) |
|
|
|
nag_period = forms.IntegerField(min_value=0, max_value=86400) |
|
|
|
tz = forms.CharField(max_length=36, validators=[TimezoneValidator()]) |
|
|
|
tz = forms.CharField() |
|
|
|
|
|
|
|
def clean_nag_period(self): |
|
|
|
seconds = self.cleaned_data["nag_period"] |
|
|
@ -98,6 +98,15 @@ class ReportSettingsForm(forms.Form): |
|
|
|
|
|
|
|
return td(seconds=seconds) |
|
|
|
|
|
|
|
def clean_tz(self): |
|
|
|
# Declare tz as "clean" only if we can find it in pytz.all_timezones |
|
|
|
if self.cleaned_data["tz"] in pytz.all_timezones: |
|
|
|
return self.cleaned_data["tz"] |
|
|
|
|
|
|
|
# Otherwise, return None, and *don't* throw a validation exception: |
|
|
|
# If user's browser reports a timezone we don't recognize, we |
|
|
|
# should ignore the timezone but still save the rest of the form. |
|
|
|
|
|
|
|
|
|
|
|
class SetPasswordForm(forms.Form): |
|
|
|
password = forms.CharField(min_length=8) |
|
|
|