def require_role(role='user'):
 def _deco(func):
  def __deco(request, *args, **kwargs):
   request.session['pre_url'] = request.path
   if (not request.user.is_authenticated()):
    return HttpResponseRedirect(reverse('login'))
   if (role == 'admin'):
    if (request.user.role == 'CU'):
     return HttpResponseRedirect(reverse('index'))
   elif (role == 'super'):
    if (request.user.role in ['CU', 'GA']):
     return HttpResponseRedirect(reverse('index'))
   return func(request, *args, **kwargs)
  return __deco
 return _deco

def require_role ( role = 'user' ) : def _deco ( func ) : def __deco ( request , * args , ** kwargs ) : request . session [ 'pre_url' ] = request . path if ( not request . user . is_authenticated ( ) ) : return HttpResponseRedirect ( reverse ( 'login' ) ) if ( role == 'admin' ) : if ( request . user . role == 'CU' ) : return HttpResponseRedirect ( reverse ( 'index' ) ) elif ( role == 'super' ) : if ( request . user . role in [ 'CU' , 'GA' ] ) : return HttpResponseRedirect ( reverse ( 'index' ) ) return func ( request , * args , ** kwargs ) return __deco return _deco
decorator for require user role in ["super" .