mirror of https://github.com/snachodog/mybuddy.git
Move duration tools to a separate template tag collection.
This commit is contained in:
parent
6f4774ae9e
commit
21e4af6f58
|
@ -1,6 +1,6 @@
|
||||||
{% extends 'babyblotter/page.html' %}
|
{% extends 'babyblotter/page.html' %}
|
||||||
{% load widget_tweaks %}
|
{% load widget_tweaks %}
|
||||||
{% load timers %}
|
{% load duration %}
|
||||||
|
|
||||||
{% block title %}Feedings{% endblock %}
|
{% block title %}Feedings{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{% extends 'babyblotter/page.html' %}
|
{% extends 'babyblotter/page.html' %}
|
||||||
{% load widget_tweaks %}
|
{% load widget_tweaks %}
|
||||||
{% load timers %}
|
{% load duration %}
|
||||||
|
|
||||||
{% block title %}Sleep{% endblock %}
|
{% block title %}Sleep{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
{% extends 'babyblotter/page.html' %}
|
{% extends 'babyblotter/page.html' %}
|
||||||
{% load timers %}
|
{% load timers %}
|
||||||
|
{% load duration %}
|
||||||
|
|
||||||
{% block title %}{{ object }}{% endblock %}
|
{% block title %}{{ object }}{% endblock %}
|
||||||
|
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<div class="jumbotron text-center">
|
<div class="jumbotron text-center">
|
||||||
<h1 class="display-1">{{ object.current_duration|duration_string_short }}</h1>
|
<h1 class="display-1">
|
||||||
|
<span id="timer_hours">{{ object.current_duration|hours }}</span>h
|
||||||
|
<span id="timer_minutes">{{ object.current_duration|minutes }}</span>m
|
||||||
|
<span id="timer_seconds">{{ object.current_duration|seconds }}</span>s
|
||||||
|
</h1>
|
||||||
<p class="lead text-muted">Started {{ object.start }} by {{ object.user }}</p>
|
<p class="lead text-muted">Started {{ object.start }} by {{ object.user }}</p>
|
||||||
|
|
||||||
{% if perms.core.add_feeding %}
|
{% if perms.core.add_feeding %}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{% extends 'babyblotter/page.html' %}
|
{% extends 'babyblotter/page.html' %}
|
||||||
{% load widget_tweaks %}
|
{% load widget_tweaks %}
|
||||||
{% load timers %}
|
{% load duration %}
|
||||||
|
|
||||||
{% block title %}Tummy Time{% endblock %}
|
{% block title %}Tummy Time{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,53 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from datetime import timedelta
|
||||||
|
|
||||||
|
from django import template
|
||||||
|
|
||||||
|
|
||||||
|
register = template.Library()
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def duration_string(duration):
|
||||||
|
h, m, s = _get_hms(duration)
|
||||||
|
|
||||||
|
duration = ''
|
||||||
|
if h > 0:
|
||||||
|
duration = '{} hour{}'.format(h, 's' if h > 1 else '')
|
||||||
|
if m > 0:
|
||||||
|
duration += '{}{} minute{}'.format(
|
||||||
|
'' if duration is '' else ', ', m, 's' if m > 1 else '')
|
||||||
|
if s > 0:
|
||||||
|
duration += '{}{} second{}'.format(
|
||||||
|
'' if duration is '' else ', ', s, 's' if s > 1 else '')
|
||||||
|
|
||||||
|
return duration
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def hours(duration):
|
||||||
|
h, m, s = _get_hms(duration)
|
||||||
|
return h
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def minutes(duration):
|
||||||
|
h, m, s = _get_hms(duration)
|
||||||
|
return m
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def seconds(duration):
|
||||||
|
h, m, s = _get_hms(duration)
|
||||||
|
return s
|
||||||
|
|
||||||
|
|
||||||
|
def _get_hms(duration):
|
||||||
|
"""Get hours, minutes and seconds from a timedelta."""
|
||||||
|
if not isinstance(duration, timedelta):
|
||||||
|
return 0, 0, 0
|
||||||
|
h, remainder = divmod(duration.seconds, 3600)
|
||||||
|
m, s = divmod(remainder, 60)
|
||||||
|
return h, m, s
|
|
@ -30,35 +30,3 @@ def timer_nav(context, active=True):
|
||||||
@register.inclusion_tag('core/timer_add.html')
|
@register.inclusion_tag('core/timer_add.html')
|
||||||
def add_timer(success_url):
|
def add_timer(success_url):
|
||||||
return {'success_url': success_url}
|
return {'success_url': success_url}
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
|
||||||
def duration_string(duration):
|
|
||||||
if not isinstance(duration, timedelta):
|
|
||||||
return duration
|
|
||||||
|
|
||||||
h, remainder = divmod(duration.seconds, 3600)
|
|
||||||
m, s = divmod(remainder, 60)
|
|
||||||
|
|
||||||
duration = ''
|
|
||||||
if h > 0:
|
|
||||||
duration = '{} hour{}'.format(h, 's' if h > 1 else '')
|
|
||||||
if m > 0:
|
|
||||||
duration += '{}{} minute{}'.format(
|
|
||||||
'' if duration is '' else ', ', m, 's' if m > 1 else '')
|
|
||||||
if s > 0:
|
|
||||||
duration += '{}{} second{}'.format(
|
|
||||||
'' if duration is '' else ', ', s, 's' if s > 1 else '')
|
|
||||||
|
|
||||||
return duration
|
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
|
||||||
def duration_string_short(duration):
|
|
||||||
if not isinstance(duration, timedelta):
|
|
||||||
return duration
|
|
||||||
|
|
||||||
h, remainder = divmod(duration.seconds, 3600)
|
|
||||||
m, s = divmod(remainder, 60)
|
|
||||||
|
|
||||||
return '{}h {}m {}s'.format(h, m, s)
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{% extends 'cards/sleep.html' %}
|
{% extends 'cards/sleep.html' %}
|
||||||
{% load timers %}
|
{% load duration %}
|
||||||
|
|
||||||
{% block header %}Last Slept{% endblock %}
|
{% block header %}Last Slept{% endblock %}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
{% extends 'cards/tummytime.html' %}
|
{% extends 'cards/tummytime.html' %}
|
||||||
{% load timers %}
|
{% load duration %}
|
||||||
|
|
||||||
{% block header %}Last Tummy Time{% endblock %}
|
{% block header %}Last Tummy Time{% endblock %}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue