fix a display issue in the karma key score
this would probably only matter if adding a key manually that doesn't have a score, but a fix is a fix Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
parent
af4746fb90
commit
cc9b110531
@ -1,14 +1,13 @@
|
|||||||
"""Karma logging models."""
|
"""Karma logging models."""
|
||||||
|
|
||||||
from datetime import timedelta
|
|
||||||
import logging
|
import logging
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
import pytz
|
import pytz
|
||||||
|
|
||||||
from irc.client import NickMask
|
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.db import models
|
from django.db import models
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
from irc.client import NickMask
|
||||||
|
|
||||||
log = logging.getLogger('karma.models')
|
log = logging.getLogger('karma.models')
|
||||||
|
|
||||||
@ -44,12 +43,13 @@ class KarmaKey(models.Model):
|
|||||||
objects = KarmaKeyManager()
|
objects = KarmaKeyManager()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""String representation."""
|
"""Display the karma key and score."""
|
||||||
return "{0:s} ({1:d})".format(self.key, self.score())
|
return "{0:s} ({1:d})".format(self.key, self.score())
|
||||||
|
|
||||||
def score(self):
|
def score(self):
|
||||||
"""Determine the score for this karma entry."""
|
"""Determine the score for this karma entry."""
|
||||||
return KarmaLogEntry.objects.filter(key=self).aggregate(models.Sum('delta'))['delta__sum']
|
score = KarmaLogEntry.objects.filter(key=self).aggregate(models.Sum('delta'))['delta__sum']
|
||||||
|
return score if score else 0
|
||||||
|
|
||||||
def rank(self):
|
def rank(self):
|
||||||
"""Determine the rank of this karma entry relative to the others."""
|
"""Determine the rank of this karma entry relative to the others."""
|
||||||
|
Loading…
Reference in New Issue
Block a user