0001-workflows-check-value-type-is-correct-when-setting-b.patch
tests/test_workflows.py | ||
---|---|---|
1733 | 1733 | |
1734 | 1734 |
formdata = formdef.data_class().get(formdata.id) |
1735 | 1735 |
assert formdata.data['bo1'].base_filename == 'xxx.xml' |
1736 | ||
1737 |
# check wrong value |
|
1738 |
del formdata.data['bo1'] |
|
1739 |
formdata.store() |
|
1740 |
assert not 'bo1' in formdata.data |
|
1741 | ||
1742 |
item = SetBackofficeFieldsWorkflowStatusItem() |
|
1743 |
item.fields = [{'field_id': 'bo1', 'value': '="HELLO"'}] |
|
1744 |
item.perform(formdata) |
|
1745 | ||
1746 |
formdata = formdef.data_class().get(formdata.id) |
|
1747 |
assert not 'bo1' in formdata.data |
wcs/wf/backoffice_fields.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU General Public License |
15 | 15 |
# along with this program; if not, see <http://www.gnu.org/licenses/>. |
16 | 16 | |
17 |
import base64 |
|
17 | 18 |
import sys |
18 | 19 |
import xml.etree.ElementTree as ET |
19 | 20 | |
... | ... | |
83 | 84 |
title=_('Fields Update'), value=self.fields, |
84 | 85 |
workflow=self.parent.parent) |
85 | 86 | |
87 |
def get_file_value(self, new_value): |
|
88 |
if isinstance(new_value, PicklableUpload): |
|
89 |
return new_value |
|
90 | ||
91 |
if isinstance(new_value, NamedAttachmentsSubstitutionProxy): |
|
92 |
upload = PicklableUpload(new_value.filename, new_value.content_type) |
|
93 |
upload.receive([new_value.content]) |
|
94 |
return upload |
|
95 | ||
96 |
raise ValueError('invalid data for file type (%r)' % new_value) |
|
97 | ||
86 | 98 |
def perform(self, formdata): |
87 | 99 |
if not self.fields: |
88 | 100 |
return |
89 | 101 |
for field in self.fields: |
90 | 102 |
try: |
103 |
formdef_field = [x for x in formdata.formdef.fields |
|
104 |
if 'bo%s' % x.id == field['field_id']][0] |
|
105 |
except IndexError: |
|
106 |
continue |
|
107 | ||
108 |
try: |
|
91 | 109 |
new_value = self.compute(field['value'], raises=True) |
92 | 110 |
except: |
93 | 111 |
get_publisher().notify_of_exception(sys.exc_info()) |
94 |
if isinstance(new_value, NamedAttachmentsSubstitutionProxy): |
|
95 |
upload = PicklableUpload(new_value.filename, new_value.content_type) |
|
96 |
upload.receive([new_value.content]) |
|
97 |
new_value = upload |
|
112 |
continue |
|
113 | ||
114 |
try: |
|
115 |
if formdef_field.type == 'file': |
|
116 |
new_value = self.get_file_value(new_value) |
|
117 |
except ValueError: |
|
118 |
get_publisher().notify_of_exception(sys.exc_info()) |
|
119 |
continue |
|
120 | ||
98 | 121 |
formdata.data['%s' % field['field_id']] = new_value |
99 | 122 |
formdata.store() |
100 | 123 | |
101 |
- |