Commits

pag committed 9f93acd

prevent users from adding more than one review per module.

  • Participants
  • Parent commits 0325360

Comments (0)

Files changed (3)

acs/templates/module.htm

                 <td>
                     {% if invalid_text %}
                     <div class="error">Please write a slightly better, longer review</div><br />
-                    {% endif %}
+                    {% else %}{% if invalid_repeat %}
+                    <div class="error">You've already reviewed this module. Contact {{ admin }} to modify your previous one.</div><br />
+                    {% endif %}{% endif %}
                     <textarea name="review" cols="60" rows="12">{{ review }}</textarea>
                 </td>
             </tr>
     invalid_difficulty = post and not difficulty
     invalid_enjoyment = post and not enjoyment
     invalid_text = post and review.count(' ') < 10
-    invalid = invalid_difficulty or invalid_enjoyment or invalid_text
+    user = request.META.get('REMOTE_USER', 'test0')
+    invalid_repeat = len(reviews.filter(reviewer=user)) != 0
+    invalid = invalid_difficulty or invalid_enjoyment or invalid_text or invalid_repeat
 
     if post and not invalid:
-        r = models.Review(reviewer=request.META['REMOTE_USER'], module=code, difficulty=difficulty, enjoyment=enjoyment, review=review)
+        r = models.Review(reviewer=user, module=code, difficulty=difficulty, enjoyment=enjoyment, review=review)
         r.save()
         difficulty = enjoyment = 0
         review = ''
 
-    return render('module', request, module=mod, difficulty=difficulty, enjoyment=enjoyment, review=review, post=post, invalid=invalid, invalid_difficulty=invalid_difficulty, invalid_enjoyment=invalid_enjoyment, invalid_text=invalid_text, reviews=reviews)
+    admin = '%s (%s)' % settings.ADMINS[0]
+    return render('module', request, module=mod, difficulty=difficulty, enjoyment=enjoyment, review=review, post=post, invalid=invalid, invalid_difficulty=invalid_difficulty, invalid_enjoyment=invalid_enjoyment, invalid_text=invalid_text, invalid_repeat=invalid_repeat, reviews=reviews, admin=admin)
 
 TEMPLATE_DEBUG = DEBUG
 
 ADMINS = (
-    # ('Your Name', 'your_email@example.com'),
+    ('Paul Giannaros', 'paul@giannaros.org'),
 )
 
 MANAGERS = ADMINS