mirror of https://github.com/snachodog/mybuddy.git
Add a "naps" card.
This commit is contained in:
parent
029f554dfc
commit
66a91fe534
|
@ -0,0 +1,22 @@
|
||||||
|
{% extends 'cards/sleep.html' %}
|
||||||
|
{% load duration %}
|
||||||
|
|
||||||
|
{% block header %}Today's Naps{% endblock %}
|
||||||
|
|
||||||
|
{% block title %}
|
||||||
|
{% if count %}
|
||||||
|
<strong>{{ count }} naps</strong>
|
||||||
|
{% else %}
|
||||||
|
<i class="icon icon-sad" aria-hidden="true"></i>
|
||||||
|
<strong>None yet today</strong>
|
||||||
|
<i class="icon icon-sad" aria-hidden="true"></i>
|
||||||
|
{% endif %}
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<div class="text-muted">
|
||||||
|
{{ total.duration__sum|duration_string }}
|
||||||
|
</div>
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block footer %}<em>Naps are sleep entries starting 7AM - 7PM.</em>{% endblock %}
|
|
@ -19,6 +19,7 @@
|
||||||
<div class="col-lg-4 col-md-6 col-sm-12">
|
<div class="col-lg-4 col-md-6 col-sm-12">
|
||||||
{% card_sleep_last object %}
|
{% card_sleep_last object %}
|
||||||
{% card_sleep_day object %}
|
{% card_sleep_day object %}
|
||||||
|
{% card_sleep_naps_day object %}
|
||||||
{% card_tummytime_day object %}
|
{% card_tummytime_day object %}
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-4 col-md-6 col-sm-12">
|
<div class="col-lg-4 col-md-6 col-sm-12">
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from django import template
|
from django import template
|
||||||
|
from django.db.models import Sum
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
|
|
||||||
from core.models import DiaperChange, Feeding, Sleep, Timer, TummyTime
|
from core.models import DiaperChange, Feeding, Sleep, Timer, TummyTime
|
||||||
|
@ -103,12 +104,25 @@ def card_sleep_day(child, date=None):
|
||||||
total += end - start
|
total += end - start
|
||||||
|
|
||||||
count = len(instances)
|
count = len(instances)
|
||||||
if count > 0:
|
|
||||||
average = total/count
|
|
||||||
else:
|
|
||||||
average = 0
|
|
||||||
|
|
||||||
return {'total': total, 'count': count, 'average': average}
|
return {'total': total, 'count': count}
|
||||||
|
|
||||||
|
|
||||||
|
@register.inclusion_tag('cards/sleep_naps_day.html')
|
||||||
|
def card_sleep_naps_day(child, date=None):
|
||||||
|
"""Nap information for the current day.
|
||||||
|
"""
|
||||||
|
local = timezone.localtime(date)
|
||||||
|
start_lower = local.replace(
|
||||||
|
hour=7, minute=0, second=0).astimezone(timezone.utc)
|
||||||
|
start_upper = local.replace(
|
||||||
|
hour=19, minute=0, second=0).astimezone(timezone.utc)
|
||||||
|
instances = Sleep.objects.filter(child=child) \
|
||||||
|
.filter(start__gte=start_lower, start__lte=start_upper)
|
||||||
|
return {
|
||||||
|
'total': instances.aggregate(Sum('duration')),
|
||||||
|
'count': len(instances)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@register.inclusion_tag('cards/timer_list.html')
|
@register.inclusion_tag('cards/timer_list.html')
|
||||||
|
|
Loading…
Reference in New Issue