From 7a59163bf49cea8d75cb194d80ef9a5d675449ee Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Tue, 8 Dec 2020 17:24:03 +0100 Subject: [PATCH] agendas: include event description in reminders (#49034) --- .../templates/agendas/events_reminder_body.html | 15 +++++++++++++++ .../templates/agendas/events_reminder_body.txt | 10 ++++++++++ chrono/manager/views.py | 11 ++++++++++- tests/test_agendas.py | 15 ++++++++++++++- tests/test_manager.py | 11 +++++++++-- 5 files changed, 58 insertions(+), 4 deletions(-) diff --git a/chrono/agendas/templates/agendas/events_reminder_body.html b/chrono/agendas/templates/agendas/events_reminder_body.html index 2134ca0..0e1a562 100644 --- a/chrono/agendas/templates/agendas/events_reminder_body.html +++ b/chrono/agendas/templates/agendas/events_reminder_body.html @@ -14,6 +14,21 @@ You have a booking for event "{{ event }}", on {{ date }} at {{ time }}.

{{ email_extra_info }}

{% endif %} +{% if booking.event.description %} +

{% trans "Additionnal information:" %}

+{{ booking.event.description|linebreaks }} +{% endif %} + +{% if booking.event.pricing %} +

{% trans "Pricing:" %} {{ booking.event.pricing }}

+{% endif %} + +{% if booking.event.url %} +

{% trans "More information" %} +{% if booking.event.url == "#" %}({% trans "link to event url, if present" %}){% endif %} +

+{% endif %} + {% if booking.form_url %} {% with _("Edit or cancel booking") as button_label %} {% include "emails/button-link.html" with url=booking.form_url label=button_label %} diff --git a/chrono/agendas/templates/agendas/events_reminder_body.txt b/chrono/agendas/templates/agendas/events_reminder_body.txt index f61bd3f..4211e51 100644 --- a/chrono/agendas/templates/agendas/events_reminder_body.txt +++ b/chrono/agendas/templates/agendas/events_reminder_body.txt @@ -9,6 +9,16 @@ You have a booking for event "{{ event }}", on {{ date }} at {{ time }}. {% if email_extra_info %} {{ email_extra_info }} {% endif %} +{% if booking.event.description %} +{% trans "Additionnal information:" %} +{{ booking.event.description }} +{% endif %} +{% if booking.event.pricing %} +{% trans "Pricing:" %} {{ booking.event.pricing }} +{% endif %} +{% if booking.event.url %} +{% trans "More information:" %} {{ booking.event.url }} +{% endif %} {% if booking.form_url %} {% trans "If in need to cancel it, you can do so here:" %} {{ booking.form_url }} {% endif %} diff --git a/chrono/manager/views.py b/chrono/manager/views.py index e146209..fbc29e5 100644 --- a/chrono/manager/views.py +++ b/chrono/manager/views.py @@ -29,9 +29,12 @@ from django.db.models import Min, Max from django.http import Http404, HttpResponse, HttpResponseRedirect from django.shortcuts import get_object_or_404 from django.shortcuts import redirect +from django.template.defaultfilters import title from django.template.loader import render_to_string from django.urls import reverse, reverse_lazy +from django.utils import lorem_ipsum from django.utils.dates import MONTHS +from django.utils.html import format_html from django.utils.timezone import now, make_aware, make_naive, localtime from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ungettext @@ -1586,10 +1589,16 @@ class AgendaReminderPreviewView(ManagedAgendaMixin, TemplateView): kind = self.agenda.kind days = self.agenda.reminder_settings.days + paragraph = lorem_ipsum.paragraphs(1)[0][:232] + label = title(lorem_ipsum.words(2)) event = Event( - label='{{ event_label }}', start_datetime=datetime.datetime(year=2020, month=6, day=2, hour=14, minute=30), + label=format_html('{} ({})', label, _('event label')), + description=format_html('{} ({})', paragraph, _('event description, if present')), + pricing=format_html('{} ({})', '...', _('event pricing, if present')), + url='#', ) + booking = Booking(user_display_label='{{ user_display_label }}', form_url='#') booking.event = event reminder_ctx = { diff --git a/tests/test_agendas.py b/tests/test_agendas.py index 1b5cfee..794fbba 100644 --- a/tests/test_agendas.py +++ b/tests/test_agendas.py @@ -1491,7 +1491,15 @@ def test_agenda_reminders_email_content(mailoutbox, freezer): agenda=agenda, days=1, send_email=True, email_extra_info='Do no forget ID card.' ) start_datetime = now() + datetime.timedelta(days=2) - event = Event.objects.create(agenda=agenda, start_datetime=start_datetime, places=10, label='Pool party') + event = Event.objects.create( + agenda=agenda, + start_datetime=start_datetime, + places=10, + label='Pool party', + description='Come !', + url='https://example.party', + pricing='10€', + ) booking = Booking.objects.create(event=event, user_email='t@test.org') @@ -1505,7 +1513,12 @@ def test_agenda_reminders_email_content(mailoutbox, freezer): assert 'Hi,' in body assert 'You have a booking for event "Pool party", on Friday 3 January at 2 p.m..' in body assert 'Do no forget ID card.' in body + assert 'Come !' in body + assert 'Pricing: 10€' in body assert not 'cancel' in body + assert not 'if present' in body # assert separation with preview code + assert 'More information: https://example.party' in mail_bodies[0] + assert 'More information' in mail_bodies[1] mailoutbox.clear() freezer.move_to('2020-01-01 14:00') diff --git a/tests/test_manager.py b/tests/test_manager.py index 64ab7f4..51c75a0 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -4760,14 +4760,21 @@ def test_manager_reminders_preview(app, admin_user): assert 'Users will receive the following email:' in resp.text assert len(resp.pyquery.find('p.email-subject')) == 1 assert 'Subject: Reminder for your booking tomorrow at 2:30 p.m.' in resp.text - assert 'You have a booking for event "{{ event_label }}", on Tuesday 2 June at 2:30 p.m..' in resp.text + assert ( + 'You have a booking for event "Lorem Ipsum (event label)", on Tuesday 2 June at 2:30 p.m..' + in resp.text + ) assert 'An ID will be required' in resp.text + assert ' ea commodo consequat. (event description, if present)' in resp.text + assert 'Pricing: ... (event pricing, if present)' in resp.text + assert 'More information' in resp.text + assert '(link to event url, if present)' in resp.text resp = resp.click('Return to settings') resp = resp.click('Preview SMS') assert 'Users will receive the following SMS:' in resp.text assert ( - 'Reminder: you have a booking for event "{{ event_label }}", on 02/06 at 2:30 p.m.. Take ID card.' + 'Reminder: you have a booking for event "Lorem Ipsum (event label)", on 02/06 at 2:30 p.m.. Take ID card.' in resp.text ) -- 2.20.1