ics: add formdata digest to ics export (#33152)

This commit is contained in:
Nicolas Roche 2020-04-09 16:17:29 +02:00
parent c0a09241c3
commit 06da67b5ac
2 changed files with 15 additions and 1 deletions

View File

@ -2429,6 +2429,7 @@ def ics_data(local_user):
fields.StringField(id='0', label='foobar', varname='foobar'),
fields.StringField(id='1', label='foobar2', varname='foobar2'),
]
formdef.digest_template = 'plöp {{ form_var_foobar }} plÔp'
formdef.store()
data_class = formdef.data_class()
@ -2492,6 +2493,14 @@ def test_api_ics_formdata(pub, local_user, ics_data):
assert resp.text.count('Jean Darmette') == 10
assert resp.text.count('DTSTART') == 10
# check formdata digest summary and description contains the formdata digest
pattern = re.compile(
r'SUMMARY:testé #1-\d+ - plöp \d{4}-\d{2}-\d{2} \d{2}:\d{2} plÔp',
re.MULTILINE)
m = pattern.findall(resp.text)
assert len(m) == 10
assert resp.text.count(r'plöp') == 20
# check with a filter
resp = get_app(pub).get(sign_uri('/api/forms/test/ics/foobar?filter=done', user=local_user))
assert resp.text.count('BEGIN:VEVENT') == 20

View File

@ -2206,7 +2206,10 @@ class FormPage(Directory):
get_request().get_server().lower(),
formdef.url_name,
formdata.id)
vevent.add('summary').value = force_text(formdata.get_display_name(), charset)
summary = force_text(formdata.get_display_name(), charset)
if formdata.digest:
summary += ' - %s' % force_text(formdata.digest, charset)
vevent.add('summary').value = summary
vevent.add('dtstart').value = dtstart
if dtend:
vevent.add('dtend').value = dtend
@ -2216,6 +2219,8 @@ class FormPage(Directory):
form_name = force_text(formdef.name, charset)
status_name = force_text(formdata.get_status_label(), charset)
description = '%s | %s | %s\n' % (form_name, formdata.get_display_id(), status_name)
if formdata.digest:
description += '%s\n' % force_text(formdata.digest, charset)
description += backoffice_url
# TODO: improve performance by loading all users in one
# single query before the loop