Hide Child from Timer detail in one child use cases

This commit is contained in:
Christopher C. Wells 2020-01-31 12:01:17 -08:00
parent b5dc34e388
commit 17ed16bc8b
3 changed files with 27 additions and 2 deletions

View File

@ -3,6 +3,8 @@ from django import template
from django.apps import apps from django.apps import apps
from django.utils.translation import to_locale, get_language from django.utils.translation import to_locale, get_language
from core.models import Child
register = template.Library() register = template.Library()
@ -43,3 +45,8 @@ def get_current_locale():
:return: locale code (e.g. 'de', 'fr', etc.). :return: locale code (e.g. 'de', 'fr', etc.).
""" """
return to_locale(get_language()) return to_locale(get_language())
@register.simple_tag()
def get_child_count():
return Child.count()

View File

@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
from django.test import TestCase
from django.utils import timezone
from core.models import Child
from babybuddy.templatetags import babybuddy_tags
class TemplateTagsTestCase(TestCase):
def test_child_count(self):
self.assertEqual(babybuddy_tags.get_child_count(), 0)
Child.objects.create(first_name='Test', last_name='Child',
birth_date=timezone.localdate())
self.assertEqual(babybuddy_tags.get_child_count(), 1)
Child.objects.create(first_name='Test', last_name='Child 2',
birth_date=timezone.localdate())
self.assertEqual(babybuddy_tags.get_child_count(), 2)

View File

@ -1,5 +1,6 @@
{% extends 'babybuddy/page.html' %} {% extends 'babybuddy/page.html' %}
{% load duration i18n timers %} {% load babybuddy_tags duration i18n timers %}
{% get_child_count as CHILD_COUNT %}
{% block title %}{{ object }}{% endblock %} {% block title %}{{ object }}{% endblock %}
@ -17,7 +18,7 @@
<span class="timer-seconds">{{ object.duration|seconds }}</span>s <span class="timer-seconds">{{ object.duration|seconds }}</span>s
</h1> </h1>
{% if timer.child %} {% if timer.child and CHILD_COUNT > 1 %}
<h2 class="text-muted"> <h2 class="text-muted">
{{ timer.child }} {{ timer.child }}
</h2> </h2>