app/projrev/views/proposal.py
changeset 15 8c9e6c98de82
parent 14 9d720dfded68
child 16 bed14c9685a5
--- a/app/projrev/views/proposal.py	Fri Aug 07 03:16:44 2009 +0530
+++ b/app/projrev/views/proposal.py	Fri Aug 07 03:40:08 2009 +0530
@@ -293,23 +293,33 @@
   """
   """
 
+  context = {}
+
   if not micr_code:
     template = 'projrev/proposal/list.html'
-    context = {
-        'projects': Project.objects.all(),
-        'row_url': '/proposal/rank/',
-        }
+    context['projects'] = Project.objects.all()
+    context['row_url'] = '/proposal/rank/'
 
     return render_to_response(template, RequestContext(request, context))
 
-  projects = Project.objects.get(micr_code=micr_code)
+  project = Project.objects.get(micr_code=micr_code)
+
+  proposal = project.proposal_set.all().order_by('-submitted_on')[0]
+
+  if proposal:
+    proposal_path = str(proposal.document)
+
+    proposal_name = proposal_path.split('/')[-1]
 
-  proposal_path = str(
-      projects.proposal_set.all().order_by('-submitted_on')[0].document)
+    context['proposal_path'] = proposal_path
+    context['proposal_name'] = proposal_name
+    context['last_submitted'] = proposal.submitted_on
 
-  proposal_name = proposal_path.split('/')[-1]
-
-  reviews = projects.review_set.all()
+  reviews = project.review_set.all().order_by('-reviewed_on')
+  nr_reviews = len(reviews)
+  if reviews:
+    context['last_reviewed'] = reviews[0].reviewed_on
+    context['nr_reviews'] = nr_reviews
 
   review_score = [0] * 9
   for review in reviews:
@@ -325,13 +335,23 @@
 
   total_score = sum(review_score)
 
-  context = {
-      'project': projects,
-      'proposal_path': proposal_path,
-      'proposal_name': proposal_name,
-      'review_score': review_score,
-      'total_score': total_score,
-      }
+  review_avg = [0] * 9
+  for i, rs in enumerate(review_score):
+    try:
+      review_avg[i] = float(rs) / nr_reviews
+    except ZeroDivisionError:
+      review_avg[i] = 0
+
+  try:
+    total_avg = float(total_score) / nr_reviews
+  except ZeroDivisionError:
+    total_avg = 0
+
+  context['project'] = project
+  context['review_score'] = review_score
+  context['total_score'] = total_score
+  context['review_avg'] = review_avg
+  context['total_avg'] = total_avg
 
   template = 'projrev/proposal/rank.html'