0002-workflows-allow-setting-backoffice-file-field-from-a.patch
tests/test_workflows.py | ||
---|---|---|
1734 | 1734 |
formdata = formdef.data_class().get(formdata.id) |
1735 | 1735 |
assert formdata.data['bo1'].base_filename == 'xxx.xml' |
1736 | 1736 | |
1737 |
# check storing a file from an assembled dictionary |
|
1738 |
item = SetBackofficeFieldsWorkflowStatusItem() |
|
1739 |
item.fields = [{'field_id': 'bo1', |
|
1740 |
'value': '={"content": "hello world", "filename": "hello.txt"}'}] |
|
1741 |
item.perform(formdata) |
|
1742 | ||
1743 |
formdata = formdef.data_class().get(formdata.id) |
|
1744 |
assert formdata.data['bo1'].base_filename == 'hello.txt' |
|
1745 |
assert formdata.data['bo1'].get_content() == 'hello world' |
|
1746 | ||
1747 |
item = SetBackofficeFieldsWorkflowStatusItem() |
|
1748 |
item.fields = [{'field_id': 'bo1', |
|
1749 |
'value': '={"b64_content": "SEVMTE8gV09STEQ=", "filename": "hello.txt"}'}] |
|
1750 |
item.perform(formdata) |
|
1751 | ||
1752 |
formdata = formdef.data_class().get(formdata.id) |
|
1753 |
assert formdata.data['bo1'].base_filename == 'hello.txt' |
|
1754 |
assert formdata.data['bo1'].get_content() == 'HELLO WORLD' |
|
1755 | ||
1737 | 1756 |
# check wrong value |
1738 | 1757 |
del formdata.data['bo1'] |
1739 | 1758 |
formdata.store() |
wcs/wf/backoffice_fields.py | ||
---|---|---|
93 | 93 |
upload.receive([new_value.content]) |
94 | 94 |
return upload |
95 | 95 | |
96 |
if isinstance(new_value, dict): |
|
97 |
# if value is a dictionary we expect it to have a content or |
|
98 |
# b64_content key and a filename keys and an optional |
|
99 |
# content_type key. |
|
100 |
if 'b64_content' in new_value: |
|
101 |
new_value['content'] = base64.decodestring(new_value['b64_content']) |
|
102 |
if 'filename' in new_value and 'content' in new_value: |
|
103 |
upload = PicklableUpload(new_value['filename'], |
|
104 |
new_value.get('content_type') or 'application/octet-stream') |
|
105 |
upload.receive(new_value['content']) |
|
106 |
return upload |
|
107 | ||
96 | 108 |
raise ValueError('invalid data for file type (%r)' % new_value) |
97 | 109 | |
98 | 110 |
def perform(self, formdata): |
99 |
- |