<s> from __future__ import unicode_literals <EOL> from functools import wraps <EOL> from django . core . exceptions import PermissionDenied <EOL> from rolepermissions . roles import RolesManager <EOL> from rolepermissions . verifications import has_role , has_permission <EOL> def has_role_decorator ( role ) : <EOL> def request_decorator ( dispatch ) : <EOL> @ wraps ( dispatch ) <EOL> def wrapper ( request , * args , ** kwargs ) : <EOL> user = request . user <EOL> if user . is_authenticated ( ) : <EOL> if has_role ( user , role ) : <EOL> return dispatch ( request , * args , ** kwargs ) <EOL> raise PermissionDenied <EOL> return wrapper <EOL> return request_decorator <EOL> def has_permission_decorator ( permission_name ) : <EOL> def request_decorator ( dispatch ) : <EOL> @ wraps ( dispatch ) <EOL> def wrapper ( request , * args , ** kwargs ) : <EOL> user = request . user <EOL> if user . is_authenticated ( ) : <EOL> if has_permission ( user , permission_name ) : <EOL> return dispatch ( request , * args , ** kwargs ) <EOL> raise PermissionDenied <EOL> return wrapper <EOL> return request_decorator </s>
