admin: sort unused workflows in a secondary section (#12663)
This commit is contained in:
parent
931de1f511
commit
68a614159f
|
@ -2353,6 +2353,36 @@ def test_workflows_inspect_view(pub):
|
|||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/workflows/%s/inspect' % workflow.id)
|
||||
|
||||
def test_workflows_unused(pub):
|
||||
create_superuser(pub)
|
||||
FormDef.wipe()
|
||||
Workflow.wipe()
|
||||
app = login(get_app(pub))
|
||||
resp = app.get('/backoffice/workflows/')
|
||||
assert not 'Unused workflows' in resp.body
|
||||
|
||||
workflow = Workflow(name='Workflow One')
|
||||
workflow.store()
|
||||
resp = app.get('/backoffice/workflows/')
|
||||
assert 'Unused workflows' in resp.body
|
||||
|
||||
formdef = FormDef()
|
||||
formdef.name = 'form title'
|
||||
formdef.fields = []
|
||||
formdef.store()
|
||||
resp = app.get('/backoffice/workflows/')
|
||||
assert 'Unused workflows' in resp.body
|
||||
|
||||
formdef.workflow = workflow
|
||||
formdef.store()
|
||||
resp = app.get('/backoffice/workflows/')
|
||||
assert not 'Unused workflows' in resp.body
|
||||
|
||||
workflow = Workflow(name='Workflow Two')
|
||||
workflow.store()
|
||||
resp = app.get('/backoffice/workflows/')
|
||||
assert 'Unused workflows' in resp.body
|
||||
|
||||
def test_users(pub):
|
||||
create_superuser(pub)
|
||||
app = login(get_app(pub))
|
||||
|
|
|
@ -1775,14 +1775,31 @@ class WorkflowsDirectory(Directory):
|
|||
get_response().filter['sidebar'] = self.get_sidebar()
|
||||
|
||||
r += htmltext('<h2>%s</h2>') % _('Workflows')
|
||||
r += htmltext('<div>')
|
||||
r += htmltext('<ul class="biglist">')
|
||||
for workflow in [Workflow.get_default_workflow()] + Workflow.select(order_by = 'name'):
|
||||
workflows_in_use = set(['_default'])
|
||||
for formdef in FormDef.select():
|
||||
workflows_in_use.add(str(formdef.workflow_id))
|
||||
workflows = [Workflow.get_default_workflow()] + Workflow.select(order_by='name')
|
||||
has_unused_workflows = False
|
||||
for workflow in workflows:
|
||||
if not str(workflow.id) in workflows_in_use:
|
||||
has_unused_workflows = True
|
||||
continue
|
||||
r += htmltext('<li>')
|
||||
r += htmltext('<strong class="label"><a href="%s/">%s</a></strong>') % (workflow.id, workflow.name)
|
||||
r += htmltext('</li>')
|
||||
r += htmltext('</ul>')
|
||||
r += htmltext('</div>') # .bo-block
|
||||
if has_unused_workflows:
|
||||
r += htmltext('<h2>%s</h2>') % _('Unused workflows')
|
||||
r += htmltext('<ul class="biglist">')
|
||||
for workflow in workflows:
|
||||
if str(workflow.id) in workflows_in_use:
|
||||
continue
|
||||
r += htmltext('<li>')
|
||||
r += htmltext('<strong class="label"><a href="%s/">%s</a></strong>') % (workflow.id, workflow.name)
|
||||
r += htmltext('</li>')
|
||||
r += htmltext('</ul>')
|
||||
|
||||
return r.getvalue()
|
||||
|
||||
def get_sidebar(self):
|
||||
|
|
Loading…
Reference in New Issue