Projet

Général

Profil

0001-agendas-include-event-description-in-reminders-49034.patch

Valentin Deniaud, 09 décembre 2020 12:11

Télécharger (7,18 ko)

Voir les différences:

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(-)
chrono/agendas/templates/agendas/events_reminder_body.html
14 14
<p>{{ email_extra_info }}</p>
15 15
{% endif %}
16 16

  
17
{% if booking.event.description %}
18
<p>{% trans "Additionnal information:" %}</p>
19
{{ booking.event.description|linebreaks }}
20
{% endif %}
21

  
22
{% if booking.event.pricing %}
23
<p>{% trans "Pricing:" %} {{ booking.event.pricing }}</p>
24
{% endif %}
25

  
26
{% if booking.event.url %}
27
<p><a href="{{ booking.event.url }}">{% trans "More information" %}</a>
28
{% if booking.event.url == "#" %}<small>({% trans "link to event url, if present" %})</small>{% endif %}
29
</p>
30
{% endif %}
31

  
17 32
{% if booking.form_url %}
18 33
{% with _("Edit or cancel booking") as button_label %}
19 34
{% include "emails/button-link.html" with url=booking.form_url label=button_label %}
chrono/agendas/templates/agendas/events_reminder_body.txt
9 9
{% if email_extra_info %}
10 10
{{ email_extra_info }}
11 11
{% endif %}
12
{% if booking.event.description %}
13
{% trans "Additionnal information:" %}
14
{{ booking.event.description }}
15
{% endif %}
16
{% if booking.event.pricing %}
17
{% trans "Pricing:" %} {{ booking.event.pricing }}
18
{% endif %}
19
{% if booking.event.url %}
20
{% trans "More information:" %} {{ booking.event.url }}
21
{% endif %}
12 22
{% if booking.form_url %}
13 23
{% trans "If in need to cancel it, you can do so here:" %} {{ booking.form_url }}
14 24
{% endif %}
chrono/manager/views.py
29 29
from django.http import Http404, HttpResponse, HttpResponseRedirect
30 30
from django.shortcuts import get_object_or_404
31 31
from django.shortcuts import redirect
32
from django.template.defaultfilters import title
32 33
from django.template.loader import render_to_string
33 34
from django.urls import reverse, reverse_lazy
35
from django.utils import lorem_ipsum
34 36
from django.utils.dates import MONTHS
37
from django.utils.html import format_html
35 38
from django.utils.timezone import now, make_aware, make_naive, localtime
36 39
from django.utils.translation import ugettext_lazy as _
37 40
from django.utils.translation import ungettext
......
1586 1589
        kind = self.agenda.kind
1587 1590
        days = self.agenda.reminder_settings.days
1588 1591

  
1592
        paragraph = lorem_ipsum.paragraphs(1)[0][:232]
1593
        label = title(lorem_ipsum.words(2))
1589 1594
        event = Event(
1590
            label='{{ event_label }}',
1591 1595
            start_datetime=datetime.datetime(year=2020, month=6, day=2, hour=14, minute=30),
1596
            label=format_html('{} <small>({})</small>', label, _('event label')),
1597
            description=format_html('{} <small>({})</small>', paragraph, _('event description, if present')),
1598
            pricing=format_html('{} <small>({})</small>', '...', _('event pricing, if present')),
1599
            url='#',
1592 1600
        )
1601

  
1593 1602
        booking = Booking(user_display_label='{{ user_display_label }}', form_url='#')
1594 1603
        booking.event = event
1595 1604
        reminder_ctx = {
tests/test_agendas.py
1491 1491
        agenda=agenda, days=1, send_email=True, email_extra_info='Do no forget ID card.'
1492 1492
    )
1493 1493
    start_datetime = now() + datetime.timedelta(days=2)
1494
    event = Event.objects.create(agenda=agenda, start_datetime=start_datetime, places=10, label='Pool party')
1494
    event = Event.objects.create(
1495
        agenda=agenda,
1496
        start_datetime=start_datetime,
1497
        places=10,
1498
        label='Pool party',
1499
        description='Come !',
1500
        url='https://example.party',
1501
        pricing='10€',
1502
    )
1495 1503

  
1496 1504
    booking = Booking.objects.create(event=event, user_email='t@test.org')
1497 1505

  
......
1505 1513
        assert 'Hi,' in body
1506 1514
        assert 'You have a booking for event "Pool party", on Friday 3 January at 2 p.m..' in body
1507 1515
        assert 'Do no forget ID card.' in body
1516
        assert 'Come !' in body
1517
        assert 'Pricing: 10€' in body
1508 1518
        assert not 'cancel' in body
1519
        assert not 'if present' in body  # assert separation with preview code
1520
    assert 'More information: https://example.party' in mail_bodies[0]
1521
    assert '<a href="https://example.party">More information</a>' in mail_bodies[1]
1509 1522
    mailoutbox.clear()
1510 1523

  
1511 1524
    freezer.move_to('2020-01-01 14:00')
tests/test_manager.py
4760 4760
    assert 'Users will receive the following email:' in resp.text
4761 4761
    assert len(resp.pyquery.find('p.email-subject')) == 1
4762 4762
    assert '<strong>Subject:</strong> Reminder for your booking tomorrow at 2:30 p.m.' in resp.text
4763
    assert 'You have a booking for event "{{ event_label }}", on Tuesday 2 June at 2:30 p.m..' in resp.text
4763
    assert (
4764
        'You have a booking for event "Lorem Ipsum <small>(event label)</small>", on Tuesday 2 June at 2:30 p.m..'
4765
        in resp.text
4766
    )
4764 4767
    assert 'An ID will be required' in resp.text
4768
    assert ' ea commodo consequat. <small>(event description, if present)</small>' in resp.text
4769
    assert 'Pricing: ... <small>(event pricing, if present)</small>' in resp.text
4770
    assert '<a href="#">More information</a>' in resp.text
4771
    assert '<small>(link to event url, if present)</small>' in resp.text
4765 4772

  
4766 4773
    resp = resp.click('Return to settings')
4767 4774
    resp = resp.click('Preview SMS')
4768 4775
    assert 'Users will receive the following SMS:' in resp.text
4769 4776
    assert (
4770
        'Reminder: you have a booking for event "{{ event_label }}", on 02/06 at 2:30 p.m.. Take ID card.'
4777
        'Reminder: you have a booking for event "Lorem Ipsum <small>(event label)</small>", on 02/06 at 2:30 p.m.. Take ID card.'
4771 4778
        in resp.text
4772 4779
    )
4773 4780

  
4774
-