ics: add formdata description with backoffice url (#18406)
This commit is contained in:
parent
f258de57eb
commit
c4d83209dc
|
@ -9,6 +9,7 @@ import hmac
|
|||
import base64
|
||||
import hashlib
|
||||
import mock
|
||||
import re
|
||||
import urllib
|
||||
import urlparse
|
||||
import datetime
|
||||
|
@ -1607,10 +1608,20 @@ def test_api_ics_formdata(pub, local_user, ics_data):
|
|||
resp = get_app(pub).get(sign_uri('/api/forms/test/ics/foobar', user=local_user))
|
||||
assert resp.headers['content-type'] == 'text/calendar; charset=utf-8'
|
||||
assert resp.body.count('BEGIN:VEVENT') == 10
|
||||
# check that description contains form name, display id, workflow status,
|
||||
# backoffice url and attached user
|
||||
pattern = re.compile('DESCRIPTION:testé \| 1-\d+ \| New', re.MULTILINE)
|
||||
m = pattern.findall(resp.body)
|
||||
assert len(m) == 10
|
||||
assert resp.body.count('Jean Darmette') == 10
|
||||
|
||||
# check with a filter
|
||||
resp = get_app(pub).get(sign_uri('/api/forms/test/ics/foobar?filter=done', user=local_user))
|
||||
assert resp.body.count('BEGIN:VEVENT') == 20
|
||||
pattern = re.compile('DESCRIPTION:testé \| 1-\d+ \| Finished', re.MULTILINE)
|
||||
m = pattern.findall(resp.body)
|
||||
assert len(m) == 20
|
||||
assert resp.body.count('Jean Darmette') == 20
|
||||
|
||||
# check 404 on erroneous field var
|
||||
resp = get_app(pub).get(sign_uri('/api/forms/test/ics/xxx', user=local_user), status=404)
|
||||
|
|
|
@ -1646,7 +1646,17 @@ class FormPage(Directory):
|
|||
vevent.add('summary').value = unicode(formdata.get_display_name(), charset)
|
||||
vevent.add('dtstart').value = make_datetime(formdata.data[datefield_field_id])
|
||||
vevent.dtstart.value_param = 'DATE'
|
||||
vevent.add('url').value = formdata.get_url(backoffice=True)
|
||||
backoffice_url = formdata.get_url(backoffice=True)
|
||||
vevent.add('url').value = backoffice_url
|
||||
form_name = unicode(formdef.name, charset)
|
||||
status_name = unicode(formdata.get_status_label(), charset)
|
||||
description = '%s | %s | %s\n' % (form_name, formdata.get_display_id(), status_name)
|
||||
description += backoffice_url
|
||||
# TODO: improve performance by loading all users in one
|
||||
# single query before the loop
|
||||
if formdata.user:
|
||||
description += '\n%s' % unicode(formdata.user.get_display_name(), charset)
|
||||
vevent.add('description').value = description
|
||||
cal.add(vevent)
|
||||
|
||||
get_response().set_content_type('text/calendar')
|
||||
|
|
Loading…
Reference in New Issue