Projet

Général

Profil

0001-admin-sort-unused-workflows-in-a-secondary-section-1.patch

Frédéric Péters, 09 octobre 2016 17:33

Télécharger (3,45 ko)

Voir les différences:

Subject: [PATCH] admin: sort unused workflows in a secondary section (#12663)

 tests/test_admin_pages.py | 30 ++++++++++++++++++++++++++++++
 wcs/admin/workflows.py    | 23 ++++++++++++++++++++---
 2 files changed, 50 insertions(+), 3 deletions(-)
tests/test_admin_pages.py
2353 2353
    app = login(get_app(pub))
2354 2354
    resp = app.get('/backoffice/workflows/%s/inspect' % workflow.id)
2355 2355

  
2356
def test_workflows_unused(pub):
2357
    create_superuser(pub)
2358
    FormDef.wipe()
2359
    Workflow.wipe()
2360
    app = login(get_app(pub))
2361
    resp = app.get('/backoffice/workflows/')
2362
    assert not 'Unused workflows' in resp.body
2363

  
2364
    workflow = Workflow(name='Workflow One')
2365
    workflow.store()
2366
    resp = app.get('/backoffice/workflows/')
2367
    assert 'Unused workflows' in resp.body
2368

  
2369
    formdef = FormDef()
2370
    formdef.name = 'form title'
2371
    formdef.fields = []
2372
    formdef.store()
2373
    resp = app.get('/backoffice/workflows/')
2374
    assert 'Unused workflows' in resp.body
2375

  
2376
    formdef.workflow = workflow
2377
    formdef.store()
2378
    resp = app.get('/backoffice/workflows/')
2379
    assert not 'Unused workflows' in resp.body
2380

  
2381
    workflow = Workflow(name='Workflow Two')
2382
    workflow.store()
2383
    resp = app.get('/backoffice/workflows/')
2384
    assert 'Unused workflows' in resp.body
2385

  
2356 2386
def test_users(pub):
2357 2387
    create_superuser(pub)
2358 2388
    app = login(get_app(pub))
wcs/admin/workflows.py
1775 1775
        get_response().filter['sidebar'] = self.get_sidebar()
1776 1776

  
1777 1777
        r += htmltext('<h2>%s</h2>') % _('Workflows')
1778
        r += htmltext('<div>')
1779 1778
        r += htmltext('<ul class="biglist">')
1780
        for workflow in [Workflow.get_default_workflow()] + Workflow.select(order_by = 'name'):
1779
        workflows_in_use = set(['_default'])
1780
        for formdef in FormDef.select():
1781
            workflows_in_use.add(str(formdef.workflow_id))
1782
        workflows = [Workflow.get_default_workflow()] + Workflow.select(order_by='name')
1783
        has_unused_workflows = False
1784
        for workflow in workflows:
1785
            if not str(workflow.id) in workflows_in_use:
1786
                has_unused_workflows = True
1787
                continue
1781 1788
            r += htmltext('<li>')
1782 1789
            r += htmltext('<strong class="label"><a href="%s/">%s</a></strong>') % (workflow.id, workflow.name)
1783 1790
            r += htmltext('</li>')
1784 1791
        r += htmltext('</ul>')
1785
        r += htmltext('</div>') # .bo-block
1792
        if has_unused_workflows:
1793
            r += htmltext('<h2>%s</h2>') % _('Unused workflows')
1794
            r += htmltext('<ul class="biglist">')
1795
            for workflow in workflows:
1796
                if str(workflow.id) in workflows_in_use:
1797
                    continue
1798
                r += htmltext('<li>')
1799
                r += htmltext('<strong class="label"><a href="%s/">%s</a></strong>') % (workflow.id, workflow.name)
1800
                r += htmltext('</li>')
1801
            r += htmltext('</ul>')
1802

  
1786 1803
        return r.getvalue()
1787 1804

  
1788 1805
    def get_sidebar(self):
1789
-