app/projrev/views/helpers/access.py
changeset 8 294ff7ac9cb6
parent 7 3e6916eb3d2c
child 12 aac4944aca52
--- a/app/projrev/views/helpers/access.py	Thu Aug 06 18:49:06 2009 +0530
+++ b/app/projrev/views/helpers/access.py	Thu Aug 06 20:20:36 2009 +0530
@@ -7,21 +7,47 @@
 ]
 
 
-def checkAccess(func, request):
+from functools import wraps
+
+from django.shortcuts import render_to_response
+from django.template import RequestContext
+
+
+rights = {}
+rights['getMicr'] = 'proposer'
+
+def checkAccess(func):
   """ To check the access of the user and then return the appropriate function 
-object
+  object.
  """
-  user_kind = rights[func.__name__]
-  if user.is_authenticated():
-    if user_kind == 'staff':
-      if user.is_staff:
-        return func(request)
-      else:
-        return 
-        
-    if user_kind == 'proposer':
-      if not user.is_staff:
-        return func(request)
-      else:
-        return
-    
\ No newline at end of file
+
+  @wraps(func)
+  def wrapper(request, *args, **kwargs):
+    """The decorator for access check.
+    """
+
+    user_kind = rights[func.__name__]
+    user = request.user
+
+    template = 'projrev/error.html'
+    context = {}
+
+    if user.is_authenticated():
+      if user_kind == 'staff':
+        if user.is_staff:
+          return func(request, *args, **kwargs)
+        else:
+          context['not_staff'] = True 
+          return render_to_response(template, RequestContext(request, context)) 
+
+      if user_kind == 'proposer':
+        if not user.is_staff:
+          return func(request, *args, **kwargs)
+        else:
+          context['not_proposer'] = True
+          return render_to_response(template, RequestContext(request, context))
+    else:
+      context['not_authenticated'] = True
+      return render_to_response(template, RequestContext(request, context))
+
+  return wrapper
\ No newline at end of file