mirror of https://github.com/snachodog/mybuddy.git
Support two output formats from plotly.plot.
This commit is contained in:
parent
c8611fac39
commit
bff17dd2a0
|
@ -25,6 +25,5 @@
|
||||||
|
|
||||||
{% block javascript %}
|
{% block javascript %}
|
||||||
<script src="{% static "babybuddy/js/graph.js" %}"></script>
|
<script src="{% static "babybuddy/js/graph.js" %}"></script>
|
||||||
{{ js_graph|safe }}
|
{{ js|safe }}
|
||||||
{{ js_listener|safe }}
|
|
||||||
{% endblock %}
|
{% endblock %}
|
|
@ -79,10 +79,15 @@ def rangeselector_date():
|
||||||
def split_graph_output(output):
|
def split_graph_output(output):
|
||||||
"""
|
"""
|
||||||
Split out of a Plotly graph in to html and javascript.
|
Split out of a Plotly graph in to html and javascript.
|
||||||
|
This function accounts for two output formats from different Plotly
|
||||||
|
versions: one with a single <script> tag and one with two <script> tags.
|
||||||
:param output: a string of html and javascript comprising the graph.
|
:param output: a string of html and javascript comprising the graph.
|
||||||
:returns: a tuple of the the graph's html and javascript.
|
:returns: a tuple of the the graph's html and javascript.
|
||||||
"""
|
"""
|
||||||
|
try:
|
||||||
html, js_graph, js_listener = output.split('<script')
|
html, js_graph, js_listener = output.split('<script')
|
||||||
js_graph = '<script' + js_graph
|
js = js_graph + js_listener
|
||||||
js_listener = '<script' + js_listener
|
except ValueError:
|
||||||
return html, js_graph, js_listener
|
html, js = output.split('<script')
|
||||||
|
js = '<script' + js
|
||||||
|
return html, js
|
||||||
|
|
|
@ -21,7 +21,7 @@ class DiaperChangeLifetimesChildReport(PermissionRequired403Mixin, DetailView):
|
||||||
child = context['object']
|
child = context['object']
|
||||||
changes = models.DiaperChange.objects.filter(child=child)
|
changes = models.DiaperChange.objects.filter(child=child)
|
||||||
if changes and changes.count() > 1:
|
if changes and changes.count() > 1:
|
||||||
context['html'], context['js_graph'], context['js_listener'] = \
|
context['html'], context['js'] = \
|
||||||
graphs.diaperchange_lifetimes(changes)
|
graphs.diaperchange_lifetimes(changes)
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ class DiaperChangeTypesChildReport(PermissionRequired403Mixin, DetailView):
|
||||||
child = context['object']
|
child = context['object']
|
||||||
changes = models.DiaperChange.objects.filter(child=child)
|
changes = models.DiaperChange.objects.filter(child=child)
|
||||||
if changes:
|
if changes:
|
||||||
context['html'], context['js_graph'], context['js_listener'] = \
|
context['html'], context['js'] = \
|
||||||
graphs.diaperchange_types(changes)
|
graphs.diaperchange_types(changes)
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
@ -64,8 +64,7 @@ class FeedingDurationChildReport(PermissionRequired403Mixin, DetailView):
|
||||||
child = context['object']
|
child = context['object']
|
||||||
instances = models.Feeding.objects.filter(child=child)
|
instances = models.Feeding.objects.filter(child=child)
|
||||||
if instances:
|
if instances:
|
||||||
context['html'], context['js_graph'], context['js_listener'] = \
|
context['html'], context['js'] = graphs.feeding_duration(instances)
|
||||||
graphs.feeding_duration(instances)
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,8 +87,7 @@ class SleepPatternChildReport(PermissionRequired403Mixin, DetailView):
|
||||||
child = context['object']
|
child = context['object']
|
||||||
instances = models.Sleep.objects.filter(child=child).order_by('start')
|
instances = models.Sleep.objects.filter(child=child).order_by('start')
|
||||||
if instances:
|
if instances:
|
||||||
context['html'], context['js_graph'], context['js_listener'] = \
|
context['html'], context['js'] = graphs.sleep_pattern(instances)
|
||||||
graphs.sleep_pattern(instances)
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
@ -112,8 +110,7 @@ class SleepTotalsChildReport(PermissionRequired403Mixin, DetailView):
|
||||||
child = context['object']
|
child = context['object']
|
||||||
instances = models.Sleep.objects.filter(child=child).order_by('start')
|
instances = models.Sleep.objects.filter(child=child).order_by('start')
|
||||||
if instances:
|
if instances:
|
||||||
context['html'], context['js_graph'], context['js_listener'] = \
|
context['html'], context['js'] = graphs.sleep_totals(instances)
|
||||||
graphs.sleep_totals(instances)
|
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
|
||||||
|
@ -131,6 +128,5 @@ class WeightWeightChildReport(PermissionRequired403Mixin, DetailView):
|
||||||
child = context['object']
|
child = context['object']
|
||||||
objects = models.Weight.objects.filter(child=child)
|
objects = models.Weight.objects.filter(child=child)
|
||||||
if objects:
|
if objects:
|
||||||
context['html'], context['js_graph'], context['js_listener'] = \
|
context['html'], context['js'] = graphs.weight_weight(objects)
|
||||||
graphs.weight_weight(objects)
|
|
||||||
return context
|
return context
|
||||||
|
|
Loading…
Reference in New Issue