forms.py 1.3 KB

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