From 73a04af9b27c1d08bfe518923cabfd2261b11765 Mon Sep 17 00:00:00 2001 From: Ohad Lutzky Date: Thu, 8 Jul 2021 04:09:22 +0100 Subject: [PATCH] Timeline: Add edit links (#246) * Timeline: Show diaper change details * Timeline: Add edit links Suggested in #229 Co-authored-by: Christopher Charbonneau Wells <10456740+cdubz@users.noreply.github.com> --- core/templates/core/child_detail.html | 5 +++++ core/timeline.py | 14 +++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/core/templates/core/child_detail.html b/core/templates/core/child_detail.html index 8a0a60b5..db32f405 100644 --- a/core/templates/core/child_detail.html +++ b/core/templates/core/child_detail.html @@ -62,6 +62,11 @@ {% blocktrans trimmed with since=object.time|timesince time=object.time|time %} {{ since }} ago ({{ time }}) {% endblocktrans %} + {% if object.edit_link %} +
+ Edit +
+ {% endif %} diff --git a/core/timeline.py b/core/timeline.py index d42cccea..4e2a8aa5 100644 --- a/core/timeline.py +++ b/core/timeline.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +from django.urls import reverse from django.utils import timezone from django.utils.translation import gettext as _ @@ -32,13 +33,16 @@ def get_objects(child, date): 'details': _('Contents: %(contents)s') % { 'contents': ', '.join(contents), }, - 'model_name': instance.model_name, + 'edit_link': reverse('core:diaperchange-update', + args=[instance.id]), + 'model_name': instance.model_name }) instances = Feeding.objects.filter(child=child).filter( start__range=(min_date, max_date)).order_by('-start') for instance in instances: details = None + edit_link = reverse('core:feeding-update', args=[instance.id]) if instance.amount: details = _('Amount: %(amount).0f') % { 'amount': instance.amount, @@ -49,6 +53,7 @@ def get_objects(child, date): 'child': instance.child.first_name }, 'details': details, + 'edit_link': edit_link, 'model_name': instance.model_name, 'type': 'start' }) @@ -58,6 +63,7 @@ def get_objects(child, date): 'child': instance.child.first_name }, 'details': details, + 'edit_link': edit_link, 'model_name': instance.model_name, 'type': 'end' }) @@ -65,11 +71,13 @@ def get_objects(child, date): instances = Sleep.objects.filter(child=child).filter( start__range=(min_date, max_date)).order_by('-start') for instance in instances: + edit_link = reverse('core:sleep-update', args=[instance.id]) events.append({ 'time': timezone.localtime(instance.start), 'event': _('%(child)s fell asleep.') % { 'child': instance.child.first_name }, + 'edit_link': edit_link, 'model_name': instance.model_name, 'type': 'start' }) @@ -78,6 +86,7 @@ def get_objects(child, date): 'event': _('%(child)s woke up.') % { 'child': instance.child.first_name }, + 'edit_link': edit_link, 'model_name': instance.model_name, 'type': 'end' }) @@ -85,11 +94,13 @@ def get_objects(child, date): instances = TummyTime.objects.filter(child=child).filter( start__range=(min_date, max_date)).order_by('-start') for instance in instances: + edit_link = reverse('core:tummytime-update', args=[instance.id]) events.append({ 'time': timezone.localtime(instance.start), 'event': _('%(child)s started tummy time!') % { 'child': instance.child.first_name }, + 'edit_link': edit_link, 'model_name': instance.model_name, 'type': 'start' }) @@ -98,6 +109,7 @@ def get_objects(child, date): 'event': _('%(child)s finished tummy time.') % { 'child': instance.child.first_name }, + 'edit_link': edit_link, 'model_name': instance.model_name, 'type': 'end' })