mirror of https://github.com/snachodog/mybuddy.git
Finalize child timeline graph/view.
This commit is contained in:
parent
98963572ba
commit
6562fa2390
|
@ -16,15 +16,10 @@
|
||||||
aria-haspopup="true"
|
aria-haspopup="true"
|
||||||
aria-expanded="false"><i class="icon icon-graph" aria-hidden="true"></i> Reports</button>
|
aria-expanded="false"><i class="icon icon-graph" aria-hidden="true"></i> Reports</button>
|
||||||
<div class="dropdown-menu" aria-labelledby="reports-dropdown">
|
<div class="dropdown-menu" aria-labelledby="reports-dropdown">
|
||||||
{% if perms.core.view_diaperchange %}
|
<a class="dropdown-item" href="{% url 'reports:report-diaperchange-types-child' object.slug %}">Diaper Change Types</a>
|
||||||
<h6 class="dropdown-header"><i class="icon icon-delete" aria-hidden="true"></i> Diaper Changes</h6>
|
|
||||||
<a class="dropdown-item" href="{% url 'reports:report-diaperchange-types-child' object.slug %}">Change Types</a>
|
|
||||||
{% endif %}
|
|
||||||
{% if perms.core.view_sleep %}
|
|
||||||
<h6 class="dropdown-header"><i class="icon icon-sleep" aria-hidden="true"></i> Sleep</h6>
|
|
||||||
<a class="dropdown-item" href="{% url 'reports:report-sleep-pattern-child' object.slug %}">Sleep Pattern</a>
|
<a class="dropdown-item" href="{% url 'reports:report-sleep-pattern-child' object.slug %}">Sleep Pattern</a>
|
||||||
<a class="dropdown-item" href="{% url 'reports:report-sleep-totals-child' object.slug %}">Sleep Totals</a>
|
<a class="dropdown-item" href="{% url 'reports:report-sleep-totals-child' object.slug %}">Sleep Totals</a>
|
||||||
{% endif %}
|
<a class="dropdown-item" href="{% url 'reports:report-timeline-child' object.slug %}">Timeline</a>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -251,40 +251,48 @@ def timeline(child, date):
|
||||||
min_date = date
|
min_date = date
|
||||||
max_date = date.replace(hour=23, minute=59, second=59)
|
max_date = date.replace(hour=23, minute=59, second=59)
|
||||||
events = []
|
events = []
|
||||||
|
|
||||||
instances = DiaperChange.objects.filter(child=child).filter(
|
instances = DiaperChange.objects.filter(child=child).filter(
|
||||||
time__range=(min_date, max_date)).order_by('-time')
|
time__range=(min_date, max_date)).order_by('-time')
|
||||||
for instance in instances:
|
for instance in instances:
|
||||||
events.append({
|
events.append({
|
||||||
'time': timezone.localtime(instance.time),
|
'time': timezone.localtime(instance.time),
|
||||||
'event': '{} had a diaper change.'.format(child.first_name),
|
'event': '{} had a diaper change.'.format(child.first_name),
|
||||||
'model_name': instance.model_name
|
'model_name': instance.model_name,
|
||||||
})
|
})
|
||||||
|
|
||||||
instances = Feeding.objects.filter(child=child).filter(
|
instances = Feeding.objects.filter(child=child).filter(
|
||||||
start__range=(min_date, max_date)).order_by('-start')
|
start__range=(min_date, max_date)).order_by('-start')
|
||||||
for instance in instances:
|
for instance in instances:
|
||||||
events.append({
|
events.append({
|
||||||
'time': timezone.localtime(instance.start),
|
'time': timezone.localtime(instance.start),
|
||||||
'event': '{} started feeding.'.format(instance.child.first_name),
|
'event': '{} started feeding.'.format(instance.child.first_name),
|
||||||
'model_name': instance.model_name
|
'model_name': instance.model_name,
|
||||||
|
'type': 'start'
|
||||||
})
|
})
|
||||||
events.append({
|
events.append({
|
||||||
'time': timezone.localtime(instance.end),
|
'time': timezone.localtime(instance.end),
|
||||||
'event': '{} finished feeding.'.format(instance.child.first_name),
|
'event': '{} finished feeding.'.format(instance.child.first_name),
|
||||||
'model_name': instance.model_name
|
'model_name': instance.model_name,
|
||||||
|
'type': 'end'
|
||||||
})
|
})
|
||||||
|
|
||||||
instances = Sleep.objects.filter(child=child).filter(
|
instances = Sleep.objects.filter(child=child).filter(
|
||||||
start__range=(min_date, max_date)).order_by('-start')
|
start__range=(min_date, max_date)).order_by('-start')
|
||||||
for instance in instances:
|
for instance in instances:
|
||||||
events.append({
|
events.append({
|
||||||
'time': timezone.localtime(instance.start),
|
'time': timezone.localtime(instance.start),
|
||||||
'event': '{} fell asleep.'.format(instance.child.first_name),
|
'event': '{} fell asleep.'.format(instance.child.first_name),
|
||||||
'model_name': instance.model_name
|
'model_name': instance.model_name,
|
||||||
|
'type': 'start'
|
||||||
})
|
})
|
||||||
events.append({
|
events.append({
|
||||||
'time': timezone.localtime(instance.end),
|
'time': timezone.localtime(instance.end),
|
||||||
'event': '{} woke up.'.format(instance.child.first_name),
|
'event': '{} woke up.'.format(instance.child.first_name),
|
||||||
'model_name': instance.model_name
|
'model_name': instance.model_name,
|
||||||
|
'type': 'end'
|
||||||
})
|
})
|
||||||
|
|
||||||
instances = TummyTime.objects.filter(child=child).filter(
|
instances = TummyTime.objects.filter(child=child).filter(
|
||||||
start__range=(min_date, max_date)).order_by('-start')
|
start__range=(min_date, max_date)).order_by('-start')
|
||||||
for instance in instances:
|
for instance in instances:
|
||||||
|
@ -292,13 +300,17 @@ def timeline(child, date):
|
||||||
'time': timezone.localtime(instance.start),
|
'time': timezone.localtime(instance.start),
|
||||||
'event': '{} started tummy time!'.format(
|
'event': '{} started tummy time!'.format(
|
||||||
instance.child.first_name),
|
instance.child.first_name),
|
||||||
'model_name': instance.model_name
|
'model_name': instance.model_name,
|
||||||
|
'type': 'start'
|
||||||
})
|
})
|
||||||
events.append({
|
events.append({
|
||||||
'time': timezone.localtime(instance.end),
|
'time': timezone.localtime(instance.end),
|
||||||
'event': '{} finished tummy time.'.format(
|
'event': '{} finished tummy time.'.format(
|
||||||
instance.child.first_name),
|
instance.child.first_name),
|
||||||
'model_name': instance.model_name
|
'model_name': instance.model_name,
|
||||||
|
'type': 'end'
|
||||||
})
|
})
|
||||||
|
|
||||||
events.sort(key=lambda x: x['time'], reverse=True)
|
events.sort(key=lambda x: x['time'], reverse=True)
|
||||||
|
|
||||||
return events
|
return events
|
||||||
|
|
|
@ -6,11 +6,23 @@
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h1 class="text-center">Timeline</h1>
|
<h1 class="text-center">Timeline</h1>
|
||||||
<h2 class="text-center text-muted">{{ object }}</h2>
|
<h2 class="text-center text-muted">{{ object }}</h2>
|
||||||
<h3 class="text-center">{{ date|date }}</h3>
|
<h3 class="text-center">
|
||||||
<ul class="timeline">
|
<a class="btn btn-sm btn-default" href="?date={{ date_previous|date:"Y-m-d" }}" aria-label="Previous">
|
||||||
|
<i class="icon icon-chevron-left" aria-hidden="true"></i>
|
||||||
|
<span class="sr-only">Previous</span>
|
||||||
|
</a>
|
||||||
|
{{ date|date }}
|
||||||
|
<a class="btn btn-sm btn-default" href="?date={{ date_next|date:"Y-m-d" }}" aria-label="Next">
|
||||||
|
<i class="icon icon-chevron-right" aria-hidden="true"></i>
|
||||||
|
<span class="sr-only">Next</span>
|
||||||
|
</a>
|
||||||
|
</h3>
|
||||||
|
<ul class="timeline m-auto">
|
||||||
{% for object in objects %}
|
{% for object in objects %}
|
||||||
<li>
|
<li{% cycle "" ' class="timeline-inverted"' %}>
|
||||||
<div class="timeline-badge"><i class="icon icon-{{ object.model_name }}"></i></div>
|
<div class="timeline-badge {% if object.type == "start" %}bg-success{% elif object.type == "end" %}bg-danger{% else %}bg-info{% endif %}">
|
||||||
|
<i class="icon icon-{{ object.model_name }}"></i>
|
||||||
|
</div>
|
||||||
<div class="card text-right">
|
<div class="card text-right">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
{{ object.event }}
|
{{ object.event }}
|
||||||
|
|
|
@ -70,9 +70,11 @@ class TimelineChildReport(PermissionRequiredMixin, DetailView):
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
context = super(TimelineChildReport, self).get_context_data(**kwargs)
|
context = super(TimelineChildReport, self).get_context_data(**kwargs)
|
||||||
date = self.request.GET.get('date', timezone.now().date())
|
date = self.request.GET.get('date', str(timezone.now().date()))
|
||||||
date = timezone.datetime.strptime(date, '%Y-%m-%d')
|
date = timezone.datetime.strptime(date, '%Y-%m-%d')
|
||||||
date = timezone.localtime(timezone.make_aware(date))
|
date = timezone.localtime(timezone.make_aware(date))
|
||||||
context['objects'] = timeline(self.object, date)
|
context['objects'] = timeline(self.object, date)
|
||||||
context['date'] = date
|
context['date'] = date
|
||||||
|
context['date_previous'] = date - timezone.timedelta(days=1)
|
||||||
|
context['date_next'] = date + timezone.timedelta(days=1)
|
||||||
return context
|
return context
|
||||||
|
|
Loading…
Reference in New Issue