Package expedient :: Package common :: Package permissions :: Module decorators :: Class require_objs_permissions_for_view
[hide private]
[frames] | no frames]

Class require_objs_permissions_for_view

source code


Decorator to be used on views. The decorator checks that a permittee has the permissions listed in perm_names for some targets. The permittee and targets are returned respectively by the permittee_func and target_func parameters of the decorator. These should be callables that can take the parameters of the decorated function. The decorator also accepts an optional fourth parameter methods that is a list of method names for which the permission applies. target_func must return a QuerySet.

For example:

   @require_objs_permissions_for_view(
       ["can_delete_comment"],
       lambda(request, blog_id, comment_id): get_object_or_404(Blog, pk=blog_id),
       lambda(request, blog_id, comment_id): Comment.objects.filter(pk=comment_id),
       ["POST"],
   )
   def delete_blog_comment(request, blog_id, comment_id):
       ...
Instance Methods [hide private]
 
__init__(self, perm_names, permittee_func, target_func, methods=['GET', 'POST'])
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
source code
 
__call__(self, f) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self, perm_names, permittee_func, target_func, methods=['GET', 'POST'])
(Constructor)

source code 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Parameters:
  • perm_names (list of str) - a list of permission names that are required.
  • permittee_func (callable) - a callable that accepts the decorated methods arguments and returns a model instance not necessarily a PermissionUser instance.
  • target_func (callable) - a callable that accepts the decorated methods arguments and returns a QuerySet instance of targets.
  • methods (list of str) - list of methods for which the requirement applies. Default is ["GET", "POST"].
Overrides: object.__init__
(inherited documentation)