From e2779c006fd9477151a5873a181b09425dd13277 Mon Sep 17 00:00:00 2001 From: Ohad Lutzky Date: Mon, 2 Aug 2021 21:32:49 +0100 Subject: [PATCH] Hide child column if only one child is shown Fixes #233 --- babybuddy/views.py | 9 +++++++++ core/templates/core/diaperchange_list.html | 8 ++++++-- core/templates/core/feeding_list.html | 8 ++++++-- core/templates/core/note_list.html | 8 ++++++-- core/templates/core/sleep_list.html | 8 ++++++-- core/templates/core/temperature_list.html | 8 ++++++-- core/templates/core/timer_list.html | 16 ++++++++++------ core/templates/core/tummytime_list.html | 8 ++++++-- core/templates/core/weight_list.html | 8 ++++++-- 9 files changed, 61 insertions(+), 20 deletions(-) diff --git a/babybuddy/views.py b/babybuddy/views.py index 58c48284..c089f889 100644 --- a/babybuddy/views.py +++ b/babybuddy/views.py @@ -38,6 +38,15 @@ class BabyBuddyFilterView(FilterView): # TODO Figure out the correct way to use this. strict = False + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + children = { + o.child for o in context['object_list'] if hasattr(o, "child") + } + if len(children) == 1: + context['unique_child'] = True + return context + class UserList(StaffOnlyMixin, BabyBuddyFilterView): model = User diff --git a/core/templates/core/diaperchange_list.html b/core/templates/core/diaperchange_list.html index 664ca139..796981ee 100644 --- a/core/templates/core/diaperchange_list.html +++ b/core/templates/core/diaperchange_list.html @@ -22,7 +22,9 @@ {% trans "Time" %} - {% trans "Child" %} + {% if not unique_child %} + {% trans "Child" %} + {% endif %} {% trans "Contents" %} {% trans "Color" %} {% trans "Amount" %} @@ -34,7 +36,9 @@ {% cycle "odd" "even" as row_class silent %} {{ change.time|datetime_short }} - {{ change.child }} + {% if not unique_child %} + {{ change.child }} + {% endif %} {% if change.wet %}💦{% endif %} {% if change.solid %}💩{% endif %} diff --git a/core/templates/core/feeding_list.html b/core/templates/core/feeding_list.html index b21caefd..b2cfae3a 100644 --- a/core/templates/core/feeding_list.html +++ b/core/templates/core/feeding_list.html @@ -22,7 +22,9 @@ {% trans "Date" %} - {% trans "Child" %} + {% if not unique_child %} + {% trans "Child" %} + {% endif %} {% trans "Method" %} {% trans "Type" %} {% comment %}Abbreviation of "Amount"{% endcomment %} @@ -36,7 +38,9 @@ {% cycle "odd" "even" as row_class silent %} {{ feeding.start|datetime_short }} - {{ feeding.child }} + {% if not unique_child %} + {{ feeding.child }} + {% endif %} {{ feeding.get_method_display }} {{ feeding.get_type_display }} diff --git a/core/templates/core/note_list.html b/core/templates/core/note_list.html index f65fa478..46b7ba19 100644 --- a/core/templates/core/note_list.html +++ b/core/templates/core/note_list.html @@ -22,7 +22,9 @@ {% trans "Time" %} - {% trans "Child" %} + {% if not unique_child %} + {% trans "Child" %} + {% endif %} {% trans "Note" %} {% trans "Actions" %} @@ -31,7 +33,9 @@ {% for note in object_list %} {{ note.time|datetime_short }} - {{ note.child }} + {% if not unique_child %} + {{ note.child }} + {% endif %} {{ note.note }}
diff --git a/core/templates/core/sleep_list.html b/core/templates/core/sleep_list.html index ab3b2f43..3bd7cce0 100644 --- a/core/templates/core/sleep_list.html +++ b/core/templates/core/sleep_list.html @@ -23,7 +23,9 @@ {% trans "Start" %} {% trans "End" %} - {% trans "Child" %} + {% if not unique_child %} + {% trans "Child" %} + {% endif %} {% trans "Duration" %} {% trans "Nap" %} {% trans "Actions" %} @@ -35,7 +37,9 @@ {{ sleep.start|datetime_short }} {{ sleep.end|datetime_short }} - {{ sleep.child }} + {% if not unique_child %} + {{ sleep.child }} + {% endif %} {{ sleep.duration|duration_string }} {{ sleep.nap|bool_icon }} diff --git a/core/templates/core/temperature_list.html b/core/templates/core/temperature_list.html index 046a293b..74997636 100644 --- a/core/templates/core/temperature_list.html +++ b/core/templates/core/temperature_list.html @@ -22,7 +22,9 @@ {% trans "Time" %} - {% trans "Child" %} + {% if not unique_child %} + {% trans "Child" %} + {% endif %} {% trans "Temperature" %} {% trans "Actions" %} @@ -32,7 +34,9 @@ {% cycle "odd" "even" as row_class silent %} {{ temperature.time|datetime_short }} - {{ temperature.child }} + {% if not unique_child %} + {{ temperature.child }} + {% endif %} {{ temperature.temperature }}
diff --git a/core/templates/core/timer_list.html b/core/templates/core/timer_list.html index 12c3eee1..570328ab 100644 --- a/core/templates/core/timer_list.html +++ b/core/templates/core/timer_list.html @@ -23,7 +23,9 @@ {% trans "Start" %} {% trans "Name" %} - {% trans "Child" %} + {% if not unique_child %} + {% trans "Child" %} + {% endif %} {% trans "Duration" %} {% trans "End" %} {% trans "Active" %} @@ -35,11 +37,13 @@ {{ timer.start|datetime_short }} {{ timer }} - - {% if timer.child %} - {{ timer.child }} - {% endif %} - + {% if not unique_child %} + + {% if timer.child %} + {{ timer.child }} + {% endif %} + + {% endif %} {{ timer.duration|duration_string }} {% if timer.end %} diff --git a/core/templates/core/tummytime_list.html b/core/templates/core/tummytime_list.html index f05d5c98..c9f50113 100644 --- a/core/templates/core/tummytime_list.html +++ b/core/templates/core/tummytime_list.html @@ -22,7 +22,9 @@ {% trans "Start" %} {% trans "End" %} - {% trans "Child" %} + {% if not unique_child %} + {% trans "Child" %} + {% endif %} {% trans "Duration" %} {% trans "Milestone" %} {% trans "Actions" %} @@ -33,7 +35,9 @@ {{ tummytime.start|datetime_short }} {{ tummytime.end|datetime_short }} - {{ tummytime.child }} + {% if not unique_child %} + {{ tummytime.child }} + {% endif %} {{ tummytime.duration|duration_string }} {{ tummytime.milestone }} diff --git a/core/templates/core/weight_list.html b/core/templates/core/weight_list.html index 464a7748..d89a79cd 100644 --- a/core/templates/core/weight_list.html +++ b/core/templates/core/weight_list.html @@ -22,7 +22,9 @@ {% trans "Date" %} - {% trans "Child" %} + {% if not unique_child %} + {% trans "Child" %} + {% endif %} {% trans "Weight" %} {% trans "Actions" %} @@ -32,7 +34,9 @@ {% cycle "odd" "even" as row_class silent %} {{ weight.date }} - {{ weight.child }} + {% if not unique_child %} + {{ weight.child }} + {% endif %} {{ weight.weight }}