本文整理汇总了Python中django.contrib.auth.forms.UserCreationForm.Meta方法的典型用法代码示例。如果您正苦于以下问题:Python UserCreationForm.Meta方法的具体用法?Python UserCreationForm.Meta怎么用?Python UserCreationForm.Meta使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.auth.forms.UserCreationForm
的用法示例。
在下文中一共展示了UserCreationForm.Meta方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_fieldsets
# 需要导入模块: from django.contrib.auth.forms import UserCreationForm [as 别名]
# 或者: from django.contrib.auth.forms.UserCreationForm import Meta [as 别名]
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
示例2: has_perm
# 需要导入模块: from django.contrib.auth.forms import UserCreationForm [as 别名]
# 或者: from django.contrib.auth.forms.UserCreationForm import Meta [as 别名]
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)
示例3: __new__
# 需要导入模块: from django.contrib.auth.forms import UserCreationForm [as 别名]
# 或者: from django.contrib.auth.forms.UserCreationForm import Meta [as 别名]
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
示例4: __init__
# 需要导入模块: from django.contrib.auth.forms import UserCreationForm [as 别名]
# 或者: from django.contrib.auth.forms.UserCreationForm import Meta [as 别名]
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"]