#NEWLINE# def permission_required( perm , queryset = None , login_url = None , raise_exception = False ) : #NEWLINE# #INDENT# "\n    Permission check decorator for function-base generic view\n\n    This decorator works as function decorator\n\n    Parameters\n    ----------\n    perm : string\n        A permission string\n    queryset_or_model : queryset or model\n        A queryset or model for finding object.\n        With classbased generic view, ``None`` for using view default queryset.\n        When the view does not define ``get_queryset``, ``queryset``,\n        ``get_object``, or ``object`` then ``obj=None`` is used to check\n        permission.\n        With functional generic view, ``None`` for using passed queryset.\n        When non queryset was passed then ``obj=None`` is used to check\n        permission.\n\n    Examples\n    --------\n    >>> @permission_required('auth.change_user')\n    >>> def update_auth_user(request, *args, **kwargs):\n    ...     pass\n    " #NEWLINE# def wrapper( view_func ) : #NEWLINE# #INDENT# @ wraps ( view_func , assigned = available_attrs ( view_func ) ) #NEWLINE# def inner( request , * args , **kwargs ) : #NEWLINE# #INDENT# _kwargs = copy . copy ( kwargs ) #NEWLINE# if queryset : #NEWLINE# #INDENT# _kwargs [ 'queryset' ] = queryset #NEWLINE# #UNINDENT# if ( 'date_field' in _kwargs ) : #NEWLINE# #INDENT# fn = get_object_from_date_based_view #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# fn = get_object_from_list_detail_view #NEWLINE# #UNINDENT# if fn . validate ( request , * args , ** _kwargs ) : #NEWLINE# #INDENT# obj = fn ( request , * args , ** _kwargs ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# obj = None #NEWLINE# #UNINDENT# if ( not request . user . has_perm ( perm , obj = obj ) ) : #NEWLINE# #INDENT# if raise_exception : #NEWLINE# #INDENT# raise PermissionDenied #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return redirect_to_login ( request , login_url ) #NEWLINE# #UNINDENT# #UNINDENT# return view_func ( request , * args , ** _kwargs ) #NEWLINE# #UNINDENT# return inner #NEWLINE# #UNINDENT# return wrapper