Skip to content

Commit

Permalink
Fixed report breadcrumbs being duplicated. Fixed DiaperChangeTypesChi…
Browse files Browse the repository at this point in the history
…ldReport pointing to the wrong report view. Fixed child sw

itcher for WHO weight percentiles boy/girl reports.
  • Loading branch information
ntrecina committed Dec 8, 2023
1 parent 7747ae9 commit 86deef7
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 22 deletions.
2 changes: 0 additions & 2 deletions reports/templates/reports/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@

{% block breadcrumbs %}
<li class="breadcrumb-item"><a href="{% url 'core:child-list' %}">{% trans "Children" %}</a></li>
<li class="breadcrumb-item fw-bold"><a href="{% url 'core:child' object.slug %}">{{ object }}</a></li>
<li class="breadcrumb-item"><a href="{% url 'reports:report-list' object.slug %}">{% trans "Reports" %}</a></li>
{% endblock %}
11 changes: 6 additions & 5 deletions reports/templates/reports/breadcrumb_common_chunk.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{% load breadcrumb i18n %}

<li class="breadcrumb-item font-weight-bold">
{% child_quick_switch object target_url %}
</li>
<li class="breadcrumb-item"><a href="{% url 'reports:report-list' object.slug %}">{% trans "Reports" %}</a></li>

{% block breadcrumbs %}
<li class="breadcrumb-item font-weight-bold">
{% child_quick_switch object target_url %}
</li>
<li class="breadcrumb-item"><a href="{% url 'reports:report-list' object.slug %}">{% trans "Reports" %}</a></li>
{% endblock %}
1 change: 1 addition & 0 deletions reports/templates/reports/diaperchange_intervals.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@

{% block breadcrumbs %}
{{ block.super }}
{% include 'reports/breadcrumb_common_chunk.html' with target_url='reports:report-diaperchange-intervals-child' %}
<li class="breadcrumb-item active" aria-current="page">{% trans "Diaper Change Intervals" %}</li>
{% endblock %}
1 change: 1 addition & 0 deletions reports/templates/reports/feeding_intervals.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@

{% block breadcrumbs %}
{{ block.super }}
{% include 'reports/breadcrumb_common_chunk.html' with target_url='reports:report-feeding-intervals-child' %}
<li class="breadcrumb-item active" aria-current="page">{% trans "Feeding Intervals" %}</li>
{% endblock %}
4 changes: 2 additions & 2 deletions reports/templates/reports/report_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ <h1>Reports</h1>
<a href="{% url 'reports:report-temperature-change-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Temperature" %}</a>
<a href="{% url 'reports:report-tummy-time-duration-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Tummy Time Durations (Sum)" %}</a>
<a href="{% url 'reports:report-weight-change-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Weight" %}</a>
<a href="{% url 'reports:report-weight-change-child-sex' object.slug 'boy' %}" class="list-group-item list-group-item-action">{% trans "WHO Weight Percentiles for Boys in kg" %}</a>
<a href="{% url 'reports:report-weight-change-child-sex' object.slug 'girl' %}" class="list-group-item list-group-item-action">{% trans "WHO Weight Percentiles for Girls in kg" %}</a>
<a href="{% url 'reports:report-weight-change-child-boy' object.slug %}" class="list-group-item list-group-item-action">{% trans "WHO Weight Percentiles for Boys in kg" %}</a>
<a href="{% url 'reports:report-weight-change-child-girl' object.slug %}" class="list-group-item list-group-item-action">{% trans "WHO Weight Percentiles for Girls in kg" %}</a>
</div>
</div>
{% endblock %}
5 changes: 3 additions & 2 deletions reports/templates/reports/weight_change.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

{% block breadcrumbs %}
{{ block.super }}
{% include 'reports/breadcrumb_common_chunk.html' with target_url='reports:report-weight-change-child' %}
{% include 'reports/breadcrumb_common_chunk.html' with target_url=target_url %}

<li class="breadcrumb-item active" aria-current="page">{% trans "Weight" %}</li>
{% endblock %}
{% endblock %}
11 changes: 8 additions & 3 deletions reports/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,13 @@
name="report-weight-change-child",
),
path(
"children/<str:slug>/reports/weight/<sex>/",
views.WeightChangeChildReport.as_view(),
name="report-weight-change-child-sex",
"children/<str:slug>/reports/weight/boy/",
views.WeightChangeChildBoyReport.as_view(),
name="report-weight-change-child-boy",
),
path(
"children/<str:slug>/reports/weight/girl/",
views.WeightChangeChildGirlReport.as_view(),
name="report-weight-change-child-girl",
),
]
32 changes: 25 additions & 7 deletions reports/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class DiaperChangeTypesChildReport(PermissionRequiredMixin, DetailView):

model = models.Child
permission_required = ("core.view_child",)
template_name = "reports/diaperchange_intervals.html"
template_name = "reports/diaperchange_types.html"

def get_context_data(self, **kwargs):
context = super(DiaperChangeTypesChildReport, self).get_context_data(**kwargs)
Expand Down Expand Up @@ -326,20 +326,38 @@ class WeightChangeChildReport(PermissionRequiredMixin, DetailView):
Graph of weight change over time.
"""

model = models.Child
permission_required = ("core.view_child",)
template_name = "reports/weight_change.html"
def __init__(
self, sex=None, target_url="reports:report-weight-change-child"
) -> None:
self.model = models.Child
self.permission_required = ("core.view_child",)
self.template_name = "reports/weight_change.html"
self.sex = sex
self.target_url = target_url

def get_context_data(self, **kwargs):
context = super(WeightChangeChildReport, self).get_context_data(**kwargs)
child = context["object"]
birthday = child.birth_date
actual_weights = models.Weight.objects.filter(child=child)
percentile_weights = models.WeightPercentile.objects.filter(
sex=self.kwargs.get("sex")
)
percentile_weights = models.WeightPercentile.objects.filter(sex=self.sex)
context["target_url"] = self.target_url
if actual_weights:
context["html"], context["js"] = graphs.weight_change(
actual_weights, percentile_weights, birthday
)
return context


class WeightChangeChildBoyReport(WeightChangeChildReport):
def __init__(self):
super(WeightChangeChildBoyReport, self).__init__(
sex="boy", target_url="reports:report-weight-change-child-boy"
)


class WeightChangeChildGirlReport(WeightChangeChildReport):
def __init__(self):
super(WeightChangeChildGirlReport, self).__init__(
sex="girl", target_url="reports:report-weight-change-child-girl"
)

0 comments on commit 86deef7

Please sign in to comment.