#NEWLINE# def authorize( request , page = None , edit = False , add = False , delete = False , view = False , do_raise = True ) : #NEWLINE# #INDENT# if isinstance ( page , basestring ) : #NEWLINE# #INDENT# page = Page . objects . get ( slug = page ) . get_content_model ( ) #NEWLINE# #UNINDENT# user = get_user ( request ) #NEWLINE# request . user = user #NEWLINE# auth = True #NEWLINE# if ( auth and ( page is not None ) ) : #NEWLINE# #INDENT# request . user = user #NEWLINE# if edit : #NEWLINE# #INDENT# auth = page . can_change ( request ) #NEWLINE# #UNINDENT# if add : #NEWLINE# #INDENT# auth = ( auth and page . can_add ( request ) ) #NEWLINE# #UNINDENT# if delete : #NEWLINE# #INDENT# auth = ( auth and page . can_delete ( request ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if view : #NEWLINE# #INDENT# auth = ( ( auth and ( not hasattr ( page , 'can_view' ) ) ) or ( auth and hasattr ( page , 'can_view' ) and page . can_view ( request ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( do_raise and ( not auth ) ) : #NEWLINE# #INDENT# raise PermissionDenied ( json . dumps ( { #NEWLINE# #INDENT# 'error' : 'Unauthorized' , #NEWLINE# 'user' : ( user . email if user . is_authenticated ( ) else None ) , #NEWLINE# 'page' : ( page . slug if page else None ) , #NEWLINE# 'edit' : edit , #NEWLINE# 'add' : add , #NEWLINE# 'delete' : delete , #NEWLINE# 'view' : view , #NEWLINE# #UNINDENT# } ) ) #NEWLINE# #UNINDENT# return user