admin.py 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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.users.models import Rank
  5. class RankForm(forms.ModelForm):
  6. name = forms.CharField(
  7. label=_("Name"),
  8. validators=[validate_sluggable()],
  9. help_text=_('Short and descriptive name of all users with this rank. '
  10. '"The Team" or "Game Masters" are good examples.'))
  11. title = forms.CharField(
  12. label=_("User title"), required=False,
  13. help_text=_('Optional, singular version of rank name displayed by '
  14. 'user names. For example "GM" or "Dev".'))
  15. description = forms.CharField(
  16. label=_("Description"), max_length=1024, required=False,
  17. widget=forms.Textarea(attrs={'rows': 3}),
  18. help_text=_("Optional description explaining function or status of "
  19. "members distincted with this rank."))
  20. style = forms.CharField(
  21. label=_("CSS Class"), required=False,
  22. help_text=_("Optional css class added to content belonging to this "
  23. "rank owner."))
  24. is_tab = forms.BooleanField(
  25. label=_("Give rank dedicated tab on users list"), required=False,
  26. help_text=_("Selecting this option will make users with this rank "
  27. "easily discoverable by others trough dedicated page on "
  28. "forum users list."))
  29. is_on_index = forms.BooleanField(
  30. label=_("Show users online on forum index"), required=False,
  31. help_text=_("Selecting this option will make forum inform other "
  32. "users of their availability by displaying them on forum "
  33. "index page."))
  34. class Meta:
  35. model = Rank
  36. fields = [
  37. 'name', 'description', 'style', 'title', 'is_tab', 'is_on_index'
  38. ]
  39. def clean_name(self):
  40. data = self.cleaned_data['name']
  41. self.instance.set_name(data)
  42. return data