Projet

Général

Profil

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

Valentin Deniaud, 14 décembre 2020 14:44

Télécharger (7,64 ko)

Voir les différences:

Subject: [PATCH] agendas: include event description in reminders (#49034)

 .../templates/agendas/events_reminder_body.html   | 14 ++++++++++++++
 .../templates/agendas/events_reminder_body.txt    | 10 ++++++++++
 chrono/manager/views.py                           | 13 ++++++++++++-
 tests/test_agendas.py                             | 15 ++++++++++++++-
 tests/test_manager.py                             | 10 ++++++++--
 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 "Additional 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
{% firstof event_url_button_label _("More information") as button_label %}
28
{% include "emails/button-link.html" with url=booking.event.url label=button_label %}
29
{% endif %}
30

  
17 31
{% if booking.form_url %}
18 32
{% with _("Edit or cancel booking") as button_label %}
19 33
{% 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 "Additional 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
......
1595 1598
        kind = self.agenda.kind
1596 1599
        days = self.agenda.reminder_settings.days
1597 1600

  
1601
        paragraph = lorem_ipsum.paragraphs(1)[0][:232]
1602
        label = title(lorem_ipsum.words(2))
1598 1603
        event = Event(
1599
            label='{{ event_label }}',
1600 1604
            start_datetime=datetime.datetime(year=2020, month=6, day=2, hour=14, minute=30),
1605
            label=format_html('{} <small>({})</small>', label, _('event label')),
1606
            description=format_html('{} <small>({})</small>', paragraph, _('event description, if present')),
1607
            pricing=format_html('{} <small>({})</small>', '...', _('event pricing, if present')),
1608
            url='#',
1601 1609
        )
1610

  
1602 1611
        booking = Booking(user_display_label='{{ user_display_label }}', form_url='#')
1603 1612
        booking.event = event
1613
        button_label = format_html('{}<br>({})', _('More information'), _('link to event url, if present'))
1604 1614
        reminder_ctx = {
1605 1615
            'booking': booking,
1606 1616
            'in_x_days': _('tomorrow') if days == 1 else _('in %s days') % days,
1607 1617
            'date': booking.event.start_datetime,
1608 1618
            'email_extra_info': self.agenda.reminder_settings.email_extra_info,
1609 1619
            'sms_extra_info': self.agenda.reminder_settings.sms_extra_info,
1620
            'event_url_button_label': button_label,
1610 1621
        }
1611 1622

  
1612 1623
        if self.type_ == 'email':
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
4762 4762
    assert 'Users will receive the following email:' in resp.text
4763 4763
    assert len(resp.pyquery.find('p.email-subject')) == 1
4764 4764
    assert '<strong>Subject:</strong> Reminder for your booking tomorrow at 2:30 p.m.' in resp.text
4765
    assert 'You have a booking for event "{{ event_label }}", on Tuesday 2 June at 2:30 p.m..' in resp.text
4765
    assert (
4766
        'You have a booking for event "Lorem Ipsum <small>(event label)</small>", on Tuesday 2 June at 2:30 p.m..'
4767
        in resp.text
4768
    )
4766 4769
    assert 'An ID will be required' in resp.text
4770
    assert ' ea commodo consequat. <small>(event description, if present)</small>' in resp.text
4771
    assert 'Pricing: ... <small>(event pricing, if present)</small>' in resp.text
4772
    assert '<a href="#">More information<br>(link to event url, if present)</a>' in resp.text
4767 4773

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

  
4776
-