Python django.contrib.auth 模块,get_permission_codename() 实例源码

我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用django.contrib.auth.get_permission_codename()

项目:DjangoCMS    作者:farhan711    | 项目源码 | 文件源码
def save_permissions(data, obj):
    models = (
        (Page, 'page'),
        (PageUser, 'pageuser'),
        (PageUserGroup, 'pageuser'),
        (PagePermission, 'pagepermission'),
    )
    if not obj.pk:
        # save obj, otherwise we can't assign permissions to him
        obj.save()
    permission_accessor = get_permission_accessor(obj)
    for model, name in models:
        content_type = ContentType.objects.get_for_model(model)
        for key in ('add', 'change', 'delete'):
            # add permission `key` for model `model`
            codename = get_permission_codename(key, model._meta)
            permission = Permission.objects.get(content_type=content_type, codename=codename)
            if data.get('can_%s_%s' % (key, name), None):
                permission_accessor.add(permission)
            else:
                permission_accessor.remove(permission)
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
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
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
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))
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
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))
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
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))
项目:CodingDojo    作者:ComputerSocietyUNB    | 项目源码 | 文件源码
def has_change_permission(self, request, obj=None):
        opts = self.opts
        if opts.auto_created:
            # The model was auto-created as intermediary for a
            # ManyToMany-relationship, find the target model
            for field in opts.fields:
                if field.remote_field and field.remote_field.model != self.parent_model:
                    opts = field.remote_field.model._meta
                    break
        codename = get_permission_codename('change', opts)
        return request.user.has_perm("%s.%s" % (opts.app_label, codename))
项目:NarshaTech    作者:KimJangHyeon    | 项目源码 | 文件源码
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))
项目:NarshaTech    作者:KimJangHyeon    | 项目源码 | 文件源码
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))
项目:NarshaTech    作者:KimJangHyeon    | 项目源码 | 文件源码
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))
项目:NarshaTech    作者:KimJangHyeon    | 项目源码 | 文件源码
def has_change_permission(self, request, obj=None):
        opts = self.opts
        if opts.auto_created:
            # The model was auto-created as intermediary for a
            # ManyToMany-relationship, find the target model
            for field in opts.fields:
                if field.remote_field and field.remote_field.model != self.parent_model:
                    opts = field.remote_field.model._meta
                    break
        codename = get_permission_codename('change', opts)
        return request.user.has_perm("%s.%s" % (opts.app_label, codename))
项目:blog_django    作者:chnpmy    | 项目源码 | 文件源码
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)))
项目:blog_django    作者:chnpmy    | 项目源码 | 文件源码
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))
项目:blog_django    作者:chnpmy    | 项目源码 | 文件源码
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))
项目:blog_django    作者:chnpmy    | 项目源码 | 文件源码
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))
项目:blog_django    作者:chnpmy    | 项目源码 | 文件源码
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))
项目:blog_django    作者:chnpmy    | 项目源码 | 文件源码
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))
项目:Scrum    作者:prakharchoudhary    | 项目源码 | 文件源码
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))
项目:Scrum    作者:prakharchoudhary    | 项目源码 | 文件源码
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))
项目:Scrum    作者:prakharchoudhary    | 项目源码 | 文件源码
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))
项目:Scrum    作者:prakharchoudhary    | 项目源码 | 文件源码
def has_change_permission(self, request, obj=None):
        opts = self.opts
        if opts.auto_created:
            # The model was auto-created as intermediary for a
            # ManyToMany-relationship, find the target model
            for field in opts.fields:
                if field.remote_field and field.remote_field.model != self.parent_model:
                    opts = field.remote_field.model._meta
                    break
        codename = get_permission_codename('change', opts)
        return request.user.has_perm("%s.%s" % (opts.app_label, codename))
项目:dream_blog    作者:fanlion    | 项目源码 | 文件源码
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)))
项目:dream_blog    作者:fanlion    | 项目源码 | 文件源码
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))
项目:dream_blog    作者:fanlion    | 项目源码 | 文件源码
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))
项目:dream_blog    作者:fanlion    | 项目源码 | 文件源码
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))
项目:dream_blog    作者:fanlion    | 项目源码 | 文件源码
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))
项目:dream_blog    作者:fanlion    | 项目源码 | 文件源码
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))
项目:MxOnline    作者:myTeemo    | 项目源码 | 文件源码
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)))
项目:MxOnline    作者:myTeemo    | 项目源码 | 文件源码
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))
项目:MxOnline    作者:myTeemo    | 项目源码 | 文件源码
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))
项目:MxOnline    作者:myTeemo    | 项目源码 | 文件源码
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))
项目:MxOnline    作者:myTeemo    | 项目源码 | 文件源码
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))
项目:MxOnline    作者:myTeemo    | 项目源码 | 文件源码
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))
项目:djangoblog    作者:liuhuipy    | 项目源码 | 文件源码
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)))
项目:djangoblog    作者:liuhuipy    | 项目源码 | 文件源码
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))
项目:djangoblog    作者:liuhuipy    | 项目源码 | 文件源码
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))
项目:djangoblog    作者:liuhuipy    | 项目源码 | 文件源码
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))
项目:djangoblog    作者:liuhuipy    | 项目源码 | 文件源码
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))
项目:djangoblog    作者:liuhuipy    | 项目源码 | 文件源码
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))
项目:baya    作者:counsyl    | 项目源码 | 文件源码
def get_all_permissions(self, user, obj=None):
        """Return a set of <app_label>.<permission> for this user.

        Note that these results will only be applicable to the admin panel.

        <permission> is something like add_mymodel or change_mymodel.
        """
        if hasattr(user, '_baya_cached_all_permissions'):
            return user._baya_cached_all_permissions
        permissions = super(NestedLDAPGroupsBackend, self).get_all_permissions(
            user, obj)
        from baya.admin.sites import _admin_registry
        for admin_site in _admin_registry:
            for model, opts in six.iteritems(admin_site._registry):
                app = model._meta.app_label
                perm_name = partial(get_permission_codename, opts=model._meta)
                if (hasattr(opts, 'user_has_add_permission') and
                        opts.user_has_add_permission(user)):
                    permissions.add("%s.%s" % (app, perm_name('add')))
                if (hasattr(opts, 'user_has_change_permission') and
                        opts.user_has_change_permission(user)):
                    permissions.add("%s.%s" % (app, perm_name('change')))
                if (hasattr(opts, 'user_has_delete_permission') and
                        opts.user_has_delete_permission(user)):
                    permissions.add("%s.%s" % (app, perm_name('delete')))
        user._baya_cached_all_permissions = permissions
        return permissions
项目:baya    作者:counsyl    | 项目源码 | 文件源码
def get_all_permissions(self, user, obj=None):
        """Return a set of <app_label>.<permission> for this user.

        Note that these results will only be applicable to the admin panel.

        <permission> is something like add_mymodel or change_mymodel.
        """
        if hasattr(user, '_baya_cached_all_permissions'):
            return user._baya_cached_all_permissions
        permissions = super(NestedLDAPGroupsBackend, self).get_all_permissions(
            user, obj)
        from baya.admin.sites import _admin_registry
        for admin_site in _admin_registry:
            for model, opts in six.iteritems(admin_site._registry):
                app = model._meta.app_label
                perm_name = partial(get_permission_codename, opts=model._meta)
                if (hasattr(opts, 'user_has_add_permission') and
                        opts.user_has_add_permission(user)):
                    permissions.add("%s.%s" % (app, perm_name('add')))
                if (hasattr(opts, 'user_has_change_permission') and
                        opts.user_has_change_permission(user)):
                    permissions.add("%s.%s" % (app, perm_name('change')))
                if (hasattr(opts, 'user_has_delete_permission') and
                        opts.user_has_delete_permission(user)):
                    permissions.add("%s.%s" % (app, perm_name('delete')))
        user._baya_cached_all_permissions = permissions
        return permissions
项目:sdining    作者:Lurance    | 项目源码 | 文件源码
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)))
项目:sdining    作者:Lurance    | 项目源码 | 文件源码
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))
项目:sdining    作者:Lurance    | 项目源码 | 文件源码
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))
项目:sdining    作者:Lurance    | 项目源码 | 文件源码
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))
项目:sdining    作者:Lurance    | 项目源码 | 文件源码
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))
项目:sdining    作者:Lurance    | 项目源码 | 文件源码
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))
项目:django-seven    作者:iwoca    | 项目源码 | 文件源码
def get_permission_codename(action, opts):
        return '%s_%s' % (action, opts.object_name.lower())
项目:Gypsy    作者:benticarlos    | 项目源码 | 文件源码
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))
项目:Gypsy    作者:benticarlos    | 项目源码 | 文件源码
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))
项目:Gypsy    作者:benticarlos    | 项目源码 | 文件源码
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))