Skip to content

Commit

Permalink
🚧 [#4908] Add processing of attachments in plugin
Browse files Browse the repository at this point in the history
The content of the attachment is now added to the result
  • Loading branch information
viktorvanwijk committed Dec 19, 2024
1 parent 46f6381 commit c487586
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/openforms/registrations/contrib/json/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c487586

Please sign in to comment.