def has_perm_or_owns_or_403(perm, owner_attr, obj_lookup, perm_obj_lookup, **kwargs):
 def decorator(view_func):
  def _wrapped_view(request, *args, **kwargs):
   user = request.user
   if user.is_authenticated():
    obj = _resolve_lookup(obj_lookup, kwargs)
    perm_obj = _resolve_lookup(perm_obj_lookup, kwargs)
    granted = access.has_perm_or_owns(user, perm, obj, perm_obj, owner_attr)
    if (granted or user.has_perm(perm)):
     return view_func(request, *args, **kwargs)
   return HttpResponseForbidden()
  return wraps(view_func)(_wrapped_view)
 return decorator

def has_perm_or_owns_or_403 ( perm , owner_attr , obj_lookup , perm_obj_lookup , ** kwargs ) : def decorator ( view_func ) : def _wrapped_view ( request , * args , ** kwargs ) : user = request . user if user . is_authenticated ( ) : obj = _resolve_lookup ( obj_lookup , kwargs ) perm_obj = _resolve_lookup ( perm_obj_lookup , kwargs ) granted = access . has_perm_or_owns ( user , perm , obj , perm_obj , owner_attr ) if ( granted or user . has_perm ( perm ) ) : return view_func ( request , * args , ** kwargs ) return HttpResponseForbidden ( ) return wraps ( view_func ) ( _wrapped_view ) return decorator
act like permission_required_or_403 but also grant permission to owners .