Hide child column if only one child is shown

Fixes #233
This commit is contained in:
Ohad Lutzky 2021-08-02 21:32:49 +01:00 committed by Christopher Charbonneau Wells
parent 9d2e539fc4
commit e2779c006f
9 changed files with 61 additions and 20 deletions

View File

@ -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

View File

@ -22,7 +22,9 @@
<thead class="thead-inverse">
<tr>
<th>{% trans "Time" %}</th>
<th>{% trans "Child" %}</th>
{% if not unique_child %}
<th>{% trans "Child" %}</th>
{% endif %}
<th class="text-center">{% trans "Contents" %}</th>
<th>{% trans "Color" %}</th>
<th>{% trans "Amount" %}</th>
@ -34,7 +36,9 @@
{% cycle "odd" "even" as row_class silent %}
<tr class="{{ row_class }}">
<th scope="row">{{ change.time|datetime_short }}</th>
<td><a href="{% url 'core:child' change.child.slug %}">{{ change.child }}</a></td>
{% if not unique_child %}
<td><a href="{% url 'core:child' change.child.slug %}">{{ change.child }}</a></td>
{% endif %}
<td class="text-center">
{% if change.wet %}<span title="{% trans "Wet" %}">💦</span>{% endif %}
{% if change.solid %}<span title="{% trans "Solid" %}">💩</span>{% endif %}

View File

@ -22,7 +22,9 @@
<thead class="thead-inverse">
<tr>
<th>{% trans "Date" %}</th>
<th>{% trans "Child" %}</th>
{% if not unique_child %}
<th>{% trans "Child" %}</th>
{% endif %}
<th>{% trans "Method" %}</th>
<th>{% trans "Type" %}</th>
{% comment %}Abbreviation of "Amount"{% endcomment %}
@ -36,7 +38,9 @@
{% cycle "odd" "even" as row_class silent %}
<tr class="{{ row_class }}">
<th scope="row">{{ feeding.start|datetime_short }}</th>
<td><a href="{% url 'core:child' feeding.child.slug %}">{{ feeding.child }}</a></td>
{% if not unique_child %}
<td><a href="{% url 'core:child' feeding.child.slug %}">{{ feeding.child }}</a></td>
{% endif %}
<td>{{ feeding.get_method_display }}</td>
<td>{{ feeding.get_type_display }}</td>
<td>

View File

@ -22,7 +22,9 @@
<thead class="thead-inverse">
<tr>
<th>{% trans "Time" %}</th>
<th>{% trans "Child" %}</th>
{% if not unique_child %}
<th>{% trans "Child" %}</th>
{% endif %}
<th>{% trans "Note" %}</th>
<th class="text-center">{% trans "Actions" %}</th>
</tr>
@ -31,7 +33,9 @@
{% for note in object_list %}
<tr>
<th scope="row">{{ note.time|datetime_short }}</th>
<td><a href="{% url 'core:child' note.child.slug %}">{{ note.child }}</a></td>
{% if not unique_child %}
<td><a href="{% url 'core:child' note.child.slug %}">{{ note.child }}</a></td>
{% endif %}
<td>{{ note.note }}</td>
<td class="text-center">
<div class="btn-group btn-group-sm" role="group" aria-label="{% trans "Actions" %}">

View File

@ -23,7 +23,9 @@
<tr>
<th>{% trans "Start" %}</th>
<th>{% trans "End" %}</th>
<th>{% trans "Child" %}</th>
{% if not unique_child %}
<th>{% trans "Child" %}</th>
{% endif %}
<th>{% trans "Duration" %}</th>
<th class="text-center">{% trans "Nap" %}</th>
<th class="text-center">{% trans "Actions" %}</th>
@ -35,7 +37,9 @@
<tr class="{{ row_class }}">
<th scope="row">{{ sleep.start|datetime_short }}</th>
<td>{{ sleep.end|datetime_short }}</td>
<td><a href="{% url 'core:child' sleep.child.slug %}">{{ sleep.child }}</a></td>
{% if not unique_child %}
<td><a href="{% url 'core:child' sleep.child.slug %}">{{ sleep.child }}</a></td>
{% endif %}
<td>{{ sleep.duration|duration_string }}</td>
<td class="text-center">{{ sleep.nap|bool_icon }}</td>
<td class="text-center">

View File

@ -22,7 +22,9 @@
<thead class="thead-inverse">
<tr>
<th>{% trans "Time" %}</th>
<th>{% trans "Child" %}</th>
{% if not unique_child %}
<th>{% trans "Child" %}</th>
{% endif %}
<th>{% trans "Temperature" %}</th>
<th class="text-center">{% trans "Actions" %}</th>
</tr>
@ -32,7 +34,9 @@
{% cycle "odd" "even" as row_class silent %}
<tr class="{{ row_class }}">
<th scope="row">{{ temperature.time|datetime_short }}</th>
<td><a href="{% url 'core:child' temperature.child.slug %}">{{ temperature.child }}</a></td>
{% if not unique_child %}
<td><a href="{% url 'core:child' temperature.child.slug %}">{{ temperature.child }}</a></td>
{% endif %}
<td>{{ temperature.temperature }}</td>
<td class="text-center">
<div class="btn-group btn-group-sm" role="group" aria-label="{% trans "Actions" %}">

View File

@ -23,7 +23,9 @@
<tr>
<th>{% trans "Start" %}</th>
<th>{% trans "Name" %}</th>
<th>{% trans "Child" %}</th>
{% if not unique_child %}
<th>{% trans "Child" %}</th>
{% endif %}
<th>{% trans "Duration" %}</th>
<th>{% trans "End" %}</th>
<th>{% trans "Active" %}</th>
@ -35,11 +37,13 @@
<tr>
<th scope="row">{{ timer.start|datetime_short }}</th>
<td><a href="{% url 'core:timer-detail' timer.id %}">{{ timer }}</a></td>
<td>
{% if timer.child %}
<a href="{% url 'core:child' timer.child.slug %}">{{ timer.child }}</a>
{% endif %}
</td>
{% if not unique_child %}
<td>
{% if timer.child %}
<a href="{% url 'core:child' timer.child.slug %}">{{ timer.child }}</a>
{% endif %}
</td>
{% endif %}
<td>{{ timer.duration|duration_string }}</td>
<td>
{% if timer.end %}

View File

@ -22,7 +22,9 @@
<tr>
<th>{% trans "Start" %}</th>
<th>{% trans "End" %}</th>
<th>{% trans "Child" %}</th>
{% if not unique_child %}
<th>{% trans "Child" %}</th>
{% endif %}
<th>{% trans "Duration" %}</th>
<th>{% trans "Milestone" %}</th>
<th class="text-center">{% trans "Actions" %}</th>
@ -33,7 +35,9 @@
<tr>
<th scope="row">{{ tummytime.start|datetime_short }}</th>
<td>{{ tummytime.end|datetime_short }}</td>
<td><a href="{% url 'core:child' tummytime.child.slug %}">{{ tummytime.child }}</a></td>
{% if not unique_child %}
<td><a href="{% url 'core:child' tummytime.child.slug %}">{{ tummytime.child }}</a></td>
{% endif %}
<td>{{ tummytime.duration|duration_string }}</td>
<td>{{ tummytime.milestone }}</td>
<td class="text-center">

View File

@ -22,7 +22,9 @@
<thead class="thead-inverse">
<tr>
<th>{% trans "Date" %}</th>
<th>{% trans "Child" %}</th>
{% if not unique_child %}
<th>{% trans "Child" %}</th>
{% endif %}
<th>{% trans "Weight" %}</th>
<th class="text-center">{% trans "Actions" %}</th>
</tr>
@ -32,7 +34,9 @@
{% cycle "odd" "even" as row_class silent %}
<tr class="{{ row_class }}">
<th scope="row">{{ weight.date }}</th>
<td><a href="{% url 'core:child' weight.child.slug %}">{{ weight.child }}</a></td>
{% if not unique_child %}
<td><a href="{% url 'core:child' weight.child.slug %}">{{ weight.child }}</a></td>
{% endif %}
<td>{{ weight.weight }}</td>
<td class="text-center">
<div class="btn-group btn-group-sm" role="group" aria-label="{% trans "Actions" %}">