Ranking of proposals view completion.
authorMadhusudan.C.S <madhusudancs@gmail.com>
Fri, 07 Aug 2009 03:40:08 +0530
changeset 15 8c9e6c98de82
parent 14 9d720dfded68
child 16 bed14c9685a5
Ranking of proposals view completion.
app/projrev/views/proposal.py
app/templates/projrev/base.html
app/templates/projrev/proposal/rank.html
app/urls.py
--- 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'
 
--- a/app/templates/projrev/base.html	Fri Aug 07 03:16:44 2009 +0530
+++ b/app/templates/projrev/base.html	Fri Aug 07 03:40:08 2009 +0530
@@ -53,6 +53,7 @@
             <li><a href="/logout/" class="top">Logout</a></li>
             {% if user.is_staff%}
               <li><a href="/proposal/review/" class="top">Review Proposals</a></li>
+              <li><a href="/proposal/rank/" class="top">Aggregated Scores for Proposals</a></li>
             {% else %}
               <li><a href="/proposal/submit/" class="top">Create/Edit Proposals</a></li>
             {% endif %}
--- a/app/templates/projrev/proposal/rank.html	Fri Aug 07 03:16:44 2009 +0530
+++ b/app/templates/projrev/proposal/rank.html	Fri Aug 07 03:40:08 2009 +0530
@@ -56,77 +56,105 @@
       Attribute Name
     </div>
     <div class='review-right'>
-      <b>Score</b>
+      <b>Score</b>&nbsp;&nbsp;&nbsp;&nbsp;<b>Average</b>
     </div>
     <br />
     <div class='review-left'>
       Attribute 1:
     </div>
     <div class='review-right'>
-      {{ review_score.0 }}
+      {{ review_score.0 }}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+      {{ review_avg.0 }}
     </div>
     <br />
     <div class='review-left'>
       Attribute 2:
     </div>
     <div class='review-right'>
-      {{ review_score.1 }}
+      {{ review_score.1 }}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+      {{ review_avg.1 }}
     </div>
     <br />
     <div class='review-left'>
       Attribute 3:
     </div>
     <div class='review-right'>
-      {{ review_score.2 }}
+      {{ review_score.2 }}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+      {{ review_avg.2 }}
     </div><br />
     <div class='review-left'>
       Attribute 4:
     </div>
     <div class='review-right'>
-      {{ review_score.3 }}
+      {{ review_score.3 }}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+      {{ review_avg.3 }}
     </div><br />
     <div class='review-left'>
       Attribute 5:
     </div>
     <div class='review-right'>
-      {{ review_score.4 }}
+      {{ review_score.4 }}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+      {{ review_avg.4 }}
     </div><br />
     <div class='review-left'>
       Attribute 6:
     </div>
     <div class='review-right'>
-      {{ review_score.5 }}
+      {{ review_score.5 }}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+      {{ review_avg.5 }}
     </div><br />
     <div class='review-left'>
       Attribute 7:
     </div>
     <div class='review-right'>
-      {{ review_score.6 }}
+      {{ review_score.6 }}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+      {{ review_avg.6 }}
     </div><br />
     <div class='review-left'>
       Attribute 8:
     </div>
     <div class='review-right'>
-      {{ review_score.7 }}
+      {{ review_score.7 }}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+      {{ review_avg.7 }}
     </div><br />
     <div class='review-left'>
       Attribute 9:
     </div>
     <div class='review-right'>
-      {{ review_score.8 }}
-    </div><br />
+      {{ review_score.8 }}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+      {{ review_avg.8 }}
+    </div><br /><hr /><br />
     <div class='review-left'>
       Overall Score:
     </div>
     <div class='review-right'>
-      {{ total_score }}
+      {{ total_score }}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
+      {{ total_avg }}
     </div>
-  </p>	
-	<p class="post-footer align-right">					
-		<span class="comments">Reviews (5)</span>
-		<span class="date">Last reviewed: Nov 11, 2006</span>
-		<span class="date">Last submitted: Nov 11, 2006</span>	
-	</p>
-				
+  </p>
+
+  <p class="post-footer align-right">
+    <span class="comments">Reviews:
+    {% if nr_reviews %}
+      {{ nr_reviews }}
+    {% else %}
+      (<i>None</i>)
+    {% endif %}
+    </span>
+    <span class="date">Last reviewed:
+    {% if last_reviewed %}
+      {{ last_reviewed|date:"jS F Y h:iA" }}
+    {% else %}
+      (<i>Not Reviewed</i>)
+    {% endif %}
+    </span>
+    <span class="date">Last submitted:
+    {% if last_submitted %}
+      {{ last_submitted|date:"jS F Y h:iA" }}
+    {% else %}
+      (<i>New Submission</i>)
+    {% endif %} 
+    </span> 
+  </p>				
 </div>
 {% endblock content %}
\ No newline at end of file
--- a/app/urls.py	Fri Aug 07 03:16:44 2009 +0530
+++ b/app/urls.py	Fri Aug 07 03:40:08 2009 +0530
@@ -31,7 +31,7 @@
     (r'^proposal/review/(?P<micr_code>[A-Z]{6}\d{9})/$', 
      'app.projrev.views.proposal.review'),
     (r'^proposal/rank/$', 'app.projrev.views.proposal.rank'),
-    (r'^proposal/rank/(?P<micr_code>[A-Z]{6}\d{9})$',
+    (r'^proposal/rank/(?P<micr_code>[A-Z]{6}\d{9})/$',
      'app.projrev.views.proposal.rank'),
     (r'^site-content/(?P<path>.*)', 'django.views.static.serve',
         {'document_root': settings.MEDIA_ROOT}),