From 76a774d38eb1fb97f210d47f9c40b29772c62d2f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Tue, 19 Jul 2022 09:43:14 +0200 Subject: [PATCH] workflows: fix attachment of files with no varnames (#67463) --- tests/workflow/test_email.py | 11 +++++++++++ wcs/variables.py | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/workflow/test_email.py b/tests/workflow/test_email.py index 6c591d5ba..6e0768589 100644 --- a/tests/workflow/test_email.py +++ b/tests/workflow/test_email.py @@ -368,6 +368,17 @@ def test_email_attachments(pub, emails): assert emails.emails['foobar']['msg'].get_payload()[0].get_content_type() == 'text/html' assert emails.emails['foobar']['msg'].get_payload()[1].get_content_type() == 'image/jpeg' + # check with template with varname-less field + emails.empty() + sendmail.attachments = ['{{form_fbo1_1x}}'] + sendmail.perform(formdata) + get_response().process_after_jobs() + assert emails.count() == 1 + assert emails.emails['foobar']['msg'].is_multipart() + assert emails.emails['foobar']['msg'].get_content_subtype() == 'mixed' + assert emails.emails['foobar']['msg'].get_payload()[0].get_content_type() == 'text/html' + assert emails.emails['foobar']['msg'].get_payload()[1].get_content_type() == 'image/jpeg' + # check with variable emails.empty() sendmail.attachments = ['form_var_backoffice_file1_raw'] diff --git a/wcs/variables.py b/wcs/variables.py index 6b9c1a479..75360857c 100644 --- a/wcs/variables.py +++ b/wcs/variables.py @@ -704,7 +704,7 @@ class LazyFormData(LazyFormDef): except AttributeError: if key.startswith('f'): for field in self._formdef.get_all_fields(): - if str(field.id) == str(key[1:]): + if str(field.id).replace('-', '_') == str(key[1:]): return self._formdata.data.get(field.id) raise