workflows: do not display common varnames in unused workflows (#42741) #761
|
@ -3149,6 +3149,50 @@ def test_workflows_create_carddata_action_config(pub):
|
|||
assert "syntax error: Could not parse the remainder: '{{' from '{{'" in resp
|
||||
|
||||
|
||||
def test_workflows_create_formdata_config_common_varnames(pub):
|
||||
create_superuser(pub)
|
||||
|
||||
FormDef.wipe()
|
||||
target_formdef = FormDef()
|
||||
target_formdef.name = 'target form'
|
||||
target_formdef.fields = [
|
||||
fields.StringField(id='0', label='string1', varname='foo_string'),
|
||||
fields.StringField(id='1', label='string2', varname='bar_string'),
|
||||
]
|
||||
target_formdef.store()
|
||||
|
||||
Workflow.wipe()
|
||||
wf = Workflow(name='create-formdata')
|
||||
st = wf.add_status('New')
|
||||
st.add_action('create_formdata')
|
||||
wf.store()
|
||||
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/workflows/%s/status/%s/items/1/' % (wf.id, st.id))
|
||||
resp.forms[0]['formdef_slug'] = 'target-form'
|
||||
resp = resp.forms[0].submit('submit')
|
||||
assert 'Please define new mappings' in resp
|
||||
resp.form['map_fields_by_varname'].checked = True
|
||||
resp = resp.forms[0].submit('submit')
|
||||
resp = app.get('/backoffice/workflows/%s/status/%s/items/1/' % (wf.id, st.id))
|
||||
assert resp.pyquery('.common-varnames').length == 0
|
||||
|
||||
# attach workflow to a formdef
|
||||
formdef = FormDef()
|
||||
formdef.name = 'form'
|
||||
formdef.workflow = wf
|
||||
formdef.store()
|
||||
resp = app.get('/backoffice/workflows/%s/status/%s/items/1/' % (wf.id, st.id))
|
||||
assert resp.pyquery('.common-varnames').text() == 'Common varnames: none'
|
||||
|
||||
formdef.fields = [
|
||||
fields.StringField(id='2', label='string1', varname='foo_string'),
|
||||
]
|
||||
formdef.store()
|
||||
resp = app.get('/backoffice/workflows/%s/status/%s/items/1/' % (wf.id, st.id))
|
||||
assert resp.pyquery('.common-varnames').text() == 'Common varnames: foo_string'
|
||||
|
||||
|
||||
def test_workflows_create_formdata_expression_types(pub):
|
||||
create_superuser(pub)
|
||||
|
||||
|
|
|
@ -23,7 +23,7 @@ from quixote import get_publisher, get_request, get_session
|
|||
from quixote.html import TemplateIO, htmltext
|
||||
|
||||
from wcs.formdef import FormDef
|
||||
from wcs.qommon import _, ngettext
|
||||
from wcs.qommon import _, ngettext, pgettext
|
||||
from wcs.qommon.form import (
|
||||
CheckboxWidget,
|
||||
CompositeWidget,
|
||||
|
@ -497,13 +497,19 @@ class CreateFormdataWorkflowStatusItem(WorkflowStatusItem):
|
|||
value=self.map_fields_by_varname,
|
||||
advanced=True,
|
||||
)
|
||||
if self.map_fields_by_varname and self.formdef:
|
||||
common_varnames = [htmltext('<tt>%s</tt>') % varname for varname in self._common_varnames()]
|
||||
common_varnames = htmltext(', ').join(common_varnames)
|
||||
workflow_formdefs = self.get_workflow().formdefs()
|
||||
if self.map_fields_by_varname and self.formdef and workflow_formdefs:
|
||||
common_varnames = self.get_common_varnames(workflow_formdefs)
|
||||
if common_varnames:
|
||||
common_varnames = htmltext(', ').join(
|
||||
[htmltext('<tt>%s</tt>') % x for x in common_varnames]
|
||||
)
|
||||
else:
|
||||
common_varnames = htmltext('<i>%s</i>') % pgettext('identifier', 'none')
|
||||
form.add(
|
||||
HtmlWidget,
|
||||
name='common_varnames',
|
||||
title=htmltext('<div class="infonotice">%s %s</div>')
|
||||
title=htmltext('<div class="infonotice common-varnames">%s %s</div>')
|
||||
% (_('Common varnames:'), common_varnames),
|
||||
advanced=True,
|
||||
)
|
||||
|
@ -544,12 +550,13 @@ class CreateFormdataWorkflowStatusItem(WorkflowStatusItem):
|
|||
result.append(htmltext('<li>#%s → %s</li>') % (mapping.field_id, mapping.expression))
|
||||
return htmltext('<ul class="mappings">%s</ul>') % htmltext('').join(result)
|
||||
|
||||
def _common_varnames(self):
|
||||
'''Compute common varnames between the targeted formdef and all formdefs related to the parent workflow.'''
|
||||
def get_common_varnames(self, workflow_formdefs):
|
||||
# Compute common varnames between the targeted formdef and all formdefs related
|
||||
# to the parent workflow.
|
||||
assert self.formdef
|
||||
varnames = {
|
||||
field.varname
|
||||
for formdef in self.get_workflow().formdefs()
|
||||
for formdef in workflow_formdefs
|
||||
for field in formdef.get_widget_fields()
|
||||
if field.varname
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue