wcs/wcs/wf/edit_carddata.py

62 lines
2.2 KiB
Python

# w.c.s. - web application for online forms
# Copyright (C) 2005-2020 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 quixote import get_publisher
from wcs.qommon import N_, _
from wcs.wf.create_carddata import CreateCarddataWorkflowStatusItem
from wcs.wf.external_workflow import ExternalWorkflowGlobalAction
from wcs.workflows import register_item_class
class EditCarddataWorkflowStatusItem(CreateCarddataWorkflowStatusItem, ExternalWorkflowGlobalAction):
description = _('Edit Card Data')
key = 'edit_carddata'
mappings_label = _('Mappings to card fields')
accept_empty_value = True
automatic_targetting = N_('Action on linked cards')
manual_targetting = N_('Specify the identifier of the card on which the action will be applied')
@classmethod
def is_available(cls, workflow=None):
return ExternalWorkflowGlobalAction.is_available()
def get_parameters(self):
return ('formdef_slug', 'target_mode', 'target_id', 'mappings', 'condition')
@property
def slug(self):
# act only on linked carddefs
return 'carddef:%s' % self.formdef_slug
def perform(self, formdata):
carddef = self.formdef
if not carddef:
return
formdata.store()
for target_data in self.iter_target_datas(formdata, carddef):
self.apply_mappings(dest=target_data, src=formdata)
with get_publisher().substitutions.freeze():
target_data.store()
# update local object as it may have modified itself
formdata.refresh_from_storage()
register_item_class(EditCarddataWorkflowStatusItem)