fields: export empty list if no display locations (#89002)
gitea/wcs/pipeline/head This commit looks good Details

This commit is contained in:
Lauréline Guérin 2024-04-03 11:29:08 +02:00 committed by Lauréline Guérin
parent df99864ada
commit c81031052b
4 changed files with 24 additions and 3 deletions

View File

@ -2298,6 +2298,19 @@ def test_workflows_backoffice_fields(pub):
)
assert 'prefill$type' not in resp.form.fields.keys()
# check display_locations
resp.form['display_locations$element0'] = False
resp.form['display_locations$element1'] = False
resp = resp.form.submit('submit')
assert (
resp.location
== 'http://example.net/backoffice/workflows/1/backoffice-fields/fields/#fieldId_%s'
% workflow.backoffice_fields_formdef.fields[1].id
)
resp = resp.follow()
workflow = Workflow.get(workflow.id)
assert workflow.backoffice_fields_formdef.fields[1].display_locations is None
# add a title field
resp = app.get('/backoffice/workflows/1/backoffice-fields/fields/')
resp.forms[0]['label'] = 'foobar3'

View File

@ -87,7 +87,7 @@ def test_empty_display_locations_tag(pub):
formdef = FormDef()
formdef.name = 'Foo'
formdef.fields = [
fields.TitleField(label='title', display_locations=[]),
fields.TitleField(label='title', display_locations=None),
fields.SubtitleField(label='subtitle', display_locations=[]),
fields.TextField(label='string', display_locations=[]),
]

View File

@ -494,9 +494,12 @@ def test_backoffice_fields(pub):
wf = Workflow(name='bo fields')
wf.backoffice_fields_formdef = WorkflowBackofficeFieldsFormDef(wf)
wf.backoffice_fields_formdef.fields = [
StringField(id='bo1', label='1st backoffice field', varname='backoffice_blah'),
StringField(
id='bo1', label='1st backoffice field', varname='backoffice_blah', display_locations=None
),
]
assert_import_export_works(wf, True)
wf2 = assert_import_export_works(wf)
assert wf2.backoffice_fields_formdef.fields[0].display_locations == []
def test_complex_dispatch_action(pub):

View File

@ -443,6 +443,11 @@ class Field:
if xml_node_text(node.find('locked')) == 'True':
self.prefill['locked'] = True
def display_locations_export_to_xml(self, node, include_id=False):
display_locations_node = ET.SubElement(node, 'display_locations')
for v in self.display_locations or []:
ET.SubElement(display_locations_node, 'item').text = force_str(v)
def get_rst_view_value(self, value, indent=''):
return indent + self.get_view_value(value)