|
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 RedirectToUrlStatusItem(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 self.url:
|
|
51 |
return # don't redirect
|
|
52 |
return url
|
|
53 |
|
|
54 |
register_item_class(RedirectToUrlStatusItem)
|