0001-wf-add-remove-tracking-code-action-59033.patch
tests/admin_pages/test_workflow.py | ||
---|---|---|
27 | 27 |
from wcs.wf.jump import JumpWorkflowStatusItem |
28 | 28 |
from wcs.wf.redirect_to_url import RedirectToUrlWorkflowStatusItem |
29 | 29 |
from wcs.wf.register_comment import RegisterCommenterWorkflowStatusItem |
30 |
from wcs.wf.remove_tracking_code import RemoveTrackingCodeWorkflowStatusItem |
|
30 | 31 |
from wcs.wf.roles import AddRoleWorkflowStatusItem, RemoveRoleWorkflowStatusItem |
31 | 32 |
from wcs.wf.wscall import WebserviceCallStatusItem |
32 | 33 |
from wcs.workflows import ( |
... | ... | |
3519 | 3520 |
wf2 = Workflow.get(2) |
3520 | 3521 |
assert wf2.possible_status[0].id == 'baz' |
3521 | 3522 |
assert wf2.backoffice_fields_formdef.fields[0].id == 'bo1-1x' |
3523 | ||
3524 | ||
3525 |
def test_remove_tracking_code_details(pub): |
|
3526 |
create_superuser(pub) |
|
3527 | ||
3528 |
Workflow.wipe() |
|
3529 |
workflow = Workflow(name='foo') |
|
3530 |
baz_status = workflow.add_status(name='baz') |
|
3531 |
remove_code = RemoveTrackingCodeWorkflowStatusItem() |
|
3532 |
remove_code.parent = baz_status |
|
3533 |
baz_status.items.append(remove_code) |
|
3534 |
workflow.store() |
|
3535 | ||
3536 |
app = login(get_app(pub)) |
|
3537 |
resp = app.get('/backoffice/workflows/%s/status/%s/' % (workflow.id, baz_status.id)) |
|
3538 |
assert 'Remove Tracking Code' in resp.text |
|
3539 |
assert 'Remove Tracking Code (' not in resp.text |
|
3540 | ||
3541 |
remove_code.replace = True |
|
3542 |
workflow.store() |
|
3543 |
resp = app.get('/backoffice/workflows/%s/status/%s/' % (workflow.id, baz_status.id)) |
|
3544 |
assert 'Remove Tracking Code (replace with a new one)' in resp.text |
tests/workflow/test_all.py | ||
---|---|---|
70 | 70 |
from wcs.wf.redirect_to_url import RedirectToUrlWorkflowStatusItem |
71 | 71 |
from wcs.wf.register_comment import JournalEvolutionPart, RegisterCommenterWorkflowStatusItem |
72 | 72 |
from wcs.wf.remove import RemoveWorkflowStatusItem |
73 |
from wcs.wf.remove_tracking_code import RemoveTrackingCodeWorkflowStatusItem |
|
73 | 74 |
from wcs.wf.roles import AddRoleWorkflowStatusItem, RemoveRoleWorkflowStatusItem |
74 | 75 |
from wcs.wf.timeout_jump import TimeoutWorkflowStatusItem |
75 | 76 |
from wcs.wf.wscall import WebserviceCallStatusItem |
... | ... | |
6852 | 6853 |
formdata.refresh_from_storage() |
6853 | 6854 |
assert formdata.evolution[0].parts[-1].actions[0][1:] == ('register-comment', str(comment.id)) |
6854 | 6855 |
assert formdata.evolution[0].parts[-1].actions[1][1:] == ('jump', str(jump2.id)) |
6856 | ||
6857 | ||
6858 |
def test_remove_tracking_code(two_pubs): |
|
6859 |
formdef = FormDef() |
|
6860 |
formdef.name = 'baz' |
|
6861 |
formdef.enable_tracking_codes = True |
|
6862 |
formdef.store() |
|
6863 | ||
6864 |
formdef.data_class().wipe() |
|
6865 |
formdata = formdef.data_class()() |
|
6866 |
formdata.store() |
|
6867 |
code = get_publisher().tracking_code_class() |
|
6868 |
code.formdata = formdata |
|
6869 |
formdata.refresh_from_storage() |
|
6870 | ||
6871 |
assert formdata.tracking_code |
|
6872 |
assert get_publisher().tracking_code_class().count() == 1 |
|
6873 | ||
6874 |
item = RemoveTrackingCodeWorkflowStatusItem() |
|
6875 |
item.perform(formdata) |
|
6876 |
assert not formdata.tracking_code |
|
6877 |
assert get_publisher().tracking_code_class().count() == 0 |
|
6878 |
item.perform(formdata) # do not crash if no tracking_code |
|
6879 | ||
6880 |
item.replace = True |
|
6881 |
item.perform(formdata) |
|
6882 |
assert formdata.tracking_code |
|
6883 |
assert get_publisher().tracking_code_class().count() == 1 |
|
6884 |
tracking_code_orig = formdata.tracking_code |
|
6885 |
item.perform(formdata) |
|
6886 |
assert formdata.tracking_code |
|
6887 |
assert formdata.tracking_code != tracking_code_orig |
|
6888 |
assert get_publisher().tracking_code_class().count() == 1 |
|
6889 | ||
6890 |
# cannot replace if formdef not handles tracking code |
|
6891 |
formdef.enable_tracking_codes = False |
|
6892 |
formdef.store() |
|
6893 |
item.perform(formdata) |
|
6894 |
assert not formdata.tracking_code |
|
6895 |
assert get_publisher().tracking_code_class().count() == 0 |
wcs/wf/remove_tracking_code.py | ||
---|---|---|
1 |
# w.c.s. - web application for online forms |
|
2 |
# Copyright (C) 2005-2022 Entr'ouvert |
|
3 |
# |
|
4 |
# This program is free software; you can redistribute it and/or modify |
|
5 |
# it under the terms of the GNU General Public License as published by |
|
6 |
# the Free Software Foundation; either version 2 of the License, or |
|
7 |
# (at your option) any later version. |
|
8 |
# |
|
9 |
# This program is distributed in the hope that it will be useful, |
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 |
# GNU General Public License for more details. |
|
13 |
# |
|
14 |
# You should have received a copy of the GNU General Public License |
|
15 |
# along with this program; if not, see <http://www.gnu.org/licenses/>. |
|
16 | ||
17 |
from quixote import get_publisher |
|
18 | ||
19 |
from wcs.qommon import _ |
|
20 |
from wcs.qommon.form import CheckboxWidget |
|
21 |
from wcs.workflows import WorkflowStatusItem, register_item_class |
|
22 | ||
23 | ||
24 |
class RemoveTrackingCodeWorkflowStatusItem(WorkflowStatusItem): |
|
25 |
description = _('Remove Tracking Code') |
|
26 |
key = 'remove_tracking_code' |
|
27 |
category = 'formdata-action' |
|
28 | ||
29 |
replace = False |
|
30 | ||
31 |
def add_parameters_widgets(self, form, parameters, prefix='', formdef=None, **kwargs): |
|
32 |
super().add_parameters_widgets(form, parameters, prefix=prefix, formdef=formdef, **kwargs) |
|
33 |
if 'replace' in parameters: |
|
34 |
form.add( |
|
35 |
CheckboxWidget, |
|
36 |
'%sreplace' % prefix, |
|
37 |
title=_('Replace with a new tracking code'), |
|
38 |
value=self.replace, |
|
39 |
hint=_('This only works if form supports tracking codes.'), |
|
40 |
) |
|
41 | ||
42 |
def get_line_details(self): |
|
43 |
if self.replace: |
|
44 |
return _('replace with a new one') |
|
45 | ||
46 |
def get_parameters(self): |
|
47 |
return ('replace', 'condition') |
|
48 | ||
49 |
def perform(self, formdata): |
|
50 |
if formdata.tracking_code: |
|
51 |
get_publisher().tracking_code_class.remove_object(formdata.tracking_code) |
|
52 |
if self.replace and formdata.formdef.enable_tracking_codes: |
|
53 |
code = get_publisher().tracking_code_class() |
|
54 |
code.formdata = formdata # this will .store() code and formdata |
|
55 |
else: |
|
56 |
formdata.tracking_code = None |
|
57 |
formdata.store() |
|
58 | ||
59 | ||
60 |
register_item_class(RemoveTrackingCodeWorkflowStatusItem) |
wcs/workflows.py | ||
---|---|---|
3453 | 3453 |
from .wf import redirect_to_url # noqa pylint: disable=unused-import |
3454 | 3454 |
from .wf import register_comment # noqa pylint: disable=unused-import |
3455 | 3455 |
from .wf import remove # noqa pylint: disable=unused-import |
3456 |
from .wf import remove_tracking_code # noqa pylint: disable=unused-import |
|
3456 | 3457 |
from .wf import resubmit # noqa pylint: disable=unused-import |
3457 | 3458 |
from .wf import roles # noqa pylint: disable=unused-import |
3458 | 3459 |
from .wf import sendmail # noqa pylint: disable=unused-import |
3459 |
- |