app/projrev/views/helpers/access.py
changeset 12 aac4944aca52
parent 8 294ff7ac9cb6
--- a/app/projrev/views/helpers/access.py	Thu Aug 06 22:48:30 2009 +0530
+++ b/app/projrev/views/helpers/access.py	Fri Aug 07 01:03:56 2009 +0530
@@ -12,9 +12,23 @@
 from django.shortcuts import render_to_response
 from django.template import RequestContext
 
-
+# Dictionary containing access checks for views.
+# Keys: View function name.
+# Values: proposer or staff
 rights = {}
-rights['getMicr'] = 'proposer'
+ 
+def register(access_type):
+  """Function to register access type for a View function
+  """
+
+  def wrapper(func):
+    """The decorator for registering access checks.
+    """
+
+    rights['%s.%s' % (func.__module__, func.__name__)] = access_type
+    return func
+
+  return wrapper
 
 def checkAccess(func):
   """ To check the access of the user and then return the appropriate function 
@@ -26,14 +40,14 @@
     """The decorator for access check.
     """
 
-    user_kind = rights[func.__name__]
+    user_kind = rights['%s.%s' % (func.__module__, func.__name__)]
     user = request.user
 
     template = 'projrev/error.html'
     context = {}
 
     if user.is_authenticated():
-      if user_kind == 'staff':
+      if user_kind == 'reviewer':
         if user.is_staff:
           return func(request, *args, **kwargs)
         else: