Change reports list to a page

Fixes #379
This commit is contained in:
Christopher C. Wells 2022-02-26 13:23:43 -08:00
parent e7862801b1
commit 20d9cab158
7 changed files with 80 additions and 51 deletions

View File

@ -9,32 +9,11 @@
<a href="{% url 'core:child' object.slug %}" class="btn" title="{% trans "Timeline" %}">
<i class="icon-timeline" aria-hidden="true"></i>
</a>
<a href="{% url 'reports:report-list' object.slug %}" class="btn" title="{% trans "Reports" %}">
<i class="icon-graph" aria-hidden="true"></i>
</a>
{% endif %}
<div class="btn-group" role="group">
<button id="reports-dropdown"
class="btn dropdown-toggle"
title="{% trans "Reports" %}"
type="button"
data-toggle="dropdown"
aria-haspopup="true"
aria-expanded="false"><i class="icon-graph" aria-hidden="true"></i></button>
<div class="dropdown-menu" aria-labelledby="reports-dropdown">
<a class="dropdown-item" href="{% url 'reports:report-diaperchange-amounts-child' object.slug %}">{% trans "Diaper Change Amounts" %}</a>
<a class="dropdown-item" href="{% url 'reports:report-diaperchange-types-child' object.slug %}">{% trans "Diaper Change Types" %}</a>
<a class="dropdown-item" href="{% url 'reports:report-diaperchange-lifetimes-child' object.slug %}">{% trans "Diaper Lifetimes" %}</a>
<a class="dropdown-item" href="{% url 'reports:report-feeding-amounts-child' object.slug %}">{% trans "Feeding Amounts" %}</a>
<a class="dropdown-item" href="{% url 'reports:report-feeding-duration-child' object.slug %}">{% trans "Feeding Durations (Average)" %}</a>
<a class="dropdown-item" href="{% url 'reports:report-sleep-pattern-child' object.slug %}">{% trans "Sleep Pattern" %}</a>
<a class="dropdown-item" href="{% url 'reports:report-sleep-totals-child' object.slug %}">{% trans "Sleep Totals" %}</a>
<a class="dropdown-item" href="{% url 'reports:report-tummytime-duration-child' object.slug %}">{% trans "Tummy Time Durations (Sum)" %}</a>
<a class="dropdown-item" href="{% url 'reports:report-weight-weight-child' object.slug %}">{% trans "Weight" %}</a>
<a class="dropdown-item" href="{% url 'reports:report-height-height-child' object.slug %}">{% trans "Height" %}</a>
<a class="dropdown-item" href="{% url 'reports:report-head-circumference-head-circumference-child' object.slug %}">{% trans "Head Circumference" %}</a>
<a class="dropdown-item" href="{% url 'reports:report-bmi-bmi-child' object.slug %}">{% trans "BMI" %}</a>
</div>
</div>
{% if perms.core.change_child %}
<a class="btn d-none d-md-inline-block"
href="{% url 'core:child-update' object.slug %}"

View File

@ -0,0 +1,10 @@
{% extends 'babybuddy/page.html' %}
{% load i18n static %}
{% block title %}{% endblock %}
{% block breadcrumbs %}
<li class="breadcrumb-item"><a href="{% url 'core:child-list' %}">{% trans "Children" %}</a></li>
<li class="breadcrumb-item font-weight-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 %}

View File

@ -1,12 +1,10 @@
{% extends 'babybuddy/page.html' %}
{% extends 'reports/base.html' %}
{% load i18n static %}
{% block title %}{% endblock %}
{% block breadcrumbs %}
<li class="breadcrumb-item"><a href="{% url 'core:child-list' %}">{% trans "Children" %}</a></li>
<li class="breadcrumb-item font-weight-bold"><a href="{% url 'core:child' object.slug %}">{{ object }}</a></li>
<li class="breadcrumb-item">{% trans "Reports" %}</li>
{{ block.super }}
{% endblock %}
{% block content %}

View File

@ -0,0 +1,24 @@
{% extends 'reports/base.html' %}
{% load i18n static %}
{% block title %}{% trans "Reports" %} - {{ object }}{% endblock %}
{% block content %}
<div class="container-fluid">
<h1>Reports</h1>
<div class="list-group">
<a href="{% url 'reports:report-bmi-bmi-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Body Mass Index (BMI)" %}</a>
<a href="{% url 'reports:report-diaperchange-amounts-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Diaper Change Amounts" %}</a>
<a href="{% url 'reports:report-diaperchange-types-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Diaper Change Types" %}</a>
<a href="{% url 'reports:report-diaperchange-lifetimes-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Diaper Lifetimes" %}</a>
<a href="{% url 'reports:report-feeding-amounts-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Feeding Amounts" %}</a>
<a href="{% url 'reports:report-feeding-duration-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Feeding Durations (Average)" %}</a>
<a href="{% url 'reports:report-head-circumference-head-circumference-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Head Circumference" %}</a>
<a href="{% url 'reports:report-height-height-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Height" %}</a>
<a href="{% url 'reports:report-sleep-pattern-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Sleep Pattern" %}</a>
<a href="{% url 'reports:report-sleep-totals-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Sleep Totals" %}</a>
<a href="{% url 'reports:report-tummytime-duration-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Tummy Time Durations (Sum)" %}</a>
<a href="{% url 'reports:report-weight-weight-child' object.slug %}" class="list-group-item list-group-item-action">{% trans "Weight" %}</a>
</div>
</div>
{% endblock %}

View File

@ -32,6 +32,9 @@ class ViewsTestCase(TestCase):
child = models.Child.objects.first()
base_url = "/children/{}/reports".format(child.slug)
page = self.c.get(base_url)
self.assertEqual(page.status_code, 200)
page = self.c.get("{}/changes/amounts/".format(base_url))
self.assertEqual(page.status_code, 200)
page = self.c.get("{}/changes/lifetimes/".format(base_url))

View File

@ -6,6 +6,11 @@ from . import views
app_name = "reports"
urlpatterns = [
path(
"children/<str:slug>/reports",
views.ChildReportList.as_view(),
name="report-list",
),
path(
"children/<str:slug>/reports/changes/amounts/",
views.DiaperChangeAmounts.as_view(),

View File

@ -7,6 +7,16 @@ from core import models
from . import graphs
class ChildReportList(PermissionRequiredMixin, DetailView):
"""
Listing of available reports for a child.
"""
model = models.Child
permission_required = ("core.view_child",)
template_name = "reports/report_list.html"
class DiaperChangeAmounts(PermissionRequiredMixin, DetailView):
"""
Graph of diaper "amounts" - measurements of urine output.
@ -109,29 +119,6 @@ class FeedingDurationChildReport(PermissionRequiredMixin, DetailView):
return context
class TummyTimeDurationChildReport(PermissionRequiredMixin, DetailView):
"""
Graph of tummy time durations over time.
"""
model = models.Child
permission_required = ("core.view_child",)
template_name = "reports/tummytime_duration.html"
def __init__(self):
super(TummyTimeDurationChildReport, self).__init__()
self.html = ""
self.js = ""
def get_context_data(self, **kwargs):
context = super(TummyTimeDurationChildReport, self).get_context_data(**kwargs)
child = context["object"]
instances = models.TummyTime.objects.filter(child=child)
if instances:
context["html"], context["js"] = graphs.tummytime_duration(instances)
return context
class SleepPatternChildReport(PermissionRequiredMixin, DetailView):
"""
Graph of sleep pattern comparing sleep to wake times by day.
@ -178,6 +165,29 @@ class SleepTotalsChildReport(PermissionRequiredMixin, DetailView):
return context
class TummyTimeDurationChildReport(PermissionRequiredMixin, DetailView):
"""
Graph of tummy time durations over time.
"""
model = models.Child
permission_required = ("core.view_child",)
template_name = "reports/tummytime_duration.html"
def __init__(self):
super(TummyTimeDurationChildReport, self).__init__()
self.html = ""
self.js = ""
def get_context_data(self, **kwargs):
context = super(TummyTimeDurationChildReport, self).get_context_data(**kwargs)
child = context["object"]
instances = models.TummyTime.objects.filter(child=child)
if instances:
context["html"], context["js"] = graphs.tummytime_duration(instances)
return context
class WeightWeightChildReport(PermissionRequiredMixin, DetailView):
"""
Graph of weight change over time.