forms.py 1.3 KB

123456789101112131415161718192021222324
  1. from django.utils.translation import ugettext_lazy as _
  2. import floppyforms as forms
  3. from misago.forms import Form, ForumMultipleChoiceField
  4. from misago.models import Forum
  5. from misago.validators import validate_sluggable
  6. class PrefixFormBase(Form):
  7. name = forms.CharField(label=_("Prefix Name"),
  8. max_length=16, validators=[validate_sluggable(
  9. _("Prefix must contain alphanumeric characters."),
  10. _("Prefix name is too long.")
  11. )])
  12. style = forms.CharField(label=_("Prefix CSS Class"),
  13. help_text=_("CSS class that will be used to style this thread prefix."),
  14. max_length=255, required=False)
  15. def PrefixForm(*args, **kwargs):
  16. forums = ForumMultipleChoiceField(label=_("Prefix Forums"),
  17. help_text=_("Select forums in which this prefix will be available."),
  18. level_indicator=u'- - ',
  19. queryset=Forum.objects.get(special='root').get_descendants())
  20. return type('FinalPrefixForm', (PrefixFormBase,), {'forums': forums})