Please don’t email random code snippets to this list.

On Mon, Feb 13, 2023 at 3:29 PM Thomas Ménès <thomas.me...@vingtcinq.io>
wrote:

> def extra_permissions(permission_classes):
> """Decorate a CBV method to add specific permissions on the instance."""
> def decorator(func):
> def decorated_func(self, *args, **kwargs):
> for permission_class in permission_classes:
> # Check the extra view level permissions.
> permission = permission_class()
> if not permission.has_permission(self.request, self):
> self.permission_denied(
> self.request,
> message=getattr(permission, "message", None),
> code=getattr(permission, "code", None)
> )
> # Add them to permission classes for obj level checks.
> # Reassignment is for global tests as they call the same CBV intances.
> self.permission_classes = self.permission_classes + [permission_class]
> return func(self, *args, **kwargs)
> return decorated_func
> return decorator
>
> --
> You received this message because you are subscribed to the Google Groups
> "Django developers (Contributions to Django itself)" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/08541759-4D69-4147-8009-0188C3CEED0D%40vingtcinq.io
> <https://groups.google.com/d/msgid/django-developers/08541759-4D69-4147-8009-0188C3CEED0D%40vingtcinq.io?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAMyDDM2rZdzvgftnh320S4n5_ge9G4J-YRFkvd2ge3eRgUovww%40mail.gmail.com.
  • [no... Thomas Ménès
    • ... 'Adam Johnson' via Django developers (Contributions to Django itself)

Reply via email to