usercp.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. from django.contrib.auth import get_user_model
  2. from django.utils.translation import ugettext_lazy as _
  3. from misago.core import forms, timezones
  4. from misago.users.models import (PRESENCE_VISIBILITY_CHOICES,
  5. AUTO_SUBSCRIBE_CHOICES)
  6. class ChangeForumOptionsBaseForm(forms.ModelForm):
  7. timezone = forms.ChoiceField(
  8. label=_("Your current timezone"), choices=[],
  9. help_text=_("If dates and hours displayed by forums are inaccurate, "
  10. "you can fix it by adjusting timezone setting."))
  11. presence_visibility = forms.TypedChoiceField(
  12. label=_("Show my presence to"),
  13. choices=PRESENCE_VISIBILITY_CHOICES, coerce=int,
  14. help_text=_("If you want to, you can limit other members ability to "
  15. "track your presence on forums."))
  16. subscribe_to_started_threads = forms.TypedChoiceField(
  17. label=_("Threads I start"), coerce=int, choices=AUTO_SUBSCRIBE_CHOICES)
  18. subscribe_to_replied_threads = forms.TypedChoiceField(
  19. label=_("Threads I reply to"), coerce=int,
  20. choices=AUTO_SUBSCRIBE_CHOICES)
  21. class Meta:
  22. model = get_user_model()
  23. fields = ['timezone', 'presence_visibility',
  24. 'subscribe_to_started_threads',
  25. 'subscribe_to_replied_threads']
  26. def ChangeForumOptionsForm(*args, **kwargs):
  27. timezone = forms.ChoiceField(
  28. label=_("Your current timezone"), choices=timezones.choices(),
  29. help_text=_("If dates and hours displayed by forums are inaccurate, "
  30. "you can fix it by adjusting timezone setting."))
  31. FinalFormType = type('FinalChangeForumOptionsForm',
  32. (ChangeForumOptionsBaseForm,),
  33. {'timezone': timezone})
  34. return FinalFormType(*args, **kwargs)
  35. class ChangeUsernameForm(forms.ModelForm):
  36. class Meta:
  37. model = get_user_model()
  38. fields = ['username', 'email', 'title']
  39. class ChangeEmailPasswordForm(forms.ModelForm):
  40. class Meta:
  41. model = get_user_model()
  42. fields = ['username', 'email', 'title']