0001-workflows-also-mark-status-on-trigger-timeout-jumps-.patch
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 |
|
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, 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), 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, action, workflow_data=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 |
print 'formdata %s jumps to status %s' % (formdata, jump_to)
|
|
120 |
wcs_jump_and_perform(formdata, jump_to, workflow_data=workflow_data)
|
|
119 |
print 'formdata %s jumps to status %s' % (formdata, action.status)
|
|
120 |
wcs_jump_and_perform(formdata, action, workflow_data=workflow_data)
|
|
121 | 121 | |
122 | 122 |
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):
|
|
123 |
for formdata, action_item in get_formdata_accepting_trigger(formdef, trigger, status_ids):
|
|
124 | 124 |
if rows == '__all__': |
125 |
jump_and_perform(formdata, jump_to)
|
|
125 |
jump_and_perform(formdata, action=action_item)
|
|
126 | 126 |
else: |
127 | 127 |
substitution_variables = formdata.get_substitution_variables() |
128 | 128 |
for row in rows: |
129 | 129 |
if match_row(substitution_variables, row): |
130 |
jump_and_perform(formdata, jump_to, row.get('data'))
|
|
130 |
jump_and_perform(formdata, action_item, row.get('data'))
|
|
131 | 131 |
break # next formdata |
wcs/forms/actions.py | ||
---|---|---|
77 | 77 |
context=context) |
78 | 78 | |
79 | 79 |
def submit(self): |
80 |
url = jump_and_perform(self.formdata, self.action.status)
|
|
80 |
url = jump_and_perform(self.formdata, self.action) |
|
81 | 81 |
self.token.remove_self() |
82 | 82 |
if url: |
83 | 83 |
return redirect(url) |
wcs/wf/jump.py | ||
---|---|---|
34 | 34 | |
35 | 35 |
JUMP_TIMEOUT_INTERVAL = max((60 // int(os.environ.get('WCS_JUMP_TIMEOUT_CHECKS', '3')), 1)) |
36 | 36 | |
37 |
def jump_and_perform(formdata, status, workflow_data=None): |
|
37 |
def jump_and_perform(formdata, action, workflow_data=None): |
|
38 |
action.handle_markers_stack(formdata) |
|
38 | 39 |
if workflow_data: |
39 | 40 |
formdata.update_workflow_data(workflow_data) |
40 | 41 |
formdata.store() |
41 |
formdata.jump_status(status) |
|
42 |
formdata.jump_status(action.status)
|
|
42 | 43 |
url = formdata.perform_workflow() |
43 | 44 |
return url |
44 | 45 | |
... | ... | |
83 | 84 |
workflow_data = None |
84 | 85 |
if hasattr(get_request(), 'json'): |
85 | 86 |
workflow_data = get_request().json |
86 |
url = jump_and_perform(self.formdata, item.status, |
|
87 |
workflow_data=workflow_data) |
|
87 |
url = jump_and_perform(self.formdata, item, workflow_data=workflow_data) |
|
88 | 88 |
else: |
89 | 89 |
if get_request().is_json(): |
90 | 90 |
get_response().status_code = 403 |
... | ... | |
293 | 293 |
get_publisher().substitutions.feed(formdef) |
294 | 294 |
get_publisher().substitutions.feed(formdata) |
295 | 295 |
if x.must_jump(formdata): |
296 |
jump_and_perform(formdata, x.status)
|
|
296 |
jump_and_perform(formdata, x) |
|
297 | 297 |
break |
298 | 298 | |
299 | 299 |
if get_publisher_class(): |
300 |
- |