workflows: add export/import for new attachment action attributes (#47181)

This commit is contained in:
Frédéric Péters 2020-09-30 13:43:46 +02:00
parent 75928eba53
commit f416e9ede1
2 changed files with 45 additions and 1 deletions

View File

@ -12,6 +12,7 @@ from wcs.workflows import (
WorkflowBackofficeFieldsFormDef, SendmailWorkflowStatusItem,
SendSMSWorkflowStatusItem, WorkflowImportError, ChoiceWorkflowStatusItem,
JumpOnSubmitWorkflowStatusItem)
from wcs.wf.attachment import AddAttachmentWorkflowStatusItem
from wcs.wf.wscall import WebserviceCallStatusItem
from wcs.wf.dispatch import DispatchWorkflowStatusItem
from wcs.wf.register_comment import RegisterCommenterWorkflowStatusItem
@ -669,6 +670,29 @@ def test_profile_action(pub):
assert item2.fields == [{'field_id': '__email', 'value': '=form_var_foo'}]
def test_attachment_action(pub):
wf = Workflow(name='status')
st1 = wf.add_status('Status1', 'st1')
item = AddAttachmentWorkflowStatusItem()
item.id = '_foo'
item.document_type = {
'id': '_audio',
'label': 'Sound files',
'mimetypes': ['audio/*'],
}
st1.items.append(item)
item.parent = st1
wf2 = assert_import_export_works(wf)
item2 = wf2.possible_status[0].items[0]
assert item2.document_type == {
'id': '_audio',
'label': 'Sound files',
'mimetypes': ['audio/*'],
}
def test_set_backoffice_fields_action(pub):
wf = Workflow(name='status')
st1 = wf.add_status('Status1', 'st1')

View File

@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>.
import xml.etree.ElementTree as ET
from django.utils.six.moves.urllib import parse as urllib
from quixote import redirect
@ -22,7 +23,7 @@ from ..qommon import _, N_
from wcs.workflows import *
from ..qommon import get_cfg
from ..qommon.errors import *
from ..qommon.misc import get_document_type_value_options
from ..qommon.misc import get_document_type_value_options, xml_node_text
from wcs.forms.common import FormStatusPage, FileDirectory
from wcs.portfolio import has_portfolio, push_document
@ -212,6 +213,25 @@ class AddAttachmentWorkflowStatusItem(WorkflowStatusItem):
value=self.max_file_size,
advanced=not(self.max_file_size))
def document_type_export_to_xml(self, xml_item, charset, include_id=False):
if not self.document_type:
return
node = ET.SubElement(xml_item, 'document_type')
ET.SubElement(node, 'id').text = str(self.document_type['id'])
ET.SubElement(node, 'label').text = str(self.document_type['label'])
for mimetype in self.document_type.get('mimetypes') or []:
ET.SubElement(node, 'mimetype').text = mimetype
return node
def document_type_init_with_xml(self, node, charset, include_id=False):
self.document_type = {}
if node is None:
return
self.document_type['id'] = xml_node_text(node.find('id'))
self.document_type['label'] = xml_node_text(node.find('label'))
self.document_type['mimetypes'] = []
for mimetype_node in (node.findall('mimetype') or []):
self.document_type['mimetypes'].append(xml_node_text(mimetype_node))
register_item_class(AddAttachmentWorkflowStatusItem)