Commits

Simone Marzola committed 3c94e68

catch IntegrityErrors in votes and rollback the transaction

  • Participants
  • Parent commits 5f59c2e

Comments (0)

Files changed (1)

tgcomments/controllers/root.py

 
 def back_to_referer(*args, **kw):
     if not kw.get('success'):
-        flash('Failed to post comment', 'error')
+        flash(_('Failed to post comment'), 'error')
     if request.referer is not None:
         raise redirect(request.referer)
     raise redirect(request.host_url)
 
         try:
             DBSession.flush()
-            transaction.commit()
         except IntegrityError:
-            return back_to_referer(success=False)
+            transaction.doom()
+            flash(_('Already voted this comment'), 'warning')
+            return back_to_referer(success=True)
 
         flash(_('Thanks for your vote!'))
         return back_to_referer(success=True)