forms.py 936 B

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