summaryrefslogtreecommitdiffstats
path: root/hyperkitty/lib
diff options
context:
space:
mode:
authorAurélien Bompard <aurelien@bompard.org>2013-02-07 11:29:04 +0100
committerAurélien Bompard <aurelien@bompard.org>2013-02-07 11:29:04 +0100
commit76e48cc49fc7c73ba9642129059c2e51234c3fe6 (patch)
tree60a0aa47d588b0f2f77166ef0c3ce26cb35b5242 /hyperkitty/lib
parentbe47fc55a268d80308cb9354c0b9f3c7e78b24b3 (diff)
downloadhyperkitty-76e48cc49fc7c73ba9642129059c2e51234c3fe6.tar.gz
hyperkitty-76e48cc49fc7c73ba9642129059c2e51234c3fe6.tar.xz
hyperkitty-76e48cc49fc7c73ba9642129059c2e51234c3fe6.zip
Fix votes (#34)
- make sure we always use the message_id_hash - factor some code
Diffstat (limited to 'hyperkitty/lib')
-rw-r--r--hyperkitty/lib/__init__.py17
1 files changed, 17 insertions, 0 deletions
diff --git a/hyperkitty/lib/__init__.py b/hyperkitty/lib/__init__.py
index 52b6bdc..b3fa6c4 100644
--- a/hyperkitty/lib/__init__.py
+++ b/hyperkitty/lib/__init__.py
@@ -25,6 +25,8 @@ import datetime
from django.conf import settings
+from hyperkitty.models import Rating
+
def gravatar_url(email):
'''Return a gravatar url for an email address'''
@@ -86,3 +88,18 @@ def get_display_dates(year, month, day):
end_date = begin_date + datetime.timedelta(days=1)
return begin_date, end_date
+
+
+def get_votes(message_id_hash):
+ """Extract all the votes for this message"""
+ likes = dislikes = 0
+ try:
+ votes = Rating.objects.filter(messageid=message_id_hash)
+ except Rating.DoesNotExist:
+ votes = {}
+ for vote in votes:
+ if vote.vote == 1:
+ likes += 1
+ elif vote.vote == -1:
+ dislikes += 1
+ return likes, dislikes