api: allow weekday name in recurring event display template (#80042)
gitea/chrono/pipeline/head Build queued...
Details
gitea/chrono/pipeline/head Build queued...
Details
This commit is contained in:
parent
5f14f2a47b
commit
f371341d7d
|
@ -176,6 +176,10 @@ def is_event_disabled(
|
|||
|
||||
def get_event_text(event, agenda, day=None):
|
||||
event_text = force_str(event)
|
||||
|
||||
if day is not None:
|
||||
event.weekday = ISO_WEEKDAYS[day].capitalize()
|
||||
|
||||
if agenda.event_display_template:
|
||||
try:
|
||||
event_text = Template(agenda.event_display_template).render(
|
||||
|
@ -190,7 +194,7 @@ def get_event_text(event, agenda, day=None):
|
|||
)
|
||||
elif day is not None:
|
||||
event_text = _('%(weekday)s: %(event)s') % {
|
||||
'weekday': ISO_WEEKDAYS[day].capitalize(),
|
||||
'weekday': event.weekday,
|
||||
'event': event_text,
|
||||
}
|
||||
return event_text
|
||||
|
|
|
@ -123,6 +123,40 @@ def test_recurring_events_api_list(app, freezer):
|
|||
assert not any('example_event' in x['id'] for x in resp.json['data'])
|
||||
|
||||
|
||||
@pytest.mark.freeze_time('2021-12-13 14:00')
|
||||
def test_recurring_events_api_list_display_template(app):
|
||||
agenda = Agenda.objects.create(label='Foo bar', kind='events')
|
||||
Desk.objects.create(agenda=agenda, slug='_exceptions_holder')
|
||||
Event.objects.create(label='Normal event', start_datetime=now(), places=5, agenda=agenda)
|
||||
event = Event.objects.create(
|
||||
label='Example Event',
|
||||
start_datetime=now(),
|
||||
recurrence_days=[1, 4, 5], # Monday, Thursday, Friday
|
||||
recurrence_end_date=now() + datetime.timedelta(days=30),
|
||||
places=2,
|
||||
agenda=agenda,
|
||||
)
|
||||
event.create_all_recurrences()
|
||||
|
||||
resp = app.get('/api/agendas/recurring-events/?agendas=%s' % agenda.slug)
|
||||
assert [x['text'] for x in resp.json['data']] == [
|
||||
'Monday: Example Event',
|
||||
'Thursday: Example Event',
|
||||
'Friday: Example Event',
|
||||
]
|
||||
|
||||
agenda.event_display_template = (
|
||||
'{% if event.recurrence_days %}{{ event.weekday }}{% else %}{{ event }}{% endif %}'
|
||||
)
|
||||
agenda.save()
|
||||
|
||||
resp = app.get('/api/agendas/recurring-events/?agendas=%s' % agenda.slug)
|
||||
assert [x['text'] for x in resp.json['data']] == ['Monday', 'Thursday', 'Friday']
|
||||
|
||||
resp = app.get('/api/agenda/%s/datetimes/' % agenda.slug)
|
||||
assert [x['text'] for x in resp.json['data']][:3] == ['Example Event', 'Example Event', 'Example Event']
|
||||
|
||||
|
||||
@pytest.mark.freeze_time('2021-12-13 14:00') # Monday of 50th week
|
||||
def test_recurring_events_api_list_shared_custody(app):
|
||||
agenda = Agenda.objects.create(
|
||||
|
|
Loading…
Reference in New Issue