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>
This commit is contained in:
Ohad Lutzky 2021-07-08 04:09:22 +01:00 committed by GitHub
parent 8861933738
commit 73a04af9b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 1 deletions

View File

@ -62,6 +62,11 @@
{% blocktrans trimmed with since=object.time|timesince time=object.time|time %} {% blocktrans trimmed with since=object.time|timesince time=object.time|time %}
{{ since }} ago ({{ time }}) {{ since }} ago ({{ time }})
{% endblocktrans %} {% endblocktrans %}
{% if object.edit_link %}
<div>
<small><a href="{{ object.edit_link }}">Edit</a></small>
</div>
{% endif %}
</div> </div>
</div> </div>
</li> </li>

View File

@ -1,4 +1,5 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.urls import reverse
from django.utils import timezone from django.utils import timezone
from django.utils.translation import gettext as _ from django.utils.translation import gettext as _
@ -32,13 +33,16 @@ def get_objects(child, date):
'details': _('Contents: %(contents)s') % { 'details': _('Contents: %(contents)s') % {
'contents': ', '.join(contents), '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( 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:
details = None details = None
edit_link = reverse('core:feeding-update', args=[instance.id])
if instance.amount: if instance.amount:
details = _('Amount: %(amount).0f') % { details = _('Amount: %(amount).0f') % {
'amount': instance.amount, 'amount': instance.amount,
@ -49,6 +53,7 @@ def get_objects(child, date):
'child': instance.child.first_name 'child': instance.child.first_name
}, },
'details': details, 'details': details,
'edit_link': edit_link,
'model_name': instance.model_name, 'model_name': instance.model_name,
'type': 'start' 'type': 'start'
}) })
@ -58,6 +63,7 @@ def get_objects(child, date):
'child': instance.child.first_name 'child': instance.child.first_name
}, },
'details': details, 'details': details,
'edit_link': edit_link,
'model_name': instance.model_name, 'model_name': instance.model_name,
'type': 'end' 'type': 'end'
}) })
@ -65,11 +71,13 @@ def get_objects(child, date):
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:
edit_link = reverse('core:sleep-update', args=[instance.id])
events.append({ events.append({
'time': timezone.localtime(instance.start), 'time': timezone.localtime(instance.start),
'event': _('%(child)s fell asleep.') % { 'event': _('%(child)s fell asleep.') % {
'child': instance.child.first_name 'child': instance.child.first_name
}, },
'edit_link': edit_link,
'model_name': instance.model_name, 'model_name': instance.model_name,
'type': 'start' 'type': 'start'
}) })
@ -78,6 +86,7 @@ def get_objects(child, date):
'event': _('%(child)s woke up.') % { 'event': _('%(child)s woke up.') % {
'child': instance.child.first_name 'child': instance.child.first_name
}, },
'edit_link': edit_link,
'model_name': instance.model_name, 'model_name': instance.model_name,
'type': 'end' 'type': 'end'
}) })
@ -85,11 +94,13 @@ def get_objects(child, date):
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:
edit_link = reverse('core:tummytime-update', args=[instance.id])
events.append({ events.append({
'time': timezone.localtime(instance.start), 'time': timezone.localtime(instance.start),
'event': _('%(child)s started tummy time!') % { 'event': _('%(child)s started tummy time!') % {
'child': instance.child.first_name 'child': instance.child.first_name
}, },
'edit_link': edit_link,
'model_name': instance.model_name, 'model_name': instance.model_name,
'type': 'start' 'type': 'start'
}) })
@ -98,6 +109,7 @@ def get_objects(child, date):
'event': _('%(child)s finished tummy time.') % { 'event': _('%(child)s finished tummy time.') % {
'child': instance.child.first_name 'child': instance.child.first_name
}, },
'edit_link': edit_link,
'model_name': instance.model_name, 'model_name': instance.model_name,
'type': 'end' 'type': 'end'
}) })