summaryrefslogtreecommitdiffstats
path: root/forum/models/repute.py
diff options
context:
space:
mode:
Diffstat (limited to 'forum/models/repute.py')
-rwxr-xr-xforum/models/repute.py36
1 files changed, 19 insertions, 17 deletions
diff --git a/forum/models/repute.py b/forum/models/repute.py
index 533f1323..5e42542f 100755
--- a/forum/models/repute.py
+++ b/forum/models/repute.py
@@ -81,24 +81,26 @@ class ReputeManager(models.Manager):
by upvoted(also substracted from upvoted canceled). This is because we need
to prohibit gaming system by upvoting/cancel again and again.
"""
- if user is not None:
- today = datetime.date.today()
- sums = self.filter(models.Q(reputation_type=1) | models.Q(reputation_type=-8),
- user=user, reputed_at__range=(today, today + datetime.timedelta(1))). \
- aggregate(models.Sum('positive'), models.Sum('negative'))
-
- positive = sums['positive__sum']
- negative = sums['negative__sum']
-
- if positive is None:
- positive = 0
-
- if negative is None:
- negative = 0
-
- return positive + negative
- else:
+ if user is None:
return 0
+ else:
+ today = datetime.date.today()
+ tomorrow = today + datetime.timedelta(1)
+ rep_types = (1,-8)
+ sums = self.filter(models.Q(reputation_type__in=(1,-8)),
+ user=user,
+ reputed_at__range=(today, tomorrow),
+ ).aggregate(models.Sum('positive'), models.Sum('negative'))
+ if sums:
+ pos = sums['positive__sum']
+ neg = sums['negative__sum']
+ if pos is None:
+ pos = 0
+ if neg is None:
+ neg = 0
+ return pos + neg
+ else:
+ return 0
class Repute(models.Model):
"""The reputation histories for user"""