forms.py 1.1 KB

12345678910111213141516171819
  1. from django.utils.translation import ugettext_lazy as _
  2. import floppyforms as forms
  3. from misago.forms import Form, YesNoSwitch
  4. from misago.validators import validate_sluggable
  5. class RoleForm(Form):
  6. name = forms.CharField(label=_("Role Name"),
  7. help_text=_("Role Name is used to identify this role in Admin Control Panel."),
  8. max_length=255,validators=[validate_sluggable(
  9. _("Role name must contain alphanumeric characters."),
  10. _("Role name is too long.")
  11. )])
  12. protected = forms.BooleanField(label=_("Protect this Role"),
  13. help_text=_("Only system administrators can edit or assign protected roles."),
  14. widget=YesNoSwitch,required=False)
  15. def finalize_form(self):
  16. if not self.request.user.is_god():
  17. del self.fields['protected']