backoffice: add links from backoffice fields to backoffice actions (#58716) #557
|
@ -2250,6 +2250,45 @@ def test_workflows_backoffice_fields(pub):
|
|||
assert workflow.possible_status[0].items[0].fields == [{'field_id': first_field_id, 'value': 'Hello'}]
|
||||
|
||||
|
||||
def test_workflows_backoffice_fields_backlinks_to_actions(pub):
|
||||
create_superuser(pub)
|
||||
|
||||
Workflow.wipe()
|
||||
workflow = Workflow(name='foo')
|
||||
workflow.backoffice_fields_formdef = WorkflowBackofficeFieldsFormDef(workflow)
|
||||
workflow.backoffice_fields_formdef.fields = [
|
||||
fields.StringField(id='bo1', varname='bo1', label='bo1 variable'),
|
||||
fields.StringField(id='bo2', varname='bo2', label='bo2 variable'),
|
||||
]
|
||||
status = workflow.add_status(name='baz')
|
||||
action1 = status.add_action('set-backoffice-fields')
|
||||
action1.fields = [{'field_id': 'bo1', 'value': '1'}]
|
||||
global_action = workflow.add_global_action('Update')
|
||||
action2 = global_action.add_action('set-backoffice-fields')
|
||||
action2.fields = [{'field_id': 'bo1', 'value': '2'}]
|
||||
action3 = global_action.add_action('set-backoffice-fields')
|
||||
action3.label = 'foobar'
|
||||
action3.fields = [{'field_id': 'bo1', 'value': '2'}]
|
||||
workflow.store()
|
||||
|
||||
app = login(get_app(pub))
|
||||
resp = app.get(f'/backoffice/workflows/{workflow.id}/backoffice-fields/fields/bo2/')
|
||||
assert not resp.pyquery('.actions-using-this-field')
|
||||
|
||||
resp = app.get(f'/backoffice/workflows/{workflow.id}/backoffice-fields/fields/bo1/')
|
||||
assert {(x.text, x.attrib['href']) for x in resp.pyquery('.actions-using-this-field a')} == {
|
||||
('Action in status "baz"', 'http://example.net/backoffice/workflows/1/status/1/items/1/'),
|
||||
(
|
||||
'Action in global action "Update"',
|
||||
'http://example.net/backoffice/workflows/1/global-actions/1/items/1/',
|
||||
),
|
||||
(
|
||||
'"foobar" action in global action "Update"',
|
||||
'http://example.net/backoffice/workflows/1/global-actions/1/items/2/',
|
||||
),
|
||||
}
|
||||
|
||||
|
||||
def test_workflows_fields_labels(pub):
|
||||
create_superuser(pub)
|
||||
|
||||
|
|
|
@ -66,6 +66,9 @@ class FieldDefPage(Directory):
|
|||
form.add_submit('cancel', _('Cancel'))
|
||||
return form
|
||||
|
||||
def get_sidebar(self):
|
||||
return None
|
||||
|
||||
def _q_index(self):
|
||||
form = self.form()
|
||||
redo = False
|
||||
|
@ -89,6 +92,7 @@ class FieldDefPage(Directory):
|
|||
|
||||
if redo or not form.get_submit() == 'submit':
|
||||
get_response().set_title(self.objectdef.name)
|
||||
get_response().filter['sidebar'] = self.get_sidebar() # noqa pylint: disable=assignment-from-none
|
||||
r = TemplateIO(html=True)
|
||||
r += htmltext('<h2 class="field-edit--title">%s</h2>') % misc.ellipsize(
|
||||
self.field.unhtmled_label, 80
|
||||
|
|
|
@ -1132,6 +1132,32 @@ class WorkflowBackofficeFieldDefPage(FieldDefPage):
|
|||
section = 'workflows'
|
||||
blacklisted_attributes = ['condition']
|
||||
|
||||
def get_sidebar(self):
|
||||
if not self.field.id:
|
||||
return
|
||||
usage_actions = []
|
||||
for action in self.objectdef.workflow.get_all_items():
|
||||
if action.key != 'set-backoffice-fields':
|
||||
continue
|
||||
if any(x.get('field_id') == self.field.id for x in action.fields or []):
|
||||
usage_actions.append(action)
|
||||
if not usage_actions:
|
||||
return
|
||||
r = TemplateIO(html=True)
|
||||
r += htmltext('<div class="actions-using-this-field">')
|
||||
r += htmltext('<h3>%s</h3>') % _('Actions using this field')
|
||||
r += htmltext('<ul>')
|
||||
for action in usage_actions:
|
||||
label = _('"%s" action') % action.label if action.label else _('Action')
|
||||
if isinstance(action.parent, WorkflowGlobalAction):
|
||||
location = _('in global action "%s"') % action.parent.name
|
||||
else:
|
||||
location = _('in status "%s"') % action.parent.name
|
||||
r += htmltext(f'<li><a href="{action.get_admin_url()}">%s %s</a></li>') % (label, location)
|
||||
r += htmltext('</ul>')
|
||||
r += htmltext('<div>')
|
||||
return r.getvalue()
|
||||
|
||||
def form(self):
|
||||
form = super().form()
|
||||
form.remove('prefill')
|
||||
|
|
Loading…
Reference in New Issue