workflows: allow Django templates in OpenDocument image references (#55361)

This commit is contained in:
Benjamin Dauvergne 2021-06-24 21:18:31 +02:00
parent b806108f55
commit ac620ab867
3 changed files with 14 additions and 10 deletions

Binary file not shown.

View File

@ -3757,7 +3757,10 @@ def test_transform_to_pdf():
assert outstream.read(10).startswith(b'%PDF-')
def test_export_to_model_image(pub):
@pytest.mark.parametrize(
'template_name', ['template-with-image.odt', 'template-with-image-django-syntax.odt']
)
def test_export_to_model_image(pub, template_name):
formdef = FormDef()
formdef.name = 'baz'
formdef.fields = [
@ -3779,7 +3782,7 @@ def test_export_to_model_image(pub):
item = ExportToModel()
item.convert_to_pdf = False
item.method = 'non-interactive'
template_filename = os.path.join(os.path.dirname(__file__), 'template-with-image.odt')
template_filename = os.path.join(os.path.dirname(__file__), template_name)
with open(template_filename, 'rb') as fd:
template = fd.read()
upload = QuixoteUpload('/foo/template.odt', content_type='application/octet-stream')

View File

@ -587,17 +587,18 @@ class ExportToModel(WorkflowStatusItem):
if node.tag == DRAW_FRAME:
name = node.attrib.get(DRAW_NAME)
if not self.get_expression(name)['type'] == 'python':
continue
# variable image
try:
variable_image = self.compute(name)
except Exception:
continue
if not hasattr(variable_image, 'get_content'):
pub = get_publisher()
with pub.complex_data():
try:
variable_image = self.compute(name, allow_complex=True)
except Exception:
continue
complex_variable_image = get_publisher().get_cached_complex_data(variable_image)
if not hasattr(complex_variable_image, 'get_content'):
continue
image = [x for x in node if x.tag == DRAW_IMAGE][0]
new_images[image.attrib.get(XLINK_HREF)] = variable_image
new_images[image.attrib.get(XLINK_HREF)] = complex_variable_image
for attr in ('text', 'tail'):
if not getattr(node, attr):