0004-forms-add-an-_url-variant-to-vars-pointing-to-form-w.patch
help/fr/wf-form.page | ||
---|---|---|
48 | 48 |
champ</var></code> (par exemple : <code>contact_interne_var_telephone</code>). |
49 | 49 |
</p> |
50 | 50 | |
51 |
<note><p> |
|
52 |
Pour les champs de type fichier, la variable contiendra le nom du fichier. |
|
53 |
L'adresse du fichier sera présente dans la variable nommée |
|
54 |
<code><var>variable du formulaire</var>_var_<var>variable du champ</var>_url</code>. |
|
55 |
</p></note> |
|
56 | ||
51 | 57 |
</page> |
tests/test_form_pages.py | ||
---|---|---|
1078 | 1078 |
formdata = formdef.data_class().select()[0] |
1079 | 1079 |
assert 'xxx_var_yyy_raw' in formdata.workflow_data |
1080 | 1080 | |
1081 |
resp = resp.test_app.get(resp.location + 'files/form-xxx-yyy/test.txt') |
|
1082 |
assert resp.content_type == 'text/plain' |
|
1083 |
assert resp.body == 'foobar' |
|
1081 |
download = resp.test_app.get(resp.location + 'files/form-xxx-yyy/test.txt') |
|
1082 |
assert download.content_type == 'text/plain' |
|
1083 |
assert download.body == 'foobar' |
|
1084 | ||
1085 |
# go back to the status page, this will exercise the substitution variables |
|
1086 |
# codepath. |
|
1087 |
resp = resp.follow() |
wcs/formdata.py | ||
---|---|---|
17 | 17 |
import copy |
18 | 18 |
import datetime |
19 | 19 |
import json |
20 |
import re |
|
20 | 21 |
import sys |
21 | 22 |
import time |
22 | 23 | |
... | ... | |
423 | 424 | |
424 | 425 |
if self.workflow_data: |
425 | 426 |
d.update(self.workflow_data) |
427 |
# pass over uploaded files and attach an extra attribute with the |
|
428 |
# url to the file. |
|
429 |
for k, v in self.workflow_data.items(): |
|
430 |
if isinstance(v, Upload): |
|
431 |
try: |
|
432 |
formvar, fieldvar = re.match('(.*)_var_(.*)_raw$', k).groups() |
|
433 |
except AttributeError: |
|
434 |
continue |
|
435 |
d[k.rsplit('_', 1)[0] + '_url'] = '%sfiles/form-%s-%s/%s' % ( |
|
436 |
d['form_url'], formvar, fieldvar, |
|
437 |
self.workflow_data['%s_var_%s' % (formvar, fieldvar)]) |
|
426 | 438 | |
427 | 439 |
d = copy.deepcopy(d) |
428 | 440 |
flatten_dict(d) |
429 |
- |