You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

56 lines
1.4 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
9 years ago
9 years ago
  1. from datetime import timedelta as td
  2. from django import forms
  3. from django.contrib.auth.models import User
  4. class LowercaseEmailField(forms.EmailField):
  5. def clean(self, value):
  6. value = super(LowercaseEmailField, self).clean(value)
  7. return value.lower()
  8. class EmailPasswordForm(forms.Form):
  9. email = LowercaseEmailField()
  10. password = forms.CharField(required=False)
  11. class ReportSettingsForm(forms.Form):
  12. reports_allowed = forms.BooleanField(required=False)
  13. nag_period = forms.IntegerField(min_value=0, max_value=86400)
  14. def clean_nag_period(self):
  15. seconds = self.cleaned_data["nag_period"]
  16. if seconds not in (0, 3600, 86400):
  17. raise forms.ValidationError("Bad nag_period: %d" % seconds)
  18. return td(seconds=seconds)
  19. class SetPasswordForm(forms.Form):
  20. password = forms.CharField()
  21. class ChangeEmailForm(forms.Form):
  22. error_css_class = "has-error"
  23. email = LowercaseEmailField()
  24. def clean_email(self):
  25. v = self.cleaned_data["email"]
  26. if User.objects.filter(email=v).exists():
  27. raise forms.ValidationError("%s is not available" % v)
  28. return v
  29. class InviteTeamMemberForm(forms.Form):
  30. email = LowercaseEmailField()
  31. class RemoveTeamMemberForm(forms.Form):
  32. email = LowercaseEmailField()
  33. class TeamNameForm(forms.Form):
  34. team_name = forms.CharField(max_length=200, required=True)