Skip to content
This repository has been archived by the owner on Jul 21, 2021. It is now read-only.

Stay at model level #77

Open
LucasBerbesson opened this issue Jul 13, 2017 · 1 comment
Open

Stay at model level #77

LucasBerbesson opened this issue Jul 13, 2017 · 1 comment

Comments

@LucasBerbesson
Copy link

Hello,
I love this package, it's awesome thank you.
Is there a way to use the permission_required decorator on a ListView (or any CBV with a get_queryset method) on a Model level and thus checking the has_perm only once.

Right now I'm using the django.contrib.auth.mixins.PermissionRequiredMixin, but I love the permission_required decorator.

Basically I would love to do something like

from permission.decorators import permission_required

@permission_required('blog.view_post',stay_at_model_level=True)
class PostList(ListView):
    model = Post

Instead of doing :

from django.contrib.auth.mixins import PermissionRequiredMixin

class PostList(PermissionRequiredMixin, ListView):
    model = Post
    permission_required = 'blog.view_post'
@lambdalisue
Copy link
Contributor

No. But it is not so difficult to implement. For example

https:/lambdalisue/django-permission/blob/master/src/permission/decorators/classbase.py#L45

If obj here is None then it would check the model level permission.

Currently I don't have enough time to implement that feature to the existing decorators so if you are in hurry, send me a PR for all decorators in https:/lambdalisue/django-permission/tree/master/src/permission/decorators 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants