0003-formdef-fix-max_field_id-on-import-9173.patch
tests/test_formdef_import.py | ||
---|---|---|
270 | 270 | |
271 | 271 |
with pytest.raises(FormdefImportError): |
272 | 272 |
FormDef.import_from_xml(StringIO.StringIO(export), include_id=True) |
273 | ||
274 |
def test_wrong_max_field_id(): |
|
275 |
formdef = FormDef() |
|
276 |
formdef.name = 'foo' |
|
277 |
formdef.fields = [ |
|
278 |
fields.StringField(id='1', type='string'), |
|
279 |
fields.StringField(id='2', type='string'),] |
|
280 |
formdef.max_field_id = 1 |
|
281 |
export = ET.tostring(export_to_indented_xml(formdef, include_id=True)) |
|
282 | ||
283 |
formdef2 = FormDef.import_from_xml(StringIO.StringIO(export), include_id=True) |
|
284 |
assert formdef2.max_field_id == 2 |
wcs/formdef.py | ||
---|---|---|
613 | 613 |
formdef.fields.append(field_o) |
614 | 614 | |
615 | 615 |
if formdef.fields and not formdef.max_field_id: |
616 |
formdef.max_field_id = max([lax_int(x.id) for x in formdef.fields])+1
|
|
616 |
formdef.max_field_id = max([lax_int(x.id) for x in formdef.fields]) |
|
617 | 617 | |
618 | 618 |
if value.get('options'): |
619 | 619 |
formdef.workflow_options = value.get('options') |
... | ... | |
689 | 689 |
formdef = cls.import_from_xml_tree(tree, charset=charset, |
690 | 690 |
include_id=include_id) |
691 | 691 | |
692 |
# fix max_field_id if necessary |
|
693 |
if formdef.max_field_id is not None: |
|
694 |
max_field_id = max([lax_int(x.id) for x in formdef.fields]) |
|
695 |
if formdef.max_field_id < max_field_id: |
|
696 |
formdef.max_field_id = max_field_id |
|
697 | ||
692 | 698 |
# check if datasources are defined |
693 | 699 |
unknown_datasources = set() |
694 | 700 |
for field in formdef.fields: |
... | ... | |
750 | 756 |
field_o.init_with_xml(field, charset, include_id=include_id) |
751 | 757 |
if not field_o.id: |
752 | 758 |
# this assumes all fields will have id, or none of them |
753 |
field_o.id = str(i) |
|
759 |
field_o.id = str(i+1)
|
|
754 | 760 |
formdef.fields.append(field_o) |
755 | 761 | |
756 | 762 |
if formdef.fields: |
... | ... | |
758 | 764 |
if value is not None: |
759 | 765 |
formdef.max_field_id = int(value.text) |
760 | 766 |
else: |
761 |
formdef.max_field_id = max([lax_int(x.id) for x in formdef.fields])+1
|
|
767 |
formdef.max_field_id = max([lax_int(x.id) for x in formdef.fields]) |
|
762 | 768 | |
763 | 769 |
formdef.workflow_options = {} |
764 | 770 |
for option in tree.findall('options/option'): |
765 |
- |