mirror of https://github.com/snachodog/mybuddy.git
Add Tummy Time day activity card.
This commit is contained in:
parent
c2c708883e
commit
25fbf4c4d0
|
@ -183,5 +183,8 @@ class TummyTime(models.Model):
|
||||||
def duration(self):
|
def duration(self):
|
||||||
return duration_string(self.start, self.end)
|
return duration_string(self.start, self.end)
|
||||||
|
|
||||||
|
def duration_td(self):
|
||||||
|
return self.end - self.start
|
||||||
|
|
||||||
def since(self, time=timezone.now()):
|
def since(self, time=timezone.now()):
|
||||||
return timesince.timesince(self.end, time)
|
return timesince.timesince(self.end, time)
|
||||||
|
|
|
@ -7,6 +7,7 @@
|
||||||
<h4 class="card-title">{% block title %}{% endblock %}</h4>
|
<h4 class="card-title">{% block title %}{% endblock %}</h4>
|
||||||
<div class="card-text">{% block content %}{% endblock %}</div>
|
<div class="card-text">{% block content %}{% endblock %}</div>
|
||||||
</div>
|
</div>
|
||||||
|
{% block listgroup %}{% endblock %}
|
||||||
<div class="card-footer text-muted">
|
<div class="card-footer text-muted">
|
||||||
{% block footer %}{% endblock %}
|
{% block footer %}{% endblock %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -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 %}
|
|
@ -9,6 +9,7 @@
|
||||||
{% card_feeding_last object %}
|
{% card_feeding_last object %}
|
||||||
{% card_diaperchange_last object %}
|
{% card_diaperchange_last object %}
|
||||||
{% card_tummytime_last object %}
|
{% card_tummytime_last object %}
|
||||||
|
{% card_tummytime_day object %}
|
||||||
{% card_sleep_last object %}
|
{% card_sleep_last object %}
|
||||||
{% card_diaperchange_types object %}
|
{% card_diaperchange_types object %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -55,6 +55,16 @@ def card_tummytime_last(child):
|
||||||
return {'tummytime': instance}
|
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')
|
@register.inclusion_tag('cards/sleep_last.html')
|
||||||
def card_sleep_last(child):
|
def card_sleep_last(child):
|
||||||
instance = Sleep.objects.filter(child=child).order_by('-end').first()
|
instance = Sleep.objects.filter(child=child).order_by('-end').first()
|
||||||
|
|
Loading…
Reference in New Issue