From 86733e846bd825163da00f57c2761d0b3fa0b32c Mon Sep 17 00:00:00 2001 From: Thomas NOEL Date: Mon, 23 Jan 2017 17:20:11 +0100 Subject: [PATCH] workflows: add redirect to url action (#11245) --- wcs/wf/redirect_to_url.py | 54 +++++++++++++++++++++++++++++++++++++++++++++++ wcs/workflows.py | 1 + 2 files changed, 55 insertions(+) create mode 100644 wcs/wf/redirect_to_url.py diff --git a/wcs/wf/redirect_to_url.py b/wcs/wf/redirect_to_url.py new file mode 100644 index 00000000..75053361 --- /dev/null +++ b/wcs/wf/redirect_to_url.py @@ -0,0 +1,54 @@ +# w.c.s. - web application for online forms +# Copyright (C) 2005-2017 Entr'ouvert +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, see . + +from qommon.form import ComputedExpressionWidget +from wcs.workflows import (WorkflowStatusItem, register_item_class) + + +class RedirectToUrlStatusItem(WorkflowStatusItem): + description = N_('Redirect to URL') + key = 'redirect_to_url' + endpoint = False + support_substitution_variables = True + + url = None + + def render_as_line(self): + if self.url: + return _('Redirect to URL "%s"') % self.url + else: + return _('Redirect to URL (not configured)') + + def get_parameters(self): + return ('url',) + + def add_parameters_widgets(self, form, parameters, prefix='', formdef=None): + if 'url' in parameters: + widget = form.add(ComputedExpressionWidget, '%surl' % prefix, + title=_('URL'), value=self.url, + hint=_('Common substitution variables are available with the [variable] syntax.')) + widget.extra_css_class = 'grid-1-1' + + def perform(self, formdata): + if not self.url: + # action not yet configured: don't redirect + return + url = self.compute(self.url) + if not self.url: + return # don't redirect + return url + +register_item_class(RedirectToUrlStatusItem) diff --git a/wcs/workflows.py b/wcs/workflows.py index b2d8a194..c9169aab 100644 --- a/wcs/workflows.py +++ b/wcs/workflows.py @@ -2388,5 +2388,6 @@ def load_extra(): import wf.criticality import wf.profile import wf.backoffice_fields + import wf.redirect_to_url from wf.export_to_model import ExportToModel -- 2.11.0