wcs/wcs/wf/dispatch.py

61 lines
2.3 KiB
Python

# w.c.s. - web application for online forms
# Copyright (C) 2005-2013 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 <http://www.gnu.org/licenses/>.
from qommon.form import *
from wcs.roles import get_user_roles
from wcs.workflows import WorkflowStatusItem, register_item_class
class DispatchWorkflowStatusItem(WorkflowStatusItem):
description = N_('Assign a Function')
key = 'dispatch'
role_id = None
role_key = None
def get_parameters(self):
return ('role_key', 'role_id')
def role_id_export_to_xml(self, item, charset, include_id=False):
self._role_export_to_xml('role_id', item, charset,
include_id=include_id)
def role_id_init_with_xml(self, elem, charset, include_id=False):
self._role_init_with_xml('role_id', elem, charset,
include_id=include_id)
def add_parameters_widgets(self, form, parameters, prefix='', formdef=None):
if 'role_key' in parameters:
if not self.parent.parent.roles:
self.parent.parent.roles = {}
form.add(SingleSelectWidget, '%srole_key' % prefix,
title=_('Role to Set'), value=self.role_key,
options=[(None, '----')] + self.parent.parent.roles.items())
if 'role_id' in parameters:
form.add(SingleSelectWidget, '%srole_id' % prefix,
title=_('Value for role'), value=str(self.role_id),
options=[(None, '----')] + get_user_roles())
def perform(self, formdata):
if not (self.role_id and self.role_key):
return
if not formdata.workflow_roles:
formdata.workflow_roles = {}
formdata.workflow_roles[self.role_key] = str(self.role_id)
formdata.store()
register_item_class(DispatchWorkflowStatusItem)