Projet

Général

Profil

0001-admin-detail-target-status-on-choice-action-39207.patch

Nicolas Roche, 29 novembre 2020 19:34

Télécharger (5,92 ko)

Voir les différences:

Subject: [PATCH] admin: detail target status on choice action (#39207)

 tests/admin_pages/test_workflow.py | 60 +++++++++++++++++++++++++++++-
 wcs/workflows.py                   | 23 +++++++-----
 2 files changed, 72 insertions(+), 11 deletions(-)
tests/admin_pages/test_workflow.py
10 10

  
11 11
import pytest
12 12
from webtest import Upload
13 13

  
14 14
from wcs.qommon.http_request import HTTPRequest
15 15
from wcs.roles import Role
16 16
from wcs.workflows import (
17 17
    Workflow, WorkflowCriticalityLevel, DisplayMessageWorkflowStatusItem,
18
    WorkflowBackofficeFieldsFormDef, CommentableWorkflowStatusItem)
18
    WorkflowBackofficeFieldsFormDef, CommentableWorkflowStatusItem,
19
    ChoiceWorkflowStatusItem)
19 20
from wcs.wf.dispatch import DispatchWorkflowStatusItem
20 21
from wcs.wf.export_to_model import ExportToModel
21 22
from wcs.wf.jump import JumpWorkflowStatusItem
22 23
from wcs.wf.register_comment import RegisterCommenterWorkflowStatusItem
23 24
from wcs.wf.wscall import WebserviceCallStatusItem
24 25
from wcs.carddef import CardDef
25 26
from wcs.formdef import FormDef
26 27
from wcs import fields
......
946 947

  
947 948
    resp = app.get('/backoffice/workflows/1/')
948 949
    resp = resp.click('baz')
949 950
    resp = resp.click(href='items/1/', index=0)
950 951
    assert 'foobar' not in [x[2] for x in resp.form['by$element0'].options]
951 952
    assert '_receiver' in [x[0] for x in resp.form['by$element0'].options]
952 953

  
953 954

  
955
def test_workflows_edit_choice_action_line_details(pub):
956
    create_superuser(pub)
957
    create_role()
958

  
959
    Workflow.wipe()
960
    wf = Workflow(name='foo')
961
    st1 = wf.add_status('New')
962
    st2 = wf.add_status('Resubmit')
963

  
964
    jump = ChoiceWorkflowStatusItem()
965
    jump.id = '1'
966
    jump.parent = st1
967
    st1.items.append(jump)
968
    wf.store()
969

  
970
    app = login(get_app(pub))
971
    resp = app.get('/backoffice/workflows/%s/status/%s/' % (wf.id, st1.id))
972
    assert resp.html.find('a', {'href': 'items/1/'}).text == 'Manual Jump (not completed)'
973

  
974
    jump.label = 'Resubmit'
975
    wf.store()
976
    resp = app.get('/backoffice/workflows/%s/status/%s/' % (wf.id, st1.id))
977
    assert resp.html.find('a', {'href': 'items/1/'}).text == \
978
        'Manual Jump (not completed)'
979

  
980
    jump.status = st2.id
981
    wf.store()
982
    resp = app.get('/backoffice/workflows/%s/status/%s/' % (wf.id, st1.id))
983
    assert resp.html.find('a', {'href': 'items/1/'}).text == \
984
        'Manual Jump ("Resubmit", to Resubmit)'
985

  
986
    jump.label = 'Resubmit'
987
    wf.store()
988
    resp = app.get('/backoffice/workflows/%s/status/%s/' % (wf.id, st1.id))
989
    assert resp.html.find('a', {'href': 'items/1/'}).text == \
990
        'Manual Jump ("Resubmit", to Resubmit)'
991

  
992
    jump.set_marker_on_status = True
993
    wf.store()
994
    resp = app.get('/backoffice/workflows/%s/status/%s/' % (wf.id, st1.id))
995
    assert resp.html.find('a', {'href': 'items/1/'}).text == \
996
        'Manual Jump ("Resubmit", to Resubmit (and set marker))'
997

  
998
    jump.set_marker_on_status = False
999
    jump.by = ['_submitter']
1000
    wf.store()
1001
    resp = app.get('/backoffice/workflows/%s/status/%s/' % (wf.id, st1.id))
1002
    assert resp.html.find('a', {'href': 'items/1/'}).text == \
1003
        'Manual Jump ("Resubmit", to Resubmit, by User)'
1004

  
1005
    jump.set_marker_on_status = True
1006
    wf.store()
1007
    resp = app.get('/backoffice/workflows/%s/status/%s/' % (wf.id, st1.id))
1008
    assert resp.html.find('a', {'href': 'items/1/'}).text == \
1009
        'Manual Jump ("Resubmit", to Resubmit, by User (and set marker))'
1010

  
1011

  
954 1012
def test_workflows_action_subpath(pub):
955 1013
    create_superuser(pub)
956 1014
    create_role()
957 1015
    Workflow.wipe()
958 1016
    workflow = Workflow(name='foo')
959 1017
    baz_status = workflow.add_status(name='baz')
960 1018
    display_message = DisplayMessageWorkflowStatusItem()
961 1019
    display_message.parent = baz_status
wcs/workflows.py
2436 2436

  
2437 2437
    def get_label(self):
2438 2438
        expression = self.get_expression(self.label)
2439 2439
        if expression['type'] == 'text':
2440 2440
            return expression['value']
2441 2441
        return _('computed label')
2442 2442

  
2443 2443
    def get_line_details(self):
2444
        if self.label:
2444
        if self.label and self.status:
2445
            to_status = self.parent.parent.get_status(self.status)
2445 2446
            more = ''
2446 2447
            if self.set_marker_on_status:
2447 2448
                more += ' ' + _('(and set marker)')
2448 2449
            if self.by:
2449
                return  _('"%(label)s" by %(by)s%(more)s') % {
2450
                        'label' : self.get_label(),
2451
                        'by' : self.render_list_of_roles(self.by),
2452
                        'more': more
2453
                    }
2450
                return _('"%(label)s", to %(to)s, by %(by)s%(more)s') % {
2451
                    'label': self.get_label(),
2452
                    'to': to_status.name,
2453
                    'by': self.render_list_of_roles(self.by),
2454
                    'more': more
2455
                }
2454 2456
            else:
2455
                return _('"%(label)s"%(more)s') % {
2456
                        'label': self.get_label(),
2457
                        'more': more
2458
                    }
2457
                return _('"%(label)s", to %(to)s%(more)s') % {
2458
                    'label': self.get_label(),
2459
                    'to': to_status.name,
2460
                    'more': more
2461
                }
2459 2462
        else:
2460 2463
            return _('not completed')
2461 2464

  
2462 2465
    def fill_form(self, form, formdata, user, **kwargs):
2463 2466
        label = self.compute(self.label)
2464 2467
        if not label:
2465 2468
            return
2466 2469
        widget = form.add_submit('button%s' % self.id, label)
2467
-