0001-workflows-add-possibility-to-mark-and-jump-to-marked.patch
tests/test_backoffice_pages.py | ||
---|---|---|
7 | 7 |
import StringIO |
8 | 8 |
import time |
9 | 9 |
import hashlib |
10 |
import random |
|
10 | 11 | |
11 | 12 |
import pytest |
12 | 13 |
from webtest import Upload |
... | ... | |
3105 | 3106 |
.parents('li').children('div.value span') |
3106 | 3107 |
.text() == '\'\\xed\\xa0\\x00\'') |
3107 | 3108 | |
3109 |
def test_workflow_jump_previous(pub): |
|
3110 |
user = create_user(pub) |
|
3111 |
create_environment(pub) |
|
3112 | ||
3113 |
wf = Workflow(name='jump around') |
|
3114 |
# North |
|
3115 |
# / \ |
|
3116 |
# West <----> East |
|
3117 |
# | | |
|
3118 |
# | autojump |
|
3119 |
# | | |
|
3120 |
# \ / |
|
3121 |
# South |
|
3122 | ||
3123 |
st1 = wf.add_status('North') |
|
3124 |
st1.id = 'north' |
|
3125 |
st2 = wf.add_status('West') |
|
3126 |
st2.id = 'west' |
|
3127 |
st3 = wf.add_status('East') |
|
3128 |
st3.id = 'east' |
|
3129 |
st4 = wf.add_status('Autojump') |
|
3130 |
st4.id = 'autojump' |
|
3131 |
st5 = wf.add_status('South') |
|
3132 |
st5.id = 'south' |
|
3133 | ||
3134 |
button_by_id = {} |
|
3135 | ||
3136 |
def add_jump(label, src, dst_id): |
|
3137 |
jump = ChoiceWorkflowStatusItem() |
|
3138 |
jump.id = str(random.random()) |
|
3139 |
jump.label = label |
|
3140 |
jump.by = ['logged-users'] |
|
3141 |
jump.status = dst_id |
|
3142 |
src.items.append(jump) |
|
3143 |
jump.parent = src |
|
3144 |
if dst_id != '_previous': |
|
3145 |
jump.set_marker_on_status = True |
|
3146 |
button_by_id[label] = 'button%s' % jump.id |
|
3147 |
return jump |
|
3148 | ||
3149 |
add_jump('Go West', st1, st2.id) |
|
3150 |
add_jump('Go East', st1, st3.id) |
|
3151 |
add_jump('Go South', st2, st5.id) |
|
3152 |
add_jump('Go Autojump', st3, st4.id) |
|
3153 |
add_jump('Go Back', st5, '_previous') |
|
3154 | ||
3155 |
add_jump('Jump West', st3, st2.id) |
|
3156 |
add_jump('Jump East', st2, st3.id) |
|
3157 | ||
3158 |
jump = JumpWorkflowStatusItem() |
|
3159 |
jump.id = '_auto-jump' |
|
3160 |
jump.status = st5.id |
|
3161 |
st4.items.append(jump) |
|
3162 |
jump.parent = st4 |
|
3163 | ||
3164 |
wf.store() |
|
3165 | ||
3166 |
formdef = FormDef.get_by_urlname('form-title') |
|
3167 |
formdef.data_class().wipe() |
|
3168 |
formdef.workflow = wf |
|
3169 |
formdef.store() |
|
3170 | ||
3171 |
formdata = formdef.data_class()() |
|
3172 |
formdata.data = {} |
|
3173 |
formdata.just_created() |
|
3174 |
formdata.store() |
|
3175 | ||
3176 |
app = login(get_app(pub)) |
|
3177 |
resp = app.get('/backoffice/management/form-title/%s/' % formdata.id) |
|
3178 | ||
3179 |
# jump around using buttons |
|
3180 |
resp = resp.form.submit(button_by_id['Go West']).follow() # push (north) |
|
3181 |
assert formdef.data_class().get(formdata.id).status == 'wf-%s' % st2.id |
|
3182 |
resp = resp.form.submit(button_by_id['Go South']).follow() # push (north, west) |
|
3183 |
assert formdef.data_class().get(formdata.id).status == 'wf-%s' % st5.id |
|
3184 |
resp = resp.form.submit(button_by_id['Go Back']).follow() # pop (north) |
|
3185 |
assert formdef.data_class().get(formdata.id).status == 'wf-%s' % st2.id |
|
3186 |
resp = resp.form.submit(button_by_id['Go South']).follow() # push (north, west) |
|
3187 |
assert formdef.data_class().get(formdata.id).status == 'wf-%s' % st5.id |
|
3188 |
resp = resp.form.submit(button_by_id['Go Back']).follow() # pop (north) |
|
3189 |
assert formdef.data_class().get(formdata.id).status == 'wf-%s' % st2.id |
|
3190 |
resp = resp.form.submit(button_by_id['Jump East']).follow() # push (north, west) |
|
3191 |
assert formdef.data_class().get(formdata.id).status == 'wf-%s' % st3.id |
|
3192 |
resp = resp.form.submit(button_by_id['Go Autojump']).follow() # push (north, west, east) |
|
3193 |
assert formdef.data_class().get(formdata.id).status == 'wf-%s' % st5.id |
|
3194 |
resp = resp.form.submit(button_by_id['Go Back']).follow() # pop (north, west) |
|
3195 |
assert formdef.data_class().get(formdata.id).status == 'wf-%s' % st3.id |
|
3196 | ||
3197 |
# and do a last jump using the API |
|
3198 |
formdata = formdef.data_class().get(formdata.id) |
|
3199 |
formdata.jump_status('_previous') # pop (north) |
|
3200 |
assert formdata.status == 'wf-%s' % st2.id |
|
3201 | ||
3202 |
formdata = formdef.data_class().get(formdata.id) |
|
3203 |
formdata.jump_status('_previous') # pop () |
|
3204 |
assert formdata.status == 'wf-%s' % st1.id |
|
3205 | ||
3108 | 3206 |
def test_backoffice_fields(pub): |
3109 | 3207 |
user = create_user(pub) |
3110 | 3208 |
create_environment(pub) |
wcs/admin/workflows.py | ||
---|---|---|
153 | 153 |
for status in workflow.possible_status: |
154 | 154 |
i = status.id |
155 | 155 |
for item in status.items: |
156 |
next_status_ids = [x.id for x in item.get_target_status() if x.id != status.id] |
|
156 |
next_status_ids = [x.id for x in item.get_target_status() |
|
157 |
if x.id and x.id != status.id] |
|
157 | 158 |
if not next_status_ids: |
158 | 159 |
next_status_ids = [status.id] |
159 | 160 |
done = {} |
wcs/formdata.py | ||
---|---|---|
452 | 452 |
return None |
453 | 453 |
return wf_status.handle_form(form, self, user) |
454 | 454 | |
455 |
def get_previous_marked_status(self): |
|
456 |
if not self.workflow_data or not 'markers_stack' in self.workflow_data: |
|
457 |
return None |
|
458 |
try: |
|
459 |
status_id = self.workflow_data['markers_stack'].pop() |
|
460 |
except IndexError: |
|
461 |
return None |
|
462 |
return self.formdef.workflow.get_status(status_id[3:]) |
|
463 | ||
455 | 464 |
def jump_status(self, status_id): |
465 |
if status_id == '_previous': |
|
466 |
previous_status = self.get_previous_marked_status() |
|
467 |
assert previous_status, 'failed to compute previous status' |
|
468 |
status_id = previous_status.id |
|
456 | 469 |
evo = Evolution() |
457 | 470 |
evo.time = time.localtime() |
458 | 471 |
evo.status = 'wf-%s' % status_id |
wcs/wf/jump.py | ||
---|---|---|
190 | 190 |
return |
191 | 191 | |
192 | 192 |
if self.must_jump(formdata): |
193 |
wf_status = self.get_target_status() |
|
193 |
wf_status = self.get_target_status(formdata)
|
|
194 | 194 |
if wf_status: |
195 | 195 |
formdata.status = 'wf-%s' % wf_status[0].id |
196 | 196 |
wcs/workflows.py | ||
---|---|---|
421 | 421 |
# a waitpoint status is a status waiting for an event (be it user |
422 | 422 |
# interaction or something else), but can also be an endpoint (where |
423 | 423 |
# the user would wait, infinitely). |
424 |
waitpoint_status = [] |
|
425 |
for status in self.possible_status: |
|
426 |
waitpoint = False |
|
427 |
endpoint = True |
|
428 |
if status.forced_endpoint: |
|
429 |
endpoint = True |
|
430 |
else: |
|
431 |
for item in status.items: |
|
432 |
endpoint = item.endpoint and endpoint |
|
433 |
waitpoint = item.waitpoint or waitpoint |
|
434 |
if endpoint or waitpoint: |
|
435 |
waitpoint_status.append(status) |
|
436 |
return waitpoint_status |
|
424 |
return [x for x in self.possible_status if x.is_waitpoint()] |
|
437 | 425 | |
438 | 426 |
def get_endpoint_status(self): |
439 | 427 |
not_endpoint_status = self.get_not_endpoint_status() |
... | ... | |
1411 | 1399 |
return True |
1412 | 1400 |
return False |
1413 | 1401 | |
1402 |
def is_waitpoint(self): |
|
1403 |
waitpoint = False |
|
1404 |
endpoint = True |
|
1405 |
if self.forced_endpoint: |
|
1406 |
endpoint = True |
|
1407 |
else: |
|
1408 |
for item in self.items: |
|
1409 |
endpoint = item.endpoint and endpoint |
|
1410 |
waitpoint = item.waitpoint or waitpoint |
|
1411 |
return bool(endpoint or waitpoint) |
|
1412 | ||
1414 | 1413 |
def __getstate__(self): |
1415 | 1414 |
odict = self.__dict__.copy() |
1416 | 1415 |
if odict.has_key('parent'): |
... | ... | |
1634 | 1633 |
def get_substitution_variables(self, formdata): |
1635 | 1634 |
return {} |
1636 | 1635 | |
1637 |
def get_target_status(self): |
|
1636 |
def get_target_status(self, formdata=None):
|
|
1638 | 1637 |
"""Returns a list of status this item can lead to.""" |
1639 | 1638 |
if not getattr(self, 'status', None): |
1640 | 1639 |
return [] |
1641 | 1640 | |
1641 |
if self.status == '_previous': |
|
1642 |
if formdata is None: |
|
1643 |
# must be in a formdata to compute destination, just give a |
|
1644 |
# fake status for presentation purpose |
|
1645 |
return [WorkflowStatus(_('Previous Marked Status'))] |
|
1646 |
previous_status = formdata.get_previous_marked_status() |
|
1647 |
if previous_status: |
|
1648 |
return [previous_status] |
|
1649 |
return [] |
|
1650 | ||
1642 | 1651 |
try: |
1643 | 1652 |
return [x for x in self.parent.parent.possible_status if x.id == self.status] |
1644 | 1653 |
except IndexError: |
... | ... | |
1689 | 1698 |
def add_parameters_widgets(self, form, parameters, prefix='', formdef=None): |
1690 | 1699 |
if 'status' in parameters: |
1691 | 1700 |
form.add(SingleSelectWidget, '%sstatus' % prefix, title = _('Status'), value = self.status, |
1692 |
options = [(None, '---')] + [(x.id, x.name) for x in self.parent.parent.possible_status]) |
|
1701 |
options = [(None, '---')] + |
|
1702 |
[(x.id, x.name) for x in self.parent.parent.possible_status] + |
|
1703 |
[('_previous', _('Previous Marked Status'))]) |
|
1693 | 1704 | |
1694 | 1705 |
def get_parameters(self): |
1695 | 1706 |
return ('status',) |
... | ... | |
1867 | 1878 |
by = [] |
1868 | 1879 |
backoffice_info_text = None |
1869 | 1880 |
require_confirmation = False |
1881 |
set_marker_on_status = False |
|
1870 | 1882 | |
1871 | 1883 |
def render_as_line(self): |
1872 | 1884 |
if self.label: |
... | ... | |
1892 | 1904 | |
1893 | 1905 |
def submit_form(self, form, formdata, user, evo): |
1894 | 1906 |
if form.get_submit() == 'button%s' % self.id: |
1895 |
wf_status = self.get_target_status() |
|
1907 |
wf_status = self.get_target_status(formdata)
|
|
1896 | 1908 |
if wf_status: |
1897 | 1909 |
evo.status = 'wf-%s' % wf_status[0].id |
1910 |
if self.set_marker_on_status: |
|
1911 |
if formdata.workflow_data and 'markers_stack' in formdata.workflow_data: |
|
1912 |
markers_stack = formdata.workflow_data.get('markers_stack') |
|
1913 |
else: |
|
1914 |
markers_stack = [] |
|
1915 |
markers_stack.append(formdata.status) |
|
1916 |
formdata.update_workflow_data({'markers_stack': markers_stack}) |
|
1898 | 1917 |
form.clear_errors() |
1899 | 1918 |
return True # get out of processing loop |
1900 | 1919 | |
... | ... | |
1913 | 1932 |
form.add(CheckboxWidget, '%srequire_confirmation' % prefix, |
1914 | 1933 |
title=_('Require confirmation'), |
1915 | 1934 |
value=self.require_confirmation) |
1935 |
if 'set_marker_on_status' in parameters: |
|
1936 |
form.add(CheckboxWidget, '%smark_status' % prefix, |
|
1937 |
title=_('Set marker on status'), |
|
1938 |
value=self.set_marker_on_status) |
|
1916 | 1939 |
if 'backoffice_info_text' in parameters: |
1917 | 1940 |
form.add(WysiwygTextWidget, '%sbackoffice_info_text' % prefix, |
1918 | 1941 |
title=_('Information Text for Backoffice'), |
1919 | 1942 |
value=self.backoffice_info_text) |
1920 | 1943 | |
1921 | 1944 |
def get_parameters(self): |
1922 |
return ('by', 'status', 'label', 'backoffice_info_text', 'require_confirmation') |
|
1945 |
return ('by', 'status', 'label', 'backoffice_info_text', |
|
1946 |
'require_confirmation', 'set_marker_on_status') |
|
1923 | 1947 | |
1924 | 1948 |
register_item_class(ChoiceWorkflowStatusItem) |
1925 | 1949 | |
... | ... | |
1940 | 1964 | |
1941 | 1965 |
def submit_form(self, form, formdata, user, evo): |
1942 | 1966 |
if form.is_submitted() and not form.has_errors(): |
1943 |
wf_status = self.get_target_status() |
|
1967 |
wf_status = self.get_target_status(formdata)
|
|
1944 | 1968 |
if wf_status: |
1945 | 1969 |
evo.status = 'wf-%s' % wf_status[0].id |
1946 | 1970 | |
1947 |
- |