misc: make workflow file options importable (#58170) #594
|
@ -259,10 +259,10 @@ def test_workflow_options_with_file(pub):
|
|||
formdef.name = 'foo'
|
||||
formdef.workflow_options = {'foo': model_file}
|
||||
fd2 = assert_xml_import_export_works(formdef)
|
||||
assert formdef.workflow_options['foo'].filename == fd2.workflow_options['foo'].filename
|
||||
assert formdef.workflow_options['foo'].base_filename == fd2.workflow_options['foo'].base_filename
|
||||
assert formdef.workflow_options['foo'].get_content() == fd2.workflow_options['foo'].get_content()
|
||||
fd2 = assert_json_import_export_works(formdef)
|
||||
assert formdef.workflow_options['foo'].filename == fd2.workflow_options['foo'].filename
|
||||
assert formdef.workflow_options['foo'].base_filename == fd2.workflow_options['foo'].base_filename
|
||||
assert formdef.workflow_options['foo'].get_content() == fd2.workflow_options['foo'].get_content()
|
||||
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ from operator import itemgetter
|
|||
from django.utils.encoding import force_bytes, force_str
|
||||
from quixote import get_publisher, get_session
|
||||
from quixote.html import TemplateIO, htmltext
|
||||
from quixote.http_request import Upload
|
||||
|
||||
from . import data_sources, fields
|
||||
from .categories import Category
|
||||
|
@ -43,12 +42,13 @@ from .qommon.admin.emails import EmailsDirectory
|
|||
from .qommon.afterjobs import AfterJob
|
||||
from .qommon.cron import CronJob
|
||||
from .qommon.errors import UnknownReferencedErrorMixin
|
||||
from .qommon.form import Form, HtmlWidget, UploadedFile
|
||||
from .qommon.form import Form, HtmlWidget
|
||||
from .qommon.misc import JSONEncoder, get_as_datetime, is_attachment, is_upload, simplify, xml_node_text
|
||||
from .qommon.publisher import get_publisher_class
|
||||
from .qommon.storage import Equal, StorableObject, classonlymethod, fix_key
|
||||
from .qommon.substitution import Substitutions
|
||||
from .qommon.template import Template
|
||||
from .qommon.upload_storage import PicklableUpload
|
||||
from .roles import logged_users_role
|
||||
|
||||
DRAFTS_DEFAULT_LIFESPAN = 100 # days
|
||||
|
@ -1183,10 +1183,11 @@ class FormDef(StorableObject):
|
|||
formdef.workflow_options = value.get('options')
|
||||
for option_key, option_value in formdef.workflow_options.items():
|
||||
if isinstance(option_value, dict) and 'filename' in option_value:
|
||||
filename = option_value['filename']
|
||||
upload = Upload(filename, content_type=option_value['content_type'])
|
||||
new_value = UploadedFile(get_publisher().app_dir, filename, upload)
|
||||
new_value.set_content(base64.decodebytes(force_bytes(option_value['content'])))
|
||||
new_value = PicklableUpload(
|
||||
orig_filename=option_value['filename'],
|
||||
content_type=option_value['content_type'],
|
||||
)
|
||||
new_value.receive([base64.decodebytes(force_bytes(option_value['content']))])
|
||||
formdef.workflow_options[option_key] = new_value
|
||||
|
||||
if value.get('geolocations'):
|
||||
|
@ -1283,6 +1284,7 @@ class FormDef(StorableObject):
|
|||
if isinstance(option_value, str):
|
||||
element.text = force_str(self.workflow_options.get(option, ''), charset)
|
||||
elif hasattr(option_value, 'base_filename'):
|
||||
element.attrib['type'] = 'file'
|
||||
ET.SubElement(element, 'filename').text = option_value.base_filename
|
||||
ET.SubElement(element, 'content_type').text = (
|
||||
option_value.content_type or 'application/octet-stream'
|
||||
|
@ -1438,13 +1440,14 @@ class FormDef(StorableObject):
|
|||
option_value = time.strptime(option.text, '%Y-%m-%d')
|
||||
elif option.attrib.get('type') == 'bool':
|
||||
option_value = bool(option.text == 'true')
|
||||
elif option.attrib.get('type') == 'file' or option.findall('filename'):
|
||||
option_value = PicklableUpload(
|
||||
orig_filename=xml_node_text(option.find('filename')),
|
||||
content_type=xml_node_text(option.find('content_type')),
|
||||
)
|
||||
option_value.receive([base64.decodebytes(force_bytes(xml_node_text(option.find('content'))))])
|
||||
elif option.text:
|
||||
option_value = xml_node_text(option)
|
||||
elif option.findall('filename'):
|
||||
filename = xml_node_text(option.find('filename'))
|
||||
upload = Upload(filename, content_type=xml_node_text(option.find('content_type')))
|
||||
option_value = UploadedFile(get_publisher().app_dir, filename, upload)
|
||||
option_value.set_content(base64.decodebytes(force_bytes(option.find('content').text)))
|
||||
formdef.workflow_options[option.attrib.get('varname')] = option_value
|
||||
|
||||
formdef._custom_views = []
|
||||
|
|
Loading…
Reference in New Issue