misc: add export/import support for date formdef options (#34951e
This commit is contained in:
parent
69a12b7ec7
commit
e63b627403
|
@ -215,6 +215,14 @@ def test_workflow_options_with_file():
|
|||
assert formdef.workflow_options['foo'].filename == fd2.workflow_options['foo'].filename
|
||||
assert formdef.workflow_options['foo'].get_content() == fd2.workflow_options['foo'].get_content()
|
||||
|
||||
def test_workflow_options_with_date():
|
||||
formdef = FormDef()
|
||||
formdef.name = 'foo'
|
||||
formdef.workflow_options = {'foo': time.strptime('2014-02-02', '%Y-%m-%d')}
|
||||
fd2 = assert_xml_import_export_works(formdef)
|
||||
assert formdef.workflow_options['foo'] == fd2.workflow_options['foo']
|
||||
|
||||
|
||||
def test_workflow_reference():
|
||||
Workflow.wipe()
|
||||
FormDef.wipe()
|
||||
|
|
|
@ -937,6 +937,9 @@ class FormDef(StorableObject):
|
|||
ET.SubElement(element, 'content_type').text = (
|
||||
option_value.content_type or 'application/octet-stream')
|
||||
ET.SubElement(element, 'content').text = base64.b64encode(option_value.get_content())
|
||||
elif isinstance(option_value, time.struct_time):
|
||||
element.text = time.strftime('%Y-%m-%d', option_value)
|
||||
element.attrib['type'] = 'date'
|
||||
else:
|
||||
pass # TODO: extend support to other types
|
||||
|
||||
|
@ -1051,7 +1054,9 @@ class FormDef(StorableObject):
|
|||
formdef.workflow_options = {}
|
||||
for option in tree.findall('options/option'):
|
||||
option_value = None
|
||||
if option.text:
|
||||
if option.attrib.get('type') == 'date':
|
||||
option_value = time.strptime(option.text, '%Y-%m-%d')
|
||||
elif option.text:
|
||||
option_value = option.text.encode(charset)
|
||||
elif option.findall('filename'):
|
||||
filename = option.find('filename').text
|
||||
|
|
Loading…
Reference in New Issue