mirror of https://github.com/snachodog/mybuddy.git
Hide Child from Timer detail in one child use cases
This commit is contained in:
parent
b5dc34e388
commit
17ed16bc8b
|
@ -3,6 +3,8 @@ from django import template
|
|||
from django.apps import apps
|
||||
from django.utils.translation import to_locale, get_language
|
||||
|
||||
from core.models import Child
|
||||
|
||||
register = template.Library()
|
||||
|
||||
|
||||
|
@ -43,3 +45,8 @@ def get_current_locale():
|
|||
:return: locale code (e.g. 'de', 'fr', etc.).
|
||||
"""
|
||||
return to_locale(get_language())
|
||||
|
||||
|
||||
@register.simple_tag()
|
||||
def get_child_count():
|
||||
return Child.count()
|
|
@ -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)
|
|
@ -1,5 +1,6 @@
|
|||
{% extends 'babybuddy/page.html' %}
|
||||
{% load duration i18n timers %}
|
||||
{% load babybuddy_tags duration i18n timers %}
|
||||
{% get_child_count as CHILD_COUNT %}
|
||||
|
||||
{% block title %}{{ object }}{% endblock %}
|
||||
|
||||
|
@ -17,7 +18,7 @@
|
|||
<span class="timer-seconds">{{ object.duration|seconds }}</span>s
|
||||
</h1>
|
||||
|
||||
{% if timer.child %}
|
||||
{% if timer.child and CHILD_COUNT > 1 %}
|
||||
<h2 class="text-muted">
|
||||
{{ timer.child }}
|
||||
</h2>
|
||||
|
|
Loading…
Reference in New Issue