0001-backoffice-don-t-display-invalid-option-replacement-.patch
tests/admin_pages/test_workflow.py | ||
---|---|---|
1386 | 1386 |
resp = resp.click('Edit', href='1/') |
1387 | 1387 | |
1388 | 1388 | |
1389 |
def test_workflows_variables_replacement(pub): |
|
1390 |
create_superuser(pub) |
|
1391 | ||
1392 |
Workflow.wipe() |
|
1393 |
workflow = Workflow(name='foo') |
|
1394 |
baz_status = workflow.add_status(name='baz') |
|
1395 |
display_message = DisplayMessageWorkflowStatusItem() |
|
1396 |
display_message.parent = baz_status |
|
1397 |
baz_status.items.append(display_message) |
|
1398 |
workflow.store() |
|
1399 | ||
1400 |
app = login(get_app(pub)) |
|
1401 |
resp = app.get('/backoffice/workflows/%s/variables/fields/' % workflow.id) |
|
1402 | ||
1403 |
# add a field |
|
1404 |
resp.forms[0]['label'] = 'foobar' |
|
1405 |
resp.forms[0]['type'] = 'string' |
|
1406 |
resp = resp.forms[0].submit().follow() |
|
1407 | ||
1408 |
# edit |
|
1409 |
resp = resp.click('Edit', href='1/') |
|
1410 |
resp.form['varname$select'].value = '1*1*message' |
|
1411 |
resp = resp.form.submit('submit').follow() |
|
1412 | ||
1413 |
# make sure a wrong variable name is not displayed |
|
1414 |
assert 'form_option_1*1*message' not in resp.text |
|
1415 |
assert Workflow.get(workflow.id).variables_formdef.fields[0].varname == '1*1*message' |
|
1416 | ||
1417 |
# and make sure it doesn't appear in formdata inspect page |
|
1418 |
formdef = FormDef() |
|
1419 |
formdef.name = 'Form title' |
|
1420 |
formdef.workflow = workflow |
|
1421 |
formdef.fields = [] |
|
1422 |
formdef.store() |
|
1423 | ||
1424 |
data_class = formdef.data_class() |
|
1425 |
data_class.wipe() |
|
1426 | ||
1427 |
formdata = data_class() |
|
1428 |
formdata.data = {} |
|
1429 |
formdata.status = 'wf-new' |
|
1430 |
formdata.store() |
|
1431 | ||
1432 |
resp = app.get(formdata.get_backoffice_url() + 'inspect') |
|
1433 |
assert 'form_option_1*1*message' not in resp.text |
|
1434 | ||
1435 | ||
1389 | 1436 |
def test_workflows_backoffice_fields(pub): |
1390 | 1437 |
create_superuser(pub) |
1391 | 1438 |
wcs/admin/fields.py | ||
---|---|---|
31 | 31 |
from wcs.qommon.admin.menu import command_icon |
32 | 32 |
from wcs.qommon.backoffice.menu import html_top |
33 | 33 |
from wcs.qommon.form import CheckboxWidget, Form, HtmlWidget, SingleSelectWidget, StringWidget |
34 |
from wcs.qommon.substitution import CompatibilityNamesDict |
|
34 | 35 | |
35 | 36 | |
36 | 37 |
class FieldDefPage(Directory): |
... | ... | |
326 | 327 |
r += htmltext('<span class="optional">%s</span>') % required |
327 | 328 |
if getattr(field, 'condition', None): |
328 | 329 |
r += htmltext(' - <span class="condition">%s</span>') % _('depending on condition') |
329 |
if getattr(field, 'varname', None): |
|
330 |
if getattr(field, 'varname', None) and CompatibilityNamesDict.valid_key_regex.match( |
|
331 |
field.varname |
|
332 |
): |
|
330 | 333 |
r += htmltext(' - <span class="varname">{{%s%s}}</span>') % ( |
331 | 334 |
self.field_var_prefix, |
332 | 335 |
field.varname, |
wcs/variables.py | ||
---|---|---|
1186 | 1186 |
data = self._formdef.workflow_options |
1187 | 1187 |
super().__init__(fields, data) |
1188 | 1188 | |
1189 |
def inspect_keys(self): |
|
1190 |
# don't display "parameter replacement" options |
|
1191 |
return [x for x in self.varnames.keys() if '*' not in x] |
|
1192 | ||
1189 | 1193 | |
1190 | 1194 |
class CardsSource: |
1191 | 1195 |
@classmethod |
1192 |
- |