Added overview of private reviews to the Student Proposal review page.
authorLennard de Rijk <ljvderijk@gmail.com>
Sun, 12 Apr 2009 16:09:00 +0000
changeset 2173 27731db8ab1e
parent 2172 ac7bd3b467ff
child 2174 19ed1c42e836
Added overview of private reviews to the Student Proposal review page. Addresses Issue 496. Patch by: Lennard de Rijk Reviewed by: to-be-reviewed
app/soc/templates/soc/student_proposal/review.html
app/soc/views/models/student_proposal.py
--- a/app/soc/templates/soc/student_proposal/review.html	Sun Apr 12 13:22:43 2009 +0000
+++ b/app/soc/templates/soc/student_proposal/review.html	Sun Apr 12 16:09:00 2009 +0000
@@ -60,6 +60,12 @@
 </p>
 
 <hr />
+<b>Summary of Reviews</b>:
+{% for key, value in review_summary.items %}
+    <li>{{ value.name }} ({{ value.total_comments }} posts, {{ value.total_score }} points)</li>
+{% endfor %}
+
+<hr />
 <form method="POST">
 <b>Score and Review</b>
 
--- a/app/soc/views/models/student_proposal.py	Sun Apr 12 13:22:43 2009 +0000
+++ b/app/soc/views/models/student_proposal.py	Sun Apr 12 16:09:00 2009 +0000
@@ -900,20 +900,47 @@
 
       context['possible_mentors'] = ', '.join(mentor_names)
 
-    # TODO(ljvderijk) listing of total given scores per mentor
-    # a dict with key as role.user ?
-
     # order the reviews by ascending creation date
     order = ['created']
 
     # get the public reviews
-    context['public_reviews'] = review_logic.getReviewsForEntity(entity,
+    public_reviews = review_logic.getReviewsForEntity(entity,
         is_public=True, order=order)
 
     # get the private reviews
-    context['private_reviews'] = review_logic.getReviewsForEntity(entity,
+    private_reviews = review_logic.getReviewsForEntity(entity,
         is_public=False, order=order)
 
+    # store the reviews in the context
+    context['public_reviews'] = public_reviews
+    context['private_reviews'] = private_reviews
+
+    review_summary = {}
+
+    for review in private_reviews:
+
+      reviewer = review.reviewer
+      if not reviewer:
+        continue
+
+      reviewer_key = reviewer.key()
+      reviewer_summary = review_summary.get(reviewer_key)
+
+      if reviewer_summary:
+        # we already have something on file for this reviewer
+        old_total_score = reviewer_summary['total_score']
+        reviewer_summary['total_score'] = old_total_score + review.score
+
+        old_total_comments = reviewer_summary['total_comments']
+        reviewer_summary['total_comments'] = old_total_comments + 1
+      else:
+        review_summary[reviewer_key] = {
+            'name': reviewer.name(),
+            'total_comments': 1,
+            'total_score': review.score}
+
+    context['review_summary'] = review_summary
+
     # which button should we show to the mentor?
     if mentor:
       context['is_mentor'] = True