Handle empty database in mood template tags
This commit is contained in:
parent
efc6e1c326
commit
5582f15440
1 changed files with 6 additions and 0 deletions
|
@ -35,6 +35,9 @@ def current_streak(context):
|
||||||
|
|
||||||
@register.simple_tag(takes_context=True)
|
@register.simple_tag(takes_context=True)
|
||||||
def closest_mood(context, value):
|
def closest_mood(context, value):
|
||||||
|
if not value:
|
||||||
|
return None
|
||||||
|
|
||||||
mood_list = context["user"].mood_set.all()
|
mood_list = context["user"].mood_set.all()
|
||||||
|
|
||||||
found = None
|
found = None
|
||||||
|
@ -86,6 +89,9 @@ def most_common_activity(context, start, end=None):
|
||||||
for activity in status.statusactivity_set.all():
|
for activity in status.statusactivity_set.all():
|
||||||
activities.append(activity.activity)
|
activities.append(activity.activity)
|
||||||
|
|
||||||
|
if not activities:
|
||||||
|
return None
|
||||||
|
|
||||||
most_common = Counter(activities).most_common(1)[0]
|
most_common = Counter(activities).most_common(1)[0]
|
||||||
|
|
||||||
return most_common[0], most_common[1]
|
return most_common[0], most_common[1]
|
||||||
|
|
Loading…
Reference in a new issue