From d11733442d27ef45ad6c5ab0f34376377b15bfb3 Mon Sep 17 00:00:00 2001 From: Christopher Charbonneau Wells Date: Thu, 24 Aug 2017 14:54:01 -0400 Subject: [PATCH] Add a diaper change types over time report. --- core/models.py | 4 +- reports/templates/reports/diaperchange.html | 8 +-- reports/urls.py | 4 +- reports/utils.py | 37 +++++++++++ reports/views.py | 73 ++++++++++++++------- 5 files changed, 96 insertions(+), 30 deletions(-) create mode 100644 reports/utils.py diff --git a/core/models.py b/core/models.py index 2b831836..523a8ea3 100644 --- a/core/models.py +++ b/core/models.py @@ -29,8 +29,8 @@ class Child(models.Model): def name(self, reverse=False): if reverse: return '{}, {}'.format(self.last_name, self.first_name) - else: - return '{} {}'.format(self.first_name, self.last_name) + + return '{} {}'.format(self.first_name, self.last_name) class DiaperChange(models.Model): diff --git a/reports/templates/reports/diaperchange.html b/reports/templates/reports/diaperchange.html index f982abdc..77c861ea 100644 --- a/reports/templates/reports/diaperchange.html +++ b/reports/templates/reports/diaperchange.html @@ -3,11 +3,11 @@ {% block title %}Diaper Change Report - {{ object }}{% endblock %} {% block content %} -
- Diaper change report for {{ object }}. +
+

Diaper Change Reports

+

{{ object }}

- -
+
{{ html|safe }}
diff --git a/reports/urls.py b/reports/urls.py index dd6ddc40..99fe61da 100644 --- a/reports/urls.py +++ b/reports/urls.py @@ -6,8 +6,8 @@ from django.conf.urls import url from . import views urlpatterns = [ - url(r'^reports/(?P[^/.]+)/changes/$', - views.DiaperChangeReport.as_view(), name='report-diaperchange'), + url(r'^reports/changes/(?P[^/.]+)/$', + views.DiaperChangesChildReport.as_view(), name='report-diaperchange'), url(r'^reports/(?P[^/.]+)/sleep/$', views.SleepReport.as_view(), name='report-sleep'), ] diff --git a/reports/utils.py b/reports/utils.py new file mode 100644 index 00000000..678c4e69 --- /dev/null +++ b/reports/utils.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + + +def default_graph_layout_options(): + """Default layout options for all graphs. + """ + return { + 'font': { + 'color': 'rgba(0, 0, 0, 1)', + # Bootstrap 4 font family. + 'family': '-apple-system, BlinkMacSystemFont, "Segoe UI", ' + 'Roboto, "Helvetica Neue", Arial, sans-serif, ' + '"Apple Color Emoji", "Segoe UI Emoji", ' + '"Segoe UI Symbol"', + 'size': 14, + }, + 'margin': {'b': 40, 't': 40}, + 'xaxis': { + 'titlefont': { + 'color': 'rgba(0, 0, 0, 0.54)' + } + }, + 'yaxis': { + 'titlefont': { + 'color': 'rgba(0, 0, 0, 0.54)' + } + } + } + + +def split_graph_output(output): + """Split out of a Plotly graph in to html and javascript. + """ + html, javascript = output.split('