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 | ||
3195 |
# check markers are displayed in /inspect page |
|
3196 |
user.is_admin = True |
|
3197 |
user.store() |
|
3198 |
resp2 = app.get('/backoffice/management/form-title/%s/inspect' % formdata.id) |
|
3199 |
assert 'Markers Stack' in resp2.body |
|
3200 |
assert '<span class="status">East</span>' in resp2.body |
|
3201 |
assert '<span class="status">West</span>' in resp2.body |
|
3202 |
assert '<span class="status">North</span>' in resp2.body |
|
3203 |
assert resp2.body.find('<span class="status">East</span>') < resp2.body.find('<span class="status">West</span>') |
|
3204 |
assert resp2.body.find('<span class="status">West</span>') < resp2.body.find('<span class="status">North</span>') |
|
3205 | ||
3206 |
resp = resp.form.submit(button_by_id['Go Back']).follow() # pop (north, west) |
|
3207 |
assert formdef.data_class().get(formdata.id).status == 'wf-%s' % st3.id |
|
3208 | ||
3209 |
# and do a last jump using the API |
|
3210 |
formdata = formdef.data_class().get(formdata.id) |
|
3211 |
formdata.jump_status('_previous') # pop (north) |
|
3212 |
assert formdata.status == 'wf-%s' % st2.id |
|
3213 | ||
3214 |
formdata = formdef.data_class().get(formdata.id) |
|
3215 |
formdata.jump_status('_previous') # pop () |
|
3216 |
assert formdata.status == 'wf-%s' % st1.id |
|
3217 | ||
3108 | 3218 |
def test_backoffice_fields(pub): |
3109 | 3219 |
user = create_user(pub) |
3110 | 3220 |
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/backoffice/management.py | ||
---|---|---|
2085 | 2085 |
if not isinstance(v, basestring): |
2086 | 2086 |
r += htmltext(' <span class="type">(%r)</span>') % type(v) |
2087 | 2087 |
r += htmltext('</div></li>') |
2088 | ||
2089 |
if '_markers_stack' in (self.filled.workflow_data or {}): |
|
2090 |
r += htmltext('<li><h3>%s</h3></li>') % _('Markers Stack') |
|
2091 |
for marker in reversed(self.filled.workflow_data['_markers_stack']): |
|
2092 |
status = self.filled.get_status(marker['status_id']) |
|
2093 |
if status: |
|
2094 |
r += htmltext('<li><span class="status">%s</span></li>') % status.name |
|
2095 |
else: |
|
2096 |
r += htmltext('<li><span class="status">%s</span></li>') % _('Unknown') |
|
2097 | ||
2088 | 2098 |
r += htmltext('</ul>') |
2089 | 2099 |
r += htmltext('</div>') |
2090 | ||
2091 | 2100 |
return r.getvalue() |
2092 | 2101 | |
2093 | 2102 |
wcs/formdata.py | ||
---|---|---|
404 | 404 |
return None |
405 | 405 |
if not self.formdef: |
406 | 406 |
return None |
407 |
if status.startswith('wf-'): |
|
408 |
status = status[3:] |
|
407 | 409 |
try: |
408 |
status_id = status.split('-')[1] |
|
409 |
wf_status = [x for x in self.formdef.workflow.possible_status if x.id == status_id][0] |
|
410 |
wf_status = [x for x in self.formdef.workflow.possible_status if x.id == status][0] |
|
410 | 411 |
except IndexError: |
411 | 412 |
return None |
412 | 413 |
return wf_status |
... | ... | |
453 | 454 |
return None |
454 | 455 |
return wf_status.handle_form(form, self, user) |
455 | 456 | |
457 |
def get_previous_marked_status(self): |
|
458 |
if not self.workflow_data or not '_markers_stack' in self.workflow_data: |
|
459 |
return None |
|
460 |
try: |
|
461 |
marker_data = self.workflow_data['_markers_stack'].pop() |
|
462 |
status_id = marker_data['status_id'] |
|
463 |
except IndexError: |
|
464 |
return None |
|
465 |
return self.formdef.workflow.get_status(status_id) |
|
466 | ||
456 | 467 |
def jump_status(self, status_id): |
468 |
if status_id == '_previous': |
|
469 |
previous_status = self.get_previous_marked_status() |
|
470 |
assert previous_status, 'failed to compute previous status' |
|
471 |
status_id = previous_status.id |
|
457 | 472 |
evo = Evolution() |
458 | 473 |
evo.time = time.localtime() |
459 | 474 |
evo.status = 'wf-%s' % status_id |
... | ... | |
632 | 647 | |
633 | 648 |
if self.workflow_data: |
634 | 649 |
d.update(self.workflow_data) |
635 |
# pass over uploaded files and attach an extra attribute with the |
|
636 |
# url to the file. |
|
650 |
# pass over workflow data to: |
|
651 |
# - attach an extra url attribute to uploaded files |
|
652 |
# - remove "private" attributes |
|
637 | 653 |
for k, v in self.workflow_data.items(): |
654 |
if k[0] == '_': |
|
655 |
del d[k] |
|
656 |
continue |
|
638 | 657 |
if isinstance(v, Upload): |
639 | 658 |
try: |
640 | 659 |
formvar, fieldvar = re.match('(.*)_var_(.*)_raw$', k).groups() |
wcs/qommon/static/css/dc2/admin.css | ||
---|---|---|
1525 | 1525 |
font-size: 100%; |
1526 | 1526 |
} |
1527 | 1527 | |
1528 |
ul.form-inspector li span.status { |
|
1529 |
padding: 0 1ex; |
|
1530 |
} |
|
1531 | ||
1528 | 1532 |
ul.form-inspector li div.value { |
1529 | 1533 |
display: block; |
1530 | 1534 |
padding: 0 0 0.5ex 1em; |
wcs/wf/jump.py | ||
---|---|---|
145 | 145 |
return _('Change Status Automatically (to %s)') % wf_status[0].name |
146 | 146 | |
147 | 147 |
def get_parameters(self): |
148 |
return ('status', 'condition', 'trigger', 'by', 'timeout') |
|
148 |
return ('status', 'set_marker_on_status', 'condition', 'trigger', 'by', 'timeout')
|
|
149 | 149 | |
150 | 150 |
def add_parameters_widgets(self, form, parameters, prefix='', formdef=None): |
151 | 151 |
WorkflowStatusJumpItem.add_parameters_widgets(self, form, parameters, prefix, formdef) |
... | ... | |
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 | ||
---|---|---|
1633 | 1633 |
def get_substitution_variables(self, formdata): |
1634 | 1634 |
return {} |
1635 | 1635 | |
1636 |
def get_target_status(self): |
|
1636 |
def get_target_status(self, formdata=None):
|
|
1637 | 1637 |
"""Returns a list of status this item can lead to.""" |
1638 | 1638 |
if not getattr(self, 'status', None): |
1639 | 1639 |
return [] |
1640 | 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(_('Previously Marked Status'))] |
|
1646 |
previous_status = formdata.get_previous_marked_status() |
|
1647 |
if previous_status: |
|
1648 |
return [previous_status] |
|
1649 |
return [] |
|
1650 | ||
1641 | 1651 |
try: |
1642 | 1652 |
return [x for x in self.parent.parent.possible_status if x.id == self.status] |
1643 | 1653 |
except IndexError: |
... | ... | |
1684 | 1694 |
class WorkflowStatusJumpItem(WorkflowStatusItem): |
1685 | 1695 |
status = None |
1686 | 1696 |
endpoint = False |
1697 |
set_marker_on_status = False |
|
1687 | 1698 | |
1688 | 1699 |
def add_parameters_widgets(self, form, parameters, prefix='', formdef=None): |
1689 | 1700 |
if 'status' in parameters: |
1690 | 1701 |
form.add(SingleSelectWidget, '%sstatus' % prefix, title = _('Status'), value = self.status, |
1691 |
options = [(None, '---')] + [(x.id, x.name) for x in self.parent.parent.possible_status]) |
|
1702 |
options = [(None, '---')] + |
|
1703 |
[(x.id, x.name) for x in self.parent.parent.possible_status] + |
|
1704 |
[('_previous', _('Previously Marked Status'))]) |
|
1705 |
if 'set_marker_on_status' in parameters: |
|
1706 |
form.add(CheckboxWidget, '%sset_marker_on_status' % prefix, |
|
1707 |
title=_('Set marker on status'), |
|
1708 |
value=self.set_marker_on_status) |
|
1692 | 1709 | |
1693 | 1710 |
def get_parameters(self): |
1694 |
return ('status',) |
|
1711 |
return ('status', 'set_marker_on_status')
|
|
1695 | 1712 | |
1696 | 1713 | |
1697 | 1714 |
def get_role_translation(formdata, role_name): |
... | ... | |
1891 | 1908 | |
1892 | 1909 |
def submit_form(self, form, formdata, user, evo): |
1893 | 1910 |
if form.get_submit() == 'button%s' % self.id: |
1894 |
wf_status = self.get_target_status() |
|
1911 |
wf_status = self.get_target_status(formdata)
|
|
1895 | 1912 |
if wf_status: |
1896 | 1913 |
evo.status = 'wf-%s' % wf_status[0].id |
1914 |
if self.set_marker_on_status: |
|
1915 |
if formdata.workflow_data and '_markers_stack' in formdata.workflow_data: |
|
1916 |
markers_stack = formdata.workflow_data.get('_markers_stack') |
|
1917 |
else: |
|
1918 |
markers_stack = [] |
|
1919 |
markers_stack.append({'status_id': formdata.status[3:]}) |
|
1920 |
formdata.update_workflow_data({'_markers_stack': markers_stack}) |
|
1897 | 1921 |
form.clear_errors() |
1898 | 1922 |
return True # get out of processing loop |
1899 | 1923 | |
... | ... | |
1918 | 1942 |
value=self.backoffice_info_text) |
1919 | 1943 | |
1920 | 1944 |
def get_parameters(self): |
1921 |
return ('by', 'status', 'label', 'backoffice_info_text', 'require_confirmation') |
|
1945 |
return ('by', 'status', 'label', 'backoffice_info_text', |
|
1946 |
'require_confirmation', 'set_marker_on_status') |
|
1922 | 1947 | |
1923 | 1948 |
register_item_class(ChoiceWorkflowStatusItem) |
1924 | 1949 | |
... | ... | |
1939 | 1964 | |
1940 | 1965 |
def submit_form(self, form, formdata, user, evo): |
1941 | 1966 |
if form.is_submitted() and not form.has_errors(): |
1942 |
wf_status = self.get_target_status() |
|
1967 |
wf_status = self.get_target_status(formdata)
|
|
1943 | 1968 |
if wf_status: |
1944 | 1969 |
evo.status = 'wf-%s' % wf_status[0].id |
1945 | 1970 | |
1946 | 1971 |
def get_parameters(self): |
1947 |
return ('status',) |
|
1972 |
return ('status', 'set_marker_on_status')
|
|
1948 | 1973 |
register_item_class(JumpOnSubmitWorkflowStatusItem) |
1949 | 1974 | |
1950 | 1975 | |
1951 |
- |