diff --git a/core/models.py b/core/models.py index 2e1ef679..78f6afec 100644 --- a/core/models.py +++ b/core/models.py @@ -183,5 +183,8 @@ class TummyTime(models.Model): def duration(self): return duration_string(self.start, self.end) + def duration_td(self): + return self.end - self.start + def since(self, time=timezone.now()): return timesince.timesince(self.end, time) diff --git a/dashboard/templates/cards/tummytime.html b/dashboard/templates/cards/tummytime.html index 8a8d22ac..91b252c2 100644 --- a/dashboard/templates/cards/tummytime.html +++ b/dashboard/templates/cards/tummytime.html @@ -7,6 +7,7 @@

{% block title %}{% endblock %}

{% block content %}{% endblock %}
+ {% block listgroup %}{% endblock %} diff --git a/dashboard/templates/cards/tummytime_day.html b/dashboard/templates/cards/tummytime_day.html new file mode 100644 index 00000000..8ca5ea7e --- /dev/null +++ b/dashboard/templates/cards/tummytime_day.html @@ -0,0 +1,21 @@ +{% extends 'cards/tummytime.html' %} + +{% block header %}Today's Tummy Time{% endblock %} + +{% block title %} + {{ stats.total }} seconds +{% endblock %} + +{% block content %} + {{ stats.count }} total entries +{% endblock %} + +{% block listgroup %} + +{% endblock %} + +{% block footer %}Time since last: {{ last.end|timesince }}{% endblock %} \ No newline at end of file diff --git a/dashboard/templates/dashboard/child.html b/dashboard/templates/dashboard/child.html index eae0e57c..0f365336 100644 --- a/dashboard/templates/dashboard/child.html +++ b/dashboard/templates/dashboard/child.html @@ -9,6 +9,7 @@ {% card_feeding_last object %} {% card_diaperchange_last object %} {% card_tummytime_last object %} + {% card_tummytime_day object %} {% card_sleep_last object %} {% card_diaperchange_types object %} diff --git a/dashboard/templatetags/dashboard.py b/dashboard/templatetags/dashboard.py index 68e4719e..1732f912 100644 --- a/dashboard/templatetags/dashboard.py +++ b/dashboard/templatetags/dashboard.py @@ -55,6 +55,16 @@ def card_tummytime_last(child): return {'tummytime': instance} +@register.inclusion_tag('cards/tummytime_day.html') +def card_tummytime_day(child, date=timezone.now().date()): + instances = TummyTime.objects.filter( + child=child, end__day=date.day).order_by('-end') + stats = {'total': 0, 'count': instances.count()} + for instance in instances: + stats['total'] += instance.duration_td().seconds + return {'stats': stats, 'instances': instances, 'last': instances.first()} + + @register.inclusion_tag('cards/sleep_last.html') def card_sleep_last(child): instance = Sleep.objects.filter(child=child).order_by('-end').first()