From 348e622321cabc866354d342ca5156f5e3c540ea Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Wed, 25 May 2022 21:27:21 -0700 Subject: [PATCH] Refactor naming pattern of simple "change" graphs --- reports/graphs/__init__.py | 12 +- reports/graphs/{bmi_bmi.py => bmi_change.py} | 2 +- ...erence.py => head_circumference_change.py} | 2 +- .../{height_height.py => height_change.py} | 2 +- .../{weight_weight.py => weight_change.py} | 2 +- reports/templates/reports/report_list.html | 10 +- reports/tests/tests_views.py | 21 ++- reports/urls.py | 44 ++--- reports/views.py | 162 +++++++++--------- 9 files changed, 128 insertions(+), 129 deletions(-) rename reports/graphs/{bmi_bmi.py => bmi_change.py} (97%) rename reports/graphs/{head_circumference_head_circumference.py => head_circumference_change.py} (95%) rename reports/graphs/{height_height.py => height_change.py} (97%) rename reports/graphs/{weight_weight.py => weight_change.py} (97%) diff --git a/reports/graphs/__init__.py b/reports/graphs/__init__.py index 1a4bc559..6d31a582 100644 --- a/reports/graphs/__init__.py +++ b/reports/graphs/__init__.py @@ -1,15 +1,13 @@ -from .pumping_amounts import pumping_amounts # NOQA +from .bmi_change import bmi_change # NOQA from .diaperchange_amounts import diaperchange_amounts # NOQA from .diaperchange_lifetimes import diaperchange_lifetimes # NOQA from .diaperchange_types import diaperchange_types # NOQA from .feeding_amounts import feeding_amounts # NOQA from .feeding_duration import feeding_duration # NOQA +from .head_circumference_change import head_circumference_change # NOQA +from .height_change import height_change # NOQA +from .pumping_amounts import pumping_amounts # NOQA from .sleep_pattern import sleep_pattern # NOQA from .sleep_totals import sleep_totals # NOQA from .tummytime_duration import tummytime_duration # NOQA -from .weight_weight import weight_weight # NOQA -from .height_height import height_height # NOQA -from .head_circumference_head_circumference import ( - head_circumference_head_circumference, -) # NOQA -from .bmi_bmi import bmi_bmi # NOQA +from .weight_change import weight_change # NOQA diff --git a/reports/graphs/bmi_bmi.py b/reports/graphs/bmi_change.py similarity index 97% rename from reports/graphs/bmi_bmi.py rename to reports/graphs/bmi_change.py index 355a453a..2dd8b471 100644 --- a/reports/graphs/bmi_bmi.py +++ b/reports/graphs/bmi_change.py @@ -7,7 +7,7 @@ import plotly.graph_objs as go from reports import utils -def bmi_bmi(objects): +def bmi_change(objects): """ Create a graph showing bmi over time. :param objects: a QuerySet of BMI instances. diff --git a/reports/graphs/head_circumference_head_circumference.py b/reports/graphs/head_circumference_change.py similarity index 95% rename from reports/graphs/head_circumference_head_circumference.py rename to reports/graphs/head_circumference_change.py index 71ddc043..9d8d3afd 100644 --- a/reports/graphs/head_circumference_head_circumference.py +++ b/reports/graphs/head_circumference_change.py @@ -7,7 +7,7 @@ import plotly.graph_objs as go from reports import utils -def head_circumference_head_circumference(objects): +def head_circumference_change(objects): """ Create a graph showing head_circumference over time. :param objects: a QuerySet of Head Circumference instances. diff --git a/reports/graphs/height_height.py b/reports/graphs/height_change.py similarity index 97% rename from reports/graphs/height_height.py rename to reports/graphs/height_change.py index 21dd47b6..457e3a0d 100644 --- a/reports/graphs/height_height.py +++ b/reports/graphs/height_change.py @@ -7,7 +7,7 @@ import plotly.graph_objs as go from reports import utils -def height_height(objects): +def height_change(objects): """ Create a graph showing height over time. :param objects: a QuerySet of Height instances. diff --git a/reports/graphs/weight_weight.py b/reports/graphs/weight_change.py similarity index 97% rename from reports/graphs/weight_weight.py rename to reports/graphs/weight_change.py index 732f8024..17ae92ce 100644 --- a/reports/graphs/weight_weight.py +++ b/reports/graphs/weight_change.py @@ -7,7 +7,7 @@ import plotly.graph_objs as go from reports import utils -def weight_weight(objects): +def weight_change(objects): """ Create a graph showing weight over time. :param objects: a QuerySet of Weight instances. diff --git a/reports/templates/reports/report_list.html b/reports/templates/reports/report_list.html index 77156299..30c10bdb 100644 --- a/reports/templates/reports/report_list.html +++ b/reports/templates/reports/report_list.html @@ -7,19 +7,19 @@

Reports

{% endblock %} \ No newline at end of file diff --git a/reports/tests/tests_views.py b/reports/tests/tests_views.py index 2dcf26c8..17b55990 100644 --- a/reports/tests/tests_views.py +++ b/reports/tests/tests_views.py @@ -35,7 +35,7 @@ class ViewsTestCase(TestCase): page = self.c.get(base_url) self.assertEqual(page.status_code, 200) - page = self.c.get("{}/pumping/amounts/".format(base_url)) + page = self.c.get("{}/bmi/bmi/".format(base_url)) self.assertEqual(page.status_code, 200) page = self.c.get("{}/changes/amounts/".format(base_url)) @@ -50,19 +50,22 @@ class ViewsTestCase(TestCase): page = self.c.get("{}/feeding/duration/".format(base_url)) self.assertEqual(page.status_code, 200) - page = self.c.get("{}/sleep/pattern/".format(base_url)) - self.assertEqual(page.status_code, 200) - page = self.c.get("{}/sleep/totals/".format(base_url)) - self.assertEqual(page.status_code, 200) - - page = self.c.get("{}/weight/weight/".format(base_url)) + page = self.c.get("{}/head-circumference/head-circumference/".format(base_url)) self.assertEqual(page.status_code, 200) page = self.c.get("{}/height/height/".format(base_url)) self.assertEqual(page.status_code, 200) - page = self.c.get("{}/head-circumference/head-circumference/".format(base_url)) + page = self.c.get("{}/pumping/amounts/".format(base_url)) self.assertEqual(page.status_code, 200) - page = self.c.get("{}/bmi/bmi/".format(base_url)) + page = self.c.get("{}/sleep/pattern/".format(base_url)) + self.assertEqual(page.status_code, 200) + page = self.c.get("{}/sleep/totals/".format(base_url)) + self.assertEqual(page.status_code, 200) + + page = self.c.get("{}/tummy-time/duration/".format(base_url)) + self.assertEqual(page.status_code, 200) + + page = self.c.get("{}/weight/weight/".format(base_url)) self.assertEqual(page.status_code, 200) diff --git a/reports/urls.py b/reports/urls.py index a7420002..1b36320f 100644 --- a/reports/urls.py +++ b/reports/urls.py @@ -12,9 +12,9 @@ urlpatterns = [ name="report-list", ), path( - "children//reports/pumping/amounts/", - views.PumpingAmounts.as_view(), - name="report-pumping-amounts-child", + "children//reports/bmi/bmi/", + views.BMIChangeChildReport.as_view(), + name="report-bmi-change-child", ), path( "children//reports/changes/amounts/", @@ -36,11 +36,26 @@ urlpatterns = [ views.FeedingAmountsChildReport.as_view(), name="report-feeding-amounts-child", ), + path( + "children//reports/head-circumference/head-circumference/", + views.HeadCircumferenceChangeChildReport.as_view(), + name="report-head-circumference-change-child", + ), + path( + "children//reports/height/height/", + views.HeightChangeChildReport.as_view(), + name="report-height-change-child", + ), path( "children//reports/feeding/duration/", views.FeedingDurationChildReport.as_view(), name="report-feeding-duration-child", ), + path( + "children//reports/pumping/amounts/", + views.PumpingAmounts.as_view(), + name="report-pumping-amounts-child", + ), path( "children//reports/sleep/pattern/", views.SleepPatternChildReport.as_view(), @@ -52,28 +67,13 @@ urlpatterns = [ name="report-sleep-totals-child", ), path( - "children//reports/tummytime/duration/", + "children//reports/tummy-time/duration/", views.TummyTimeDurationChildReport.as_view(), - name="report-tummytime-duration-child", + name="report-tummy-time-duration-child", ), path( "children//reports/weight/weight/", - views.WeightWeightChildReport.as_view(), - name="report-weight-weight-child", - ), - path( - "children//reports/height/height/", - views.HeightHeightChildReport.as_view(), - name="report-height-height-child", - ), - path( - "children//reports/head-circumference/head-circumference/", - views.HeadCircumferenceHeadCircumferenceChildReport.as_view(), - name="report-head-circumference-head-circumference-child", - ), - path( - "children//reports/bmi/bmi/", - views.BMIBMIChildReport.as_view(), - name="report-bmi-bmi-child", + views.WeightChangeChildReport.as_view(), + name="report-weight-change-child", ), ] diff --git a/reports/views.py b/reports/views.py index 9f4f0264..968a5a36 100644 --- a/reports/views.py +++ b/reports/views.py @@ -7,6 +7,24 @@ from core import models from . import graphs +class BMIChangeChildReport(PermissionRequiredMixin, DetailView): + """ + Graph of BMI change over time. + """ + + model = models.Child + permission_required = ("core.view_child",) + template_name = "reports/bmi_change.html" + + def get_context_data(self, **kwargs): + context = super(BMIChangeChildReport, self).get_context_data(**kwargs) + child = context["object"] + objects = models.BMI.objects.filter(child=child) + if objects: + context["html"], context["js"] = graphs.bmi_change(objects) + return context + + class ChildReportList(PermissionRequiredMixin, DetailView): """ Listing of available reports for a child. @@ -17,24 +35,6 @@ class ChildReportList(PermissionRequiredMixin, DetailView): template_name = "reports/report_list.html" -class PumpingAmounts(PermissionRequiredMixin, DetailView): - """ - Graph of pumping milk amounts collected. - """ - - model = models.Child - permission_required = ("core.view_child",) - template_name = "reports/pumping_amounts.html" - - def get_context_data(self, **kwargs): - context = super(PumpingAmounts, self).get_context_data(**kwargs) - child = context["object"] - changes = models.Pumping.objects.filter(child=child) - if changes and changes.count() > 0: - context["html"], context["js"] = graphs.pumping_amounts(changes) - return context - - class DiaperChangeAmounts(PermissionRequiredMixin, DetailView): """ Graph of diaper "amounts" - measurements of urine output. @@ -137,6 +137,65 @@ class FeedingDurationChildReport(PermissionRequiredMixin, DetailView): return context +class HeadCircumferenceChangeChildReport(PermissionRequiredMixin, DetailView): + """ + Graph of head circumference change over time. + """ + + model = models.Child + permission_required = ("core.view_child",) + template_name = "reports/head_circumference_change.html" + + def get_context_data(self, **kwargs): + context = super(HeadCircumferenceChangeChildReport, self).get_context_data( + **kwargs + ) + child = context["object"] + objects = models.HeadCircumference.objects.filter(child=child) + if objects: + ( + context["html"], + context["js"], + ) = graphs.head_circumference_change(objects) + return context + + +class HeightChangeChildReport(PermissionRequiredMixin, DetailView): + """ + Graph of height change over time. + """ + + model = models.Child + permission_required = ("core.view_child",) + template_name = "reports/height_change.html" + + def get_context_data(self, **kwargs): + context = super(HeightChangeChildReport, self).get_context_data(**kwargs) + child = context["object"] + objects = models.Height.objects.filter(child=child) + if objects: + context["html"], context["js"] = graphs.height_change(objects) + return context + + +class PumpingAmounts(PermissionRequiredMixin, DetailView): + """ + Graph of pumping milk amounts collected. + """ + + model = models.Child + permission_required = ("core.view_child",) + template_name = "reports/pumping_amounts.html" + + def get_context_data(self, **kwargs): + context = super(PumpingAmounts, self).get_context_data(**kwargs) + child = context["object"] + changes = models.Pumping.objects.filter(child=child) + if changes and changes.count() > 0: + context["html"], context["js"] = graphs.pumping_amounts(changes) + return context + + class SleepPatternChildReport(PermissionRequiredMixin, DetailView): """ Graph of sleep pattern comparing sleep to wake times by day. @@ -206,7 +265,7 @@ class TummyTimeDurationChildReport(PermissionRequiredMixin, DetailView): return context -class WeightWeightChildReport(PermissionRequiredMixin, DetailView): +class WeightChangeChildReport(PermissionRequiredMixin, DetailView): """ Graph of weight change over time. """ @@ -216,70 +275,9 @@ class WeightWeightChildReport(PermissionRequiredMixin, DetailView): template_name = "reports/weight_change.html" def get_context_data(self, **kwargs): - context = super(WeightWeightChildReport, self).get_context_data(**kwargs) + context = super(WeightChangeChildReport, self).get_context_data(**kwargs) child = context["object"] objects = models.Weight.objects.filter(child=child) if objects: - context["html"], context["js"] = graphs.weight_weight(objects) - return context - - -class HeightHeightChildReport(PermissionRequiredMixin, DetailView): - """ - Graph of height change over time. - """ - - model = models.Child - permission_required = ("core.view_child",) - template_name = "reports/height_change.html" - - def get_context_data(self, **kwargs): - context = super(HeightHeightChildReport, self).get_context_data(**kwargs) - child = context["object"] - objects = models.Height.objects.filter(child=child) - if objects: - context["html"], context["js"] = graphs.height_height(objects) - return context - - -class HeadCircumferenceHeadCircumferenceChildReport( - PermissionRequiredMixin, DetailView -): - """ - Graph of head circumference change over time. - """ - - model = models.Child - permission_required = ("core.view_child",) - template_name = "reports/head_circumference_change.html" - - def get_context_data(self, **kwargs): - context = super( - HeadCircumferenceHeadCircumferenceChildReport, self - ).get_context_data(**kwargs) - child = context["object"] - objects = models.HeadCircumference.objects.filter(child=child) - if objects: - ( - context["html"], - context["js"], - ) = graphs.head_circumference_head_circumference(objects) - return context - - -class BMIBMIChildReport(PermissionRequiredMixin, DetailView): - """ - Graph of BMI change over time. - """ - - model = models.Child - permission_required = ("core.view_child",) - template_name = "reports/bmi_change.html" - - def get_context_data(self, **kwargs): - context = super(BMIBMIChildReport, self).get_context_data(**kwargs) - child = context["object"] - objects = models.BMI.objects.filter(child=child) - if objects: - context["html"], context["js"] = graphs.bmi_bmi(objects) + context["html"], context["js"] = graphs.weight_change(objects) return context