2017-08-21 23:21:08 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
from django.contrib.auth.mixins import PermissionRequiredMixin
|
|
|
|
from django.views.generic.detail import DetailView
|
|
|
|
|
2017-08-25 16:19:06 +00:00
|
|
|
from core.models import Child
|
2017-08-21 23:21:08 +00:00
|
|
|
|
2017-08-25 16:19:06 +00:00
|
|
|
from .graphs import diaperchange_types, sleep_times
|
2017-08-23 13:04:05 +00:00
|
|
|
|
2017-08-24 18:54:01 +00:00
|
|
|
|
|
|
|
class DiaperChangesChildReport(PermissionRequiredMixin, DetailView):
|
2017-08-25 16:19:06 +00:00
|
|
|
"""Diaper change information by type."""
|
2017-08-21 23:21:08 +00:00
|
|
|
model = Child
|
|
|
|
permission_required = ('core.view_child',)
|
2017-08-23 13:04:05 +00:00
|
|
|
template_name = 'reports/diaperchange.html'
|
2017-08-23 01:37:10 +00:00
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
2017-08-24 18:54:01 +00:00
|
|
|
context = super(DiaperChangesChildReport, self).get_context_data(**kwargs)
|
2017-08-23 01:37:10 +00:00
|
|
|
child = context['object']
|
2017-08-25 16:19:06 +00:00
|
|
|
context['html'], context['javascript'] = diaperchange_types(child)
|
2017-08-24 18:54:01 +00:00
|
|
|
return context
|
2017-08-23 01:37:10 +00:00
|
|
|
|
|
|
|
|
2017-08-25 12:08:02 +00:00
|
|
|
class SleepChildReport(PermissionRequiredMixin, DetailView):
|
2017-08-25 16:19:06 +00:00
|
|
|
"""All sleep times by date."""
|
2017-08-23 13:04:05 +00:00
|
|
|
model = Child
|
|
|
|
permission_required = ('core.view_child',)
|
|
|
|
template_name = 'reports/sleep.html'
|
2017-08-25 16:19:06 +00:00
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
super(SleepChildReport, self).__init__()
|
|
|
|
self.html = ''
|
|
|
|
self.javascript = ''
|
|
|
|
|
|
|
|
def get_context_data(self, **kwargs):
|
|
|
|
context = super(SleepChildReport, self).get_context_data(**kwargs)
|
|
|
|
child = context['object']
|
|
|
|
context['html'], context['javascript'] = sleep_times(child)
|
|
|
|
return context
|