本文整理汇总了Python中django.contrib.auth.get_permission_codename方法的典型用法代码示例。如果您正苦于以下问题:Python auth.get_permission_codename方法的具体用法?Python auth.get_permission_codename怎么用?Python auth.get_permission_codename使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.auth
的用法示例。
在下文中一共展示了auth.get_permission_codename方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: has_view_permission
# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_permission_codename [as 别名]
def has_view_permission(self, request, obj=None):
"""
Return True if the given request has permission to view the given
Django model instance. The default implementation doesn't examine the
`obj` parameter.
If overridden by the user in subclasses, it should return True if the
given request has permission to view the `obj` model instance. If `obj`
is None, it should return True if the request has permission to view
any object of the given type.
"""
opts = self.opts
codename_view = get_permission_codename('view', opts)
codename_change = get_permission_codename('change', opts)
return (
request.user.has_perm('%s.%s' % (opts.app_label, codename_view)) or
request.user.has_perm('%s.%s' % (opts.app_label, codename_change))
)
示例2: has_view_permission
# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_permission_codename [as 别名]
def has_view_permission(self, obj=None):
view_codename = get_permission_codename('view', self.opts)
change_codename = get_permission_codename('change', self.opts)
return ('view' not in self.remove_permissions) and (self.user.has_perm('%s.%s' % (self.app_label, view_codename)) or \
self.user.has_perm('%s.%s' % (self.app_label, change_codename)))
示例3: has_add_permission
# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_permission_codename [as 别名]
def has_add_permission(self):
codename = get_permission_codename('add', self.opts)
return ('add' not in self.remove_permissions) and self.user.has_perm('%s.%s' % (self.app_label, codename))
示例4: has_change_permission
# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_permission_codename [as 别名]
def has_change_permission(self, obj=None):
codename = get_permission_codename('change', self.opts)
return ('change' not in self.remove_permissions) and self.user.has_perm('%s.%s' % (self.app_label, codename))
示例5: has_delete_permission
# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_permission_codename [as 别名]
def has_delete_permission(self, obj=None):
codename = get_permission_codename('delete', self.opts)
return ('delete' not in self.remove_permissions) and self.user.has_perm('%s.%s' % (self.app_label, codename))
示例6: has_add_permission
# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_permission_codename [as 别名]
def has_add_permission(self):
if self.opts.auto_created:
return self.has_change_permission()
codename = get_permission_codename('add', self.opts)
return self.user.has_perm("%s.%s" % (self.opts.app_label, codename))
示例7: has_delete_permission
# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_permission_codename [as 别名]
def has_delete_permission(self):
if self.opts.auto_created:
return self.has_change_permission()
codename = get_permission_codename('delete', self.opts)
return self.user.has_perm("%s.%s" % (self.opts.app_label, codename))
示例8: has_permission
# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_permission_codename [as 别名]
def has_permission(opts, user, perm):
codename = get_permission_codename(perm, opts)
return user.has_perm("%s.%s" % (opts.app_label, codename))
示例9: get_actions
# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_permission_codename [as 别名]
def get_actions(opts, user):
actions = []
name = opts.model_name.lower()
ACTION_PATH = 'idcops.actions'
try:
action_list = import_string("{}.{}".format(ACTION_PATH, name))
except BaseException:
action_list = import_string("{}.general".format(ACTION_PATH))
for a in action_list:
action = get_action(import_string("{}.{}".format(ACTION_PATH, a)))
perm, _, _, _ = action
p = '%s.%s' % (opts.app_label, get_permission_codename(perm, opts))
if user.has_perm(p):
actions.append(action)
return actions
示例10: has_add_permission
# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_permission_codename [as 别名]
def has_add_permission(self, request):
"""
Returns True if the given request has permission to add an object.
Can be overridden by the user in subclasses.
"""
opts = self.opts
codename = get_permission_codename('add', opts)
return request.user.has_perm("%s.%s" % (opts.app_label, codename))
示例11: has_change_permission
# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_permission_codename [as 别名]
def has_change_permission(self, request, obj=None):
"""
Returns True if the given request has permission to change the given
Django model instance, the default implementation doesn't examine the
`obj` parameter.
Can be overridden by the user in subclasses. In such case it should
return True if the given request has permission to change the `obj`
model instance. If `obj` is None, this should return True if the given
request has permission to change *any* object of the given type.
"""
opts = self.opts
codename = get_permission_codename('change', opts)
return request.user.has_perm("%s.%s" % (opts.app_label, codename))
示例12: has_delete_permission
# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_permission_codename [as 别名]
def has_delete_permission(self, request, obj=None):
"""
Returns True if the given request has permission to change the given
Django model instance, the default implementation doesn't examine the
`obj` parameter.
Can be overridden by the user in subclasses. In such case it should
return True if the given request has permission to delete the `obj`
model instance. If `obj` is None, this should return True if the given
request has permission to delete *any* object of the given type.
"""
opts = self.opts
codename = get_permission_codename('delete', opts)
return request.user.has_perm("%s.%s" % (opts.app_label, codename))
示例13: _get_builtin_permissions
# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_permission_codename [as 别名]
def _get_builtin_permissions(opts):
"""
Returns (codename, name) for all autogenerated permissions.
By default, this is ('add', 'change', 'delete')
"""
perms = []
for action in opts.default_permissions:
perms.append((get_permission_codename(action, opts),
'Can %s %s' % (action, opts.verbose_name_raw)))
return perms
示例14: has_view_permission
# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_permission_codename [as 别名]
def has_view_permission(self, request, obj=None):
"""
Returns True if the given request has permission to view an object.
Can be overridden by the user in subclasses.
"""
opts = self.opts
codename = get_permission_codename('view', opts)
return request.user.has_perm("%s.%s" % (opts.app_label, codename))
示例15: has_add_permission
# 需要导入模块: from django.contrib import auth [as 别名]
# 或者: from django.contrib.auth import get_permission_codename [as 别名]
def has_add_permission(self, request):
"""
Return True if the given request has permission to add an object.
Can be overridden by the user in subclasses.
"""
opts = self.opts
codename = get_permission_codename('add', opts)
return request.user.has_perm("%s.%s" % (opts.app_label, codename))