mybuddy/reports/views.py

174 lines
5.7 KiB
Python
Raw Normal View History

2017-08-21 23:21:08 +00:00
# -*- coding: utf-8 -*-
from django.views.generic.detail import DetailView
from babybuddy.mixins import PermissionRequired403Mixin
2017-11-10 12:20:34 +00:00
from core import models
2017-08-21 23:21:08 +00:00
2017-11-10 12:20:34 +00:00
from . import graphs
2017-09-25 17:14:14 +00:00
2020-01-26 22:12:27 +00:00
class DiaperChangeAmounts(PermissionRequired403Mixin, DetailView):
"""
Graph of diaper "amounts" - measurements of urine output.
"""
model = models.Child
permission_required = ('core.view_child',)
template_name = 'reports/diaperchange_amounts.html'
def get_context_data(self, **kwargs):
context = super(DiaperChangeAmounts, self).get_context_data(**kwargs)
child = context['object']
changes = models.DiaperChange.objects.filter(child=child, amount__gt=0)
if changes and changes.count() > 0:
context['html'], context['js'] = \
graphs.diaperchange_amounts(changes)
return context
class DiaperChangeLifetimesChildReport(PermissionRequired403Mixin, DetailView):
"""
2017-11-10 12:20:34 +00:00
Graph of diaper "lifetimes" - time between diaper changes.
"""
model = models.Child
2017-09-25 17:14:14 +00:00
permission_required = ('core.view_child',)
template_name = 'reports/diaperchange_lifetimes.html'
def get_context_data(self, **kwargs):
2017-10-22 19:05:58 +00:00
context = super(
DiaperChangeLifetimesChildReport, self).get_context_data(**kwargs)
2017-09-25 17:14:14 +00:00
child = context['object']
2017-11-10 12:20:34 +00:00
changes = models.DiaperChange.objects.filter(child=child)
if changes and changes.count() > 1:
context['html'], context['js'] = \
2017-11-10 12:20:34 +00:00
graphs.diaperchange_lifetimes(changes)
2017-09-25 17:14:14 +00:00
return context
class DiaperChangeTypesChildReport(PermissionRequired403Mixin, DetailView):
"""
2017-11-10 12:20:34 +00:00
Graph of diaper changes by day and type.
"""
model = models.Child
2017-08-21 23:21:08 +00:00
permission_required = ('core.view_child',)
2017-09-13 15:25:12 +00:00
template_name = 'reports/diaperchange_types.html'
def get_context_data(self, **kwargs):
2017-09-15 12:11:41 +00:00
context = super(DiaperChangeTypesChildReport, self).get_context_data(
**kwargs)
child = context['object']
2017-11-10 12:20:34 +00:00
changes = models.DiaperChange.objects.filter(child=child)
if changes:
context['html'], context['js'] = \
2017-11-10 12:20:34 +00:00
graphs.diaperchange_types(changes)
return context
2019-05-29 17:05:30 +00:00
class FeedingAmountsChildReport(PermissionRequired403Mixin, DetailView):
"""
Graph of daily feeding amounts over time.
"""
model = models.Child
permission_required = ('core.view_child',)
template_name = 'reports/feeding_amounts.html'
def __init__(self):
super(FeedingAmountsChildReport, self).__init__()
self.html = ''
self.js = ''
def get_context_data(self, **kwargs):
context = super(FeedingAmountsChildReport, self).get_context_data(
**kwargs)
child = context['object']
instances = models.Feeding.objects.filter(child=child)
if instances:
context['html'], context['js'] = graphs.feeding_amounts(instances)
return context
class FeedingDurationChildReport(PermissionRequired403Mixin, DetailView):
"""
Graph of feeding durations over time.
"""
model = models.Child
permission_required = ('core.view_child',)
template_name = 'reports/feeding_duration.html'
def __init__(self):
super(FeedingDurationChildReport, self).__init__()
self.html = ''
2019-05-29 17:05:30 +00:00
self.js = ''
def get_context_data(self, **kwargs):
context = super(FeedingDurationChildReport, self).get_context_data(
**kwargs)
child = context['object']
instances = models.Feeding.objects.filter(child=child)
if instances:
context['html'], context['js'] = graphs.feeding_duration(instances)
return context
class SleepPatternChildReport(PermissionRequired403Mixin, DetailView):
"""
2017-11-10 12:20:34 +00:00
Graph of sleep pattern comparing sleep to wake times by day.
"""
model = models.Child
permission_required = ('core.view_child',)
2017-09-13 15:25:12 +00:00
template_name = 'reports/sleep_pattern.html'
def __init__(self):
2017-09-13 15:25:12 +00:00
super(SleepPatternChildReport, self).__init__()
self.html = ''
2019-05-29 17:05:30 +00:00
self.js = ''
def get_context_data(self, **kwargs):
2017-09-15 12:11:41 +00:00
context = super(SleepPatternChildReport, self).get_context_data(
**kwargs)
child = context['object']
2017-11-10 12:20:34 +00:00
instances = models.Sleep.objects.filter(child=child).order_by('start')
if instances:
context['html'], context['js'] = graphs.sleep_pattern(instances)
return context
2017-09-13 15:53:32 +00:00
class SleepTotalsChildReport(PermissionRequired403Mixin, DetailView):
"""
2017-11-10 12:20:34 +00:00
Graph of total sleep by day.
"""
model = models.Child
2017-09-13 15:53:32 +00:00
permission_required = ('core.view_child',)
template_name = 'reports/sleep_totals.html'
def __init__(self):
super(SleepTotalsChildReport, self).__init__()
self.html = ''
2019-05-29 17:05:30 +00:00
self.js = ''
2017-09-13 15:53:32 +00:00
def get_context_data(self, **kwargs):
2017-09-15 12:11:41 +00:00
context = super(SleepTotalsChildReport, self).get_context_data(
**kwargs)
2017-09-13 15:53:32 +00:00
child = context['object']
2017-11-10 12:20:34 +00:00
instances = models.Sleep.objects.filter(child=child).order_by('start')
if instances:
context['html'], context['js'] = graphs.sleep_totals(instances)
2017-11-10 12:20:34 +00:00
return context
2018-05-20 21:42:14 +00:00
class WeightWeightChildReport(PermissionRequired403Mixin, DetailView):
2017-11-10 12:20:34 +00:00
"""
Graph of weight change over time.
"""
model = models.Child
permission_required = ('core.view_child',)
template_name = 'reports/weight_change.html'
def get_context_data(self, **kwargs):
2018-05-20 21:42:14 +00:00
context = super(WeightWeightChildReport, self).get_context_data(
2017-11-10 12:20:34 +00:00
**kwargs)
child = context['object']
objects = models.Weight.objects.filter(child=child)
if objects:
context['html'], context['js'] = graphs.weight_weight(objects)
2017-09-13 15:53:32 +00:00
return context