Add Tummy Time day activity card.

This commit is contained in:
Christopher Charbonneau Wells 2017-08-18 14:58:10 -04:00
parent c2c708883e
commit 25fbf4c4d0
5 changed files with 36 additions and 0 deletions

View File

@ -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)

View File

@ -7,6 +7,7 @@
<h4 class="card-title">{% block title %}{% endblock %}</h4>
<div class="card-text">{% block content %}{% endblock %}</div>
</div>
{% block listgroup %}{% endblock %}
<div class="card-footer text-muted">
{% block footer %}{% endblock %}
</div>

View File

@ -0,0 +1,21 @@
{% extends 'cards/tummytime.html' %}
{% block header %}Today's Tummy Time{% endblock %}
{% block title %}
<strong>{{ stats.total }}</strong> seconds
{% endblock %}
{% block content %}
{{ stats.count }} total entries
{% endblock %}
{% block listgroup %}
<ul class="list-group list-group-flush text-muted small">
{% for instance in instances %}
<li class="list-group-item">{{ instance.duration }} at {{ instance.end|time }}</li>
{% endfor %}
</ul>
{% endblock %}
{% block footer %}Time since last: {{ last.end|timesince }}{% endblock %}

View File

@ -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 %}
</div>

View File

@ -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()