Projet

Général

Profil

0001-workflows-also-mark-status-on-trigger-timeout-jumps-.patch

Frédéric Péters, 29 octobre 2019 13:24

Télécharger (6,63 ko)

Voir les différences:

Subject: [PATCH] workflows: also mark status on trigger/timeout jumps (#37169)

 tests/test_form_pages.py                     |  4 ++-
 tests/test_workflows.py                      | 34 ++++++++++++++++++++
 wcs/ctl/management/commands/trigger_jumps.py | 16 +++++----
 wcs/wf/jump.py                               |  2 ++
 4 files changed, 48 insertions(+), 8 deletions(-)
tests/test_form_pages.py
4548 4548
    jump2 = JumpWorkflowStatusItem()
4549 4549
    jump2.trigger = 'YYY'
4550 4550
    jump2.status = 'st3'
4551
    jump2.set_marker_on_status = True
4551 4552
    st1.items.append(jump2)
4552 4553
    jump2.parent = st1
4553 4554

  
......
4591 4592
    resp = app.post(formdata.get_url() + 'jump/trigger/YYY', status=302)
4592 4593
    formdata = formdef.data_class().get(formdata.id)
4593 4594
    assert formdata.status == 'wf-st3'
4595
    assert formdata.workflow_data.get('_markers_stack') == [{'status_id': 'st1'}]
4594 4596

  
4595 4597
    formdata.status = 'wf-st1'
4596 4598
    formdata.store()
......
4598 4600
            params=json.dumps({'data': {'foo': 'bar'}}),
4599 4601
            content_type='application/json')
4600 4602
    formdata = formdef.data_class().get(formdata.id)
4601
    assert formdata.workflow_data == {'data': {'foo': 'bar'}}
4603
    assert formdata.workflow_data.get('data') == {'foo': 'bar'}
4602 4604

  
4603 4605
def test_form_worklow_multiple_identical_status(pub):
4604 4606
    user = create_user(pub)
tests/test_workflows.py
2152 2152

  
2153 2153
    assert not str(formdata_id) in [str(x) for x in formdef.data_class().keys()]
2154 2154

  
2155
def test_timeout_with_mark(two_pubs):
2156
    workflow = Workflow(name='timeout')
2157
    st1 = workflow.add_status('Status1', 'st1')
2158
    st2 = workflow.add_status('Status2', 'st2')
2159

  
2160
    jump = JumpWorkflowStatusItem()
2161
    jump.id = '_jump'
2162
    jump.by = ['_submitter', '_receiver']
2163
    jump.timeout = 0.1
2164
    jump.status = 'st2'
2165
    jump.set_marker_on_status = True
2166
    st1.items.append(jump)
2167
    jump.parent = st1
2168

  
2169
    workflow.store()
2170

  
2171
    formdef = FormDef()
2172
    formdef.name = 'baz'
2173
    formdef.fields = []
2174
    formdef.workflow_id = workflow.id
2175
    assert formdef.get_workflow().id == workflow.id
2176
    formdef.store()
2177

  
2178
    formdata = formdef.data_class()()
2179
    formdata.just_created()
2180
    formdata.store()
2181
    formdata_id = formdata.id
2182

  
2183
    time.sleep(0.3)
2184
    _apply_timeouts(two_pubs)
2185

  
2186
    formdata = formdef.data_class().get(formdata_id)
2187
    assert formdata.workflow_data.get('_markers_stack') == [{'status_id': 'st1'}]
2188

  
2155 2189
def test_sms(pub, sms_mocking):
2156 2190
    pub.cfg['sms'] = {'mode': 'xxx'}
2157 2191
    formdef = FormDef()
wcs/ctl/management/commands/trigger_jumps.py
89 89
        for item in status.items:
90 90
            if isinstance(item, JumpWorkflowStatusItem) and \
91 91
                item.trigger == trigger:
92
                yield 'wf-%s' % status.id, item.status
92
                yield 'wf-%s' % status.id, item.status, item
93 93
                break
94 94

  
95 95
def get_formdata_accepting_trigger(formdef, trigger, status_ids=None):
......
99 99
    formdata_ids = []
100 100

  
101 101
    data_class = formdef.data_class()
102
    for status_id, jump_to in status_ids:
102
    for status_id, jump_to, action_item in status_ids:
103 103
        formdata_ids = data_class.get_ids_with_indexed_value('status', status_id)
104 104
        for formdata_id in formdata_ids:
105
            yield data_class.get(id=formdata_id), jump_to
105
            yield data_class.get(id=formdata_id), jump_to, action_item
106 106

  
107 107
def match_row(substitution_variables, row):
108 108
    select = row['select']
......
111 111
            return False
112 112
    return True
113 113

  
114
def jump_and_perform(formdata, jump_to, workflow_data=None):
114
def jump_and_perform(formdata, jump_to, workflow_data=None, action=None):
115 115
    get_publisher().substitutions.reset()
116 116
    get_publisher().substitutions.feed(get_publisher())
117 117
    get_publisher().substitutions.feed(formdata.formdef)
118 118
    get_publisher().substitutions.feed(formdata)
119 119
    print 'formdata %s jumps to status %s' % (formdata, jump_to)
120
    if action:
121
        action.handle_markers_stack(formdata)
120 122
    wcs_jump_and_perform(formdata, jump_to, workflow_data=workflow_data)
121 123

  
122 124
def select_and_jump_formdata(formdef, trigger, rows, status_ids=None):
123
    for formdata, jump_to in get_formdata_accepting_trigger(formdef, trigger, status_ids):
125
    for formdata, jump_to, action_item in get_formdata_accepting_trigger(formdef, trigger, status_ids):
124 126
        if rows == '__all__':
125
            jump_and_perform(formdata, jump_to)
127
            jump_and_perform(formdata, jump_to, action=action_item)
126 128
        else:
127 129
            substitution_variables = formdata.get_substitution_variables()
128 130
            for row in rows:
129 131
                if match_row(substitution_variables, row):
130
                    jump_and_perform(formdata, jump_to, row.get('data'))
132
                    jump_and_perform(formdata, jump_to, row.get('data'), action=action_item)
131 133
                    break # next formdata
wcs/wf/jump.py
83 83
                    workflow_data = None
84 84
                    if hasattr(get_request(), 'json'):
85 85
                        workflow_data = get_request().json
86
                    item.handle_markers_stack(self.formdata)
86 87
                    url = jump_and_perform(self.formdata, item.status,
87 88
                            workflow_data=workflow_data)
88 89
                else:
......
293 294
                    get_publisher().substitutions.feed(formdef)
294 295
                    get_publisher().substitutions.feed(formdata)
295 296
                    if x.must_jump(formdata):
297
                        x.handle_markers_stack(formdata)
296 298
                        jump_and_perform(formdata, x.status)
297 299
                        break
298 300

  
299
-