Python django.contrib.auth.forms.UserCreationForm.Meta() Examples
The following are 4
code examples of django.contrib.auth.forms.UserCreationForm.Meta().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
django.contrib.auth.forms.UserCreationForm
, or try the search function
.
Example #1
Source File: admin.py From openwisp-users with BSD 3-Clause "New" or "Revised" License | 6 votes |
def get_fieldsets(self, request, obj=None): # add form fields for staff users if not obj and not request.user.is_superuser: return self.add_form.Meta.fieldsets # add form fields for superusers if not obj and request.user.is_superuser: return self.add_form.Meta.fieldsets_superuser # return fieldsets according to user fieldsets = super().get_fieldsets(request, obj) if not request.user.is_superuser: # edit this tuple to add / remove permission items # visible to non-superusers user_permissions = ('is_active', 'is_staff', 'groups', 'user_permissions') # copy to avoid modifying reference non_superuser_fieldsets = deepcopy(fieldsets) non_superuser_fieldsets[2][1]['fields'] = user_permissions return non_superuser_fieldsets return fieldsets
Example #2
Source File: __init__.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def has_perm(self, user): """Return True if the `user` has permission to perform this action.""" adding = self.instance._state.adding if adding: # This is a create action, verify that the user has the # permission to perform this create action. if self._meta.permission_create is None: raise ValueError( "`has_perm` cannot be called on a create action without " "`permission_create` being set on the form's Meta class." ) # `obj` is not passed to `has_perm` because the object is being # created and this is not an edit action. return user.has_perm(self._meta.permission_create) # This is an edit action, verify that the user has permission to # perform editing on this instance. if self._meta.permission_edit is None: raise ValueError( "`has_perm` cannot be called on a modify action without " "`permission_edit` being set on the form's Meta class." ) return user.has_perm(self._meta.permission_edit, self.instance)
Example #3
Source File: __init__.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def __new__(mcs, name, bases, attrs): new_class = super().__new__(mcs, name, bases, attrs) meta = getattr(new_class, "Meta", None) new_class._meta.permission_create = getattr( meta, "permission_create", None ) new_class._meta.permission_edit = getattr( meta, "permission_edit", None ) return new_class
Example #4
Source File: __init__.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) # Django 1.4 overrides the field 'password' thus adding it # post-facto to the list of the selected fields (Meta.fields). # Here we don't want to use this form to edit the password. if "password" in self.fields: del self.fields["password"]