With ACL registers
authorMadhusudan.C.S <madhusudancs@gmail.com>
Fri, 07 Aug 2009 01:03:56 +0530
changeset 12 aac4944aca52
parent 11 dfc069c2d35d
child 13 684540719344
With ACL registers
app/projrev/views/base.py
app/projrev/views/helpers/access.py
app/projrev/views/proposal.py
app/templates/projrev/base.html
--- a/app/projrev/views/base.py	Thu Aug 06 22:48:30 2009 +0530
+++ b/app/projrev/views/base.py	Fri Aug 07 01:03:56 2009 +0530
@@ -9,6 +9,8 @@
 
 from django.core.urlresolvers import reverse
 from django.http import HttpResponseRedirect
+from django.shortcuts import render_to_response
+from django.template import RequestContext
 
 
 def home(request):
@@ -22,4 +24,5 @@
     else:
       return HttpResponseRedirect(reverse('app.projrev.views.proposal.submit'))
   else:
-    return HttpResponseRedirect(reverse('app.projrev.views.login.login_validate'))
+    template = 'projrev/home.html'
+    return render_to_response(template, RequestContext(request, {}))
--- 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:
--- a/app/projrev/views/proposal.py	Thu Aug 06 22:48:30 2009 +0530
+++ b/app/projrev/views/proposal.py	Fri Aug 07 01:03:56 2009 +0530
@@ -22,6 +22,7 @@
 from projrev.views.helpers import forms as projrev_forms
 
 
+@access.register('proposer')
 @access.checkAccess
 def getMicr(request):
   """View to get MICR Code from the user.
@@ -62,7 +63,7 @@
 
     return render_to_response(template, RequestContext(request, context))
 
-
+@access.register('proposer')
 @access.checkAccess
 def submit(request, micr_code=None):
   """View for proposal submission.
@@ -109,7 +110,8 @@
 
     # Create a proposal for the project.
     proposal = project.proposal_set.create(
-        document=prop_form.cleaned_data['document'], rev_num = 0)
+        document=prop_form.cleaned_data['document'], 
+        submitted_by=request.user, rev_num = 0)
 
     proposal.save()
 
@@ -137,7 +139,8 @@
     prop_form = projrev_forms.ProposalForm(
         initial=initial_vals, instance=project)
 
-    proposal_path = str(project.proposal_set.all()[0].document)
+    proposal_path = str(
+        project.proposal_set.all().order_by('-submitted_on')[0].document)
 
     proposal_name = proposal_path.split('/')[-1]
 
@@ -164,6 +167,7 @@
 
   return render_to_response(template, RequestContext(request, context))
 
+@access.register('proposer')
 @access.checkAccess
 def withdraw(request, micr_code=None):
   """View Method for withdrawal of proposal.
@@ -182,6 +186,7 @@
 
   return render_to_response(template, RequestContext(request, context))
 
+@access.register('reviewer')
 @access.checkAccess
 def review(request, micr_code=None):
   """View for reviewing the proposal.
@@ -226,7 +231,8 @@
     rev_form = projrev_forms.ReviewForm()
 
   proposal_path = str(Project.objects.get(
-          micr_code=micr_code).proposal_set.all()[0].document)
+          micr_code=micr_code).proposal_set.all().order_by(
+              '-submitted_on')[0].document)
 
   proposal_name = proposal_path.split('/')[-1]
 
@@ -241,6 +247,7 @@
 
   return render_to_response(template, RequestContext(request, context))
 
+@access.register('reviewer')
 @access.checkAccess
 def rank(request, micr_code=None):
   """
@@ -272,7 +279,8 @@
 
   projects = Project.objects.get(micr_code=micr_code)
 
-  proposal_path = str(projects.proposal_set.all()[0].document)
+  proposal_path = str(
+      projects.proposal_set.all().order_by('-submitted_on')[0].document)
 
   proposal_name = proposal_path.split('/')[-1]
 
--- a/app/templates/projrev/base.html	Thu Aug 06 22:48:30 2009 +0530
+++ b/app/templates/projrev/base.html	Fri Aug 07 01:03:56 2009 +0530
@@ -65,11 +65,10 @@
 
       <div class="sidebox">
       
-        <h1>Short About</h1>
+        <h1>About NME ICT</h1>
         
-        <p>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Donec libero. Suspendisse bibendum. 
-        Cras id urna. Morbi tincidunt, orci ac convallis aliquam, lectus turpis varius lorem, eu 
-        posuere nunc justo tempus leo.</p>  
+        <p>National Mission on Education is an Ministry of Human Resources 
+        Development, Govt. of India initiative. The goal .</p>  
             
       </div>					
 		</div>	
@@ -87,39 +86,32 @@
 <div id="footer"><div id="footer-content">
 	
 		<div class="col float-left">
-			<h1>Site Partners</h1>
+			<h1>Funded projects</h1>
 			<ul>				
-				<li><a href="http://www.dreamhost.com/r.cgi?287326"><strong>Dreamhost</strong> - Affordable &amp; Reliable Webhosting</a></li>
-				<li><a href="http://www.4templates.com/?aff=ealigam"><strong>4templates</strong> - Low Cost Hi-Quality Templates</a></li>
-				<li><a href="http://store.templatemonster.com/?aff=ealigam"><strong>TemplateMonster</strong> - Best templates on the net!</a></li>	
-				<li><a href="http://www.fotolia.com/partner/114283"><strong>Fotolia</strong> - Free stock images or from $1</a></li>						
-				<li><a href="http://www.text-link-ads.com/?ref=40025"><strong>Text Link Ads</strong> - Easiest. Money. Ever.</a></li>
+				<li><a href="http://scilab.in"><strong>Scilab</strong> - scilab.in</a></li>
 			</ul>			
 		</div>
 		
 		<div class="col float-left">
 			<h1>Links</h1>
 			<ul>				
-				<li><a href="http://www.openwebdesign.org/">openwebdesign.org</a></li>
-				<li><a href="http://www.opendesigns.org/">Opendesigns.org</a></li>
-				<li><a href="http://www.pdphoto.org/">PDPhoto.org</a></li>
-				<li><a href="http://www.alistapart.com">Alistapart</a></li>					
-				<li><a href="http://www.cssremix.com">CSS Remix</a></li>				
+				<li><a href="http://www.education.nic.in/">Ministry of HRD</a></li>	
+				<li><a href="http://www.iitb.ac.in/">IIT Bombay</a></li>
 			</ul>			
 		</div>		
 	
 		<div class="col2 float-right">
 		<p>
-		&copy; copyright 2006 <strong>Your Company Name</strong><br /> 
-		Design by: <a href="index.html"><strong>styleshout</strong></a> &nbsp; &nbsp;
+		&copy; copyright 2009 <strong>Sakshath</strong><br /> 
+		Design by: <a href="index.html"><strong>IIT Bombay</strong></a> &nbsp; &nbsp;<br/>
+		Information Provided and Updated by Ministry of Human Resource Development<br/>
 		Valid <a href="http://jigsaw.w3.org/css-validator/check/referer"><strong>CSS</strong></a> | 
 		      <a href="http://validator.w3.org/check/referer"><strong>XHTML</strong></a>
 		</p>
 		
 		<ul>						
-			<li><a href="index.html"><strong>Home</strong></a></li>
-			<li><a href="index.html"><strong>Sitemap</strong></a></li>
-			<li><a href="index.html"><strong>RSS Feed</strong></a></li>								
+			<li><a href="/"><strong>Home</strong></a></li>
+			<li><a href=""><strong>Sitemap</strong></a></li>								
 		</ul>	
 		</div>