From c48758631febae4471676cd3c558ae023b9db9c7 Mon Sep 17 00:00:00 2001 From: Viktor van Wijk Date: Thu, 19 Dec 2024 11:10:11 +0100 Subject: [PATCH] :construction: [#4908] Add processing of attachments in plugin The content of the attachment is now added to the result --- .../registrations/contrib/json/plugin.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/openforms/registrations/contrib/json/plugin.py b/src/openforms/registrations/contrib/json/plugin.py index 0cd7b55278..bff7f72a62 100644 --- a/src/openforms/registrations/contrib/json/plugin.py +++ b/src/openforms/registrations/contrib/json/plugin.py @@ -19,19 +19,29 @@ def register_submission(self, submission: Submission, options: OptionsT) -> None variable.key: variable.initial_value for variable in static_variables } + values = {} + if submission.attachments.exists(): + for attachment in submission.attachments: + if not attachment.form_key in options["form_variables"]: + continue + options["form_variables"].remove(attachment.form_key) + with attachment.content.open("rb") as f: + values[attachment.form_key] = f.read() + # TODO-4908: what should the behaviour be when a form # variable is not in the data or static variables? - values = { + values.update({ form_variable: submission.data.get( form_variable, static_variables_dict.get(form_variable) ) for form_variable in options["form_variables"] - } + }) print(values) - # TODO-4908: send `values` to some service - data_to_be_sent = {"values": values} + # TODO-4908: send `values` to the service + # TODO-4908: added return for testing purposes + return {"values": values} def check_config(self): pass