admin.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. from django.utils.translation import ugettext_lazy as _
  2. from misago.core import forms
  3. from misago.core.validators import validate_sluggable
  4. from misago.acl.models import Role
  5. from misago.users.models import Rank
  6. class RankForm(forms.ModelForm):
  7. name = forms.CharField(
  8. label=_("Name"),
  9. validators=[validate_sluggable()],
  10. help_text=_('Short and descriptive name of all users with this rank. '
  11. '"The Team" or "Game Masters" are good examples.'))
  12. title = forms.CharField(
  13. label=_("User title"), required=False,
  14. help_text=_('Optional, singular version of rank name displayed by '
  15. 'user names. For example "GM" or "Dev".'))
  16. description = forms.CharField(
  17. label=_("Description"), max_length=1024, required=False,
  18. widget=forms.Textarea(attrs={'rows': 3}),
  19. help_text=_("Optional description explaining function or status of "
  20. "members distincted with this rank."))
  21. roles = forms.ModelMultipleChoiceField(
  22. label=_("User roles"), queryset=Role.objects.order_by('name'),
  23. required=False, widget=forms.CheckboxSelectMultiple,
  24. help_text=_('Rank can give users with it additional roles.'))
  25. style = forms.CharField(
  26. label=_("CSS class"), required=False,
  27. help_text=_("Optional css class added to content belonging to this "
  28. "rank owner."))
  29. is_tab = forms.BooleanField(
  30. label=_("Give rank dedicated tab on users list"), required=False,
  31. help_text=_("Selecting this option will make users with this rank "
  32. "easily discoverable by others trough dedicated page on "
  33. "forum users list."))
  34. is_on_index = forms.BooleanField(
  35. label=_("Show users online on forum index"), required=False,
  36. help_text=_("Selecting this option will make forum inform other "
  37. "users of their availability by displaying them on forum "
  38. "index page."))
  39. class Meta:
  40. model = Rank
  41. fields = [
  42. 'name',
  43. 'description',
  44. 'style',
  45. 'title',
  46. 'roles',
  47. 'is_tab',
  48. 'is_on_index',
  49. ]
  50. def clean_name(self):
  51. data = self.cleaned_data['name']
  52. self.instance.set_name(data)
  53. return data