0001-workflows-add-redirect-to-url-action-11245.patch
tests/test_workflows.py | ||
---|---|---|
35 | 35 |
from wcs.wf.export_to_model import transform_to_pdf |
36 | 36 |
from wcs.wf.geolocate import GeolocateWorkflowStatusItem |
37 | 37 |
from wcs.wf.backoffice_fields import SetBackofficeFieldsWorkflowStatusItem |
38 |
from wcs.wf.redirect_to_url import RedirectToUrlWorkflowStatusItem |
|
38 | 39 | |
39 | 40 |
from utilities import (create_temporary_pub, MockSubstitutionVariables, emails, |
40 | 41 |
http_requests, clean_temporary_pub, sms_mocking) |
... | ... | |
2193 | 2194 |
formdata = formdef.data_class().get(formdata.id) |
2194 | 2195 |
assert formdata.data['bo1'] == ['a', 'b'] |
2195 | 2196 |
assert formdata.data['bo1_display'] == 'aa, bb' |
2197 | ||
2198 |
def test_redirect_to_url(pub): |
|
2199 |
formdef = FormDef() |
|
2200 |
formdef.name = 'baz' |
|
2201 |
formdef.fields = [ |
|
2202 |
StringField(id='1', label='Test', type='string', varname='foo'), |
|
2203 |
] |
|
2204 |
formdef.store() |
|
2205 | ||
2206 |
formdata = formdef.data_class()() |
|
2207 |
formdata.data = {'1': 'bar'} |
|
2208 | ||
2209 |
item = RedirectToUrlWorkflowStatusItem() |
|
2210 |
item.url = 'https://www.example.net/?foo=[form_var_foo]' |
|
2211 |
pub.substitutions.feed(formdata) |
|
2212 |
assert item.perform(formdata) == 'https://www.example.net/?foo=bar' |
|
2213 | ||
2214 |
item.url = '[if-any nada]https://www.example.net/[end]' |
|
2215 |
pub.substitutions.feed(formdata) |
|
2216 |
assert item.perform(formdata) == None |
wcs/wf/redirect_to_url.py | ||
---|---|---|
1 |
# w.c.s. - web application for online forms |
|
2 |
# Copyright (C) 2005-2017 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 qommon.form import ComputedExpressionWidget |
|
18 |
from wcs.workflows import (WorkflowStatusItem, register_item_class) |
|
19 | ||
20 | ||
21 |
class RedirectToUrlWorkflowStatusItem(WorkflowStatusItem): |
|
22 |
description = N_('Redirect to URL') |
|
23 |
key = 'redirect_to_url' |
|
24 |
endpoint = False |
|
25 |
support_substitution_variables = True |
|
26 | ||
27 |
url = None |
|
28 | ||
29 |
def render_as_line(self): |
|
30 |
if self.url: |
|
31 |
return _('Redirect to URL "%s"') % self.url |
|
32 |
else: |
|
33 |
return _('Redirect to URL (not configured)') |
|
34 | ||
35 |
def get_parameters(self): |
|
36 |
return ('url',) |
|
37 | ||
38 |
def add_parameters_widgets(self, form, parameters, prefix='', formdef=None): |
|
39 |
if 'url' in parameters: |
|
40 |
widget = form.add(ComputedExpressionWidget, '%surl' % prefix, |
|
41 |
title=_('URL'), value=self.url, |
|
42 |
hint=_('Common substitution variables are available with the [variable] syntax.')) |
|
43 |
widget.extra_css_class = 'grid-1-1' |
|
44 | ||
45 |
def perform(self, formdata): |
|
46 |
if not self.url: |
|
47 |
# action not yet configured: don't redirect |
|
48 |
return |
|
49 |
url = self.compute(self.url) |
|
50 |
if not url: |
|
51 |
return # don't redirect |
|
52 |
return url |
|
53 | ||
54 |
register_item_class(RedirectToUrlWorkflowStatusItem) |
wcs/workflows.py | ||
---|---|---|
2388 | 2388 |
import wf.criticality |
2389 | 2389 |
import wf.profile |
2390 | 2390 |
import wf.backoffice_fields |
2391 |
import wf.redirect_to_url |
|
2391 | 2392 | |
2392 | 2393 |
from wf.export_to_model import ExportToModel |
2393 |
- |