Handle empty database in mood template tags

This commit is contained in:
Kumi 2021-03-01 07:12:15 +01:00
parent efc6e1c326
commit 5582f15440

View file

@ -35,6 +35,9 @@ def current_streak(context):
@register.simple_tag(takes_context=True)
def closest_mood(context, value):
if not value:
return None
mood_list = context["user"].mood_set.all()
found = None
@ -86,6 +89,9 @@ def most_common_activity(context, start, end=None):
for activity in status.statusactivity_set.all():
activities.append(activity.activity)
if not activities:
return None
most_common = Counter(activities).most_common(1)[0]
return most_common[0], most_common[1]