From 2eb98e0a72d4de5925207fa219b28d01423ade4e 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 | 55 +++++++++++++++++++++++++++++++++++++++++++++++ wcs/workflows.py | 1 + 2 files changed, 56 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..faebaae5 --- /dev/null +++ b/wcs/wf/redirect_to_url.py @@ -0,0 +1,55 @@ +# 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 * +from wcs.workflows import (WorkflowStatusItem, register_item_class) + + +class RedirectToUrlStatusItem(WorkflowStatusItem): + description = N_('Redirect to URL') + key = 'redirect_to_url' + endpoint = False + waitpoint = True + ok_in_global_action = False + + url = None + + def render_as_line(self): + if self.url: + return _('Redirect to "%s"') % self.url + else: + return _('Redirect to (not configured)') + + def get_parameters(self): + return ('url',) + + def add_parameters_widgets(self, form, parameters, prefix='', formdef=None): + if 'url' in parameters: + form.add(StringWidget, '%surl' % prefix, + title=_('URL'), value=self.url, size=100, + hint=_('Common substitution variables are available with the [variable] syntax.')) + + def perform(self, formdata): + if not self.url: + # misconfigured action + return + url = self.compute(self.url) + if not self.url: + # misconfigured action + return + 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