mirror of https://github.com/snachodog/mybuddy.git
Don't include duration on timeline entries with no duration
This commit is contained in:
parent
9baec8d906
commit
31f8f951ad
|
@ -1,10 +1,12 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from datetime import timedelta
|
||||
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone, timesince
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from core.models import DiaperChange, Feeding, Note, Sleep, TummyTime, Temperature
|
||||
from datetime import timedelta
|
||||
from core.utils import duration_string
|
||||
|
||||
|
||||
def get_objects(date, child=None):
|
||||
|
@ -60,19 +62,21 @@ def _add_tummy_times(min_date, max_date, events, child=None):
|
|||
"tags": instance.tags.all(),
|
||||
}
|
||||
)
|
||||
events.append(
|
||||
{
|
||||
|
||||
end = {
|
||||
"time": timezone.localtime(instance.end),
|
||||
"event": _("%(child)s finished tummy time.")
|
||||
% {"child": instance.child.first_name},
|
||||
"details": details,
|
||||
"edit_link": edit_link,
|
||||
"duration": timesince.timesince(instance.start, now=instance.end),
|
||||
"model_name": instance.model_name,
|
||||
"type": "end",
|
||||
"tags": instance.tags.all(),
|
||||
}
|
||||
)
|
||||
if instance.duration > timedelta(seconds=0):
|
||||
end["duration"] = duration_string(instance.duration)
|
||||
|
||||
events.append(end)
|
||||
|
||||
|
||||
def _add_sleeps(min_date, max_date, events, child=None):
|
||||
|
@ -98,18 +102,19 @@ def _add_sleeps(min_date, max_date, events, child=None):
|
|||
"tags": instance.tags.all(),
|
||||
}
|
||||
)
|
||||
events.append(
|
||||
{
|
||||
|
||||
end = {
|
||||
"time": timezone.localtime(instance.end),
|
||||
"event": _("%(child)s woke up.") % {"child": instance.child.first_name},
|
||||
"details": details,
|
||||
"edit_link": edit_link,
|
||||
"duration": timesince.timesince(instance.start, now=instance.end),
|
||||
"model_name": instance.model_name,
|
||||
"type": "end",
|
||||
"tags": instance.tags.all(),
|
||||
}
|
||||
)
|
||||
if instance.duration > timedelta(seconds=0):
|
||||
end["duration"] = duration_string(instance.duration)
|
||||
events.append(end)
|
||||
|
||||
|
||||
def _add_feedings(min_date, max_date, events, child=None):
|
||||
|
@ -153,8 +158,8 @@ def _add_feedings(min_date, max_date, events, child=None):
|
|||
"tags": instance.tags.all(),
|
||||
}
|
||||
)
|
||||
events.append(
|
||||
{
|
||||
|
||||
end = {
|
||||
"time": timezone.localtime(instance.end),
|
||||
"event": _("%(child)s finished feeding.")
|
||||
% {"child": instance.child.first_name},
|
||||
|
@ -165,7 +170,9 @@ def _add_feedings(min_date, max_date, events, child=None):
|
|||
"type": "end",
|
||||
"tags": instance.tags.all(),
|
||||
}
|
||||
)
|
||||
if instance.duration > timedelta(seconds=0):
|
||||
end["duration"] = duration_string(instance.duration)
|
||||
events.append(end)
|
||||
|
||||
|
||||
def _add_diaper_changes(min_date, max_date, events, child):
|
||||
|
|
|
@ -38,7 +38,7 @@ def duration_string(duration, precision="s"):
|
|||
duration = ""
|
||||
if h > 0:
|
||||
duration = ngettext("%(hours)s hour", "%(hours)s hours", h) % {"hours": h}
|
||||
if m >= 0 and precision != "h":
|
||||
if m > 0 and precision != "h":
|
||||
if duration != "":
|
||||
duration += ", "
|
||||
duration += ngettext("%(minutes)s minute", "%(minutes)s minutes", m) % {
|
||||
|
|
Loading…
Reference in New Issue