From f43084c335a984627a432d9e0c800fab98704a66 Mon Sep 17 00:00:00 2001 From: Viktor van Wijk Date: Thu, 19 Dec 2024 15:01:32 +0100 Subject: [PATCH] :art: [#4908] Restructure register submission for JSON plugin Makes more sense to keep static variables dict close to where it's used --- .../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 76fd78b151..1aad505b84 100644 --- a/src/openforms/registrations/contrib/json/plugin.py +++ b/src/openforms/registrations/contrib/json/plugin.py @@ -2,11 +2,14 @@ from django.utils.translation import gettext_lazy as _ +from zgw_consumers.client import build_client + from openforms.submissions.models import Submission from openforms.variables.service import get_static_variables from ...base import BasePlugin, OptionsT # openforms.registrations.base from ...registry import register # openforms.registrations.registry +from ...utils import execute_unless_result_exists from .config import JSONOptionsSerializer @@ -16,12 +19,11 @@ class JSONRegistration(BasePlugin): configuration_options = JSONOptionsSerializer def register_submission(self, submission: Submission, options: OptionsT) -> None: - static_variables = get_static_variables(submission=submission) - static_variables_dict = { - variable.key: variable.initial_value for variable in static_variables - } + # TODO-4908: the email plugin works with a EmailConfig singleton model. Is that useful here? + # TODO-4908: add typing for options dict values = {} + # Encode (base64) and add attachments to values dict if they were specified in the form variables list if submission.attachments.exists(): for attachment in submission.attachments: if not attachment.form_key in options["form_variables"]: @@ -33,6 +35,13 @@ def register_submission(self, submission: Submission, options: OptionsT) -> None # TODO-4908: what should the behaviour be when a form # variable is not in the data or static variables? + # Create static variables dict + static_variables = get_static_variables(submission=submission) + static_variables_dict = { + variable.key: variable.initial_value for variable in static_variables + } + + # Update values dict with relevant form data values.update({ form_variable: submission.data.get( form_variable, static_variables_dict.get(form_variable) @@ -46,5 +55,6 @@ def register_submission(self, submission: Submission, options: OptionsT) -> None # TODO-4908: added return for testing purposes return {"values": values} + # TODO-4098: what to do in here? def check_config(self): pass