Skip to content

Commit

Permalink
🎨 [#4908] Restructure register submission for JSON plugin
Browse files Browse the repository at this point in the history
Makes more sense to keep static variables dict close to where it's used
  • Loading branch information
viktorvanwijk committed Dec 19, 2024
1 parent d71a38d commit f43084c
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 @@ -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


Expand All @@ -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"]:
Expand All @@ -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)
Expand All @@ -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

0 comments on commit f43084c

Please sign in to comment.