-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🚧 [#4908] Add processing of form variable options to JSON registratio…
…n plugin Need to include all form variables listed in the options to a values dictionary
- Loading branch information
1 parent
037b928
commit c7e4837
Showing
1 changed file
with
21 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,37 @@ | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
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 .config import JSONOptionsSerializer | ||
|
||
|
||
@register("json") | ||
class JSONPlugin(BasePlugin): | ||
class JSONRegistration(BasePlugin): | ||
verbose_name = _("JSON registration") | ||
configuration_options = JSONOptionsSerializer | ||
|
||
def register_submission(self, submission: Submission, options: OptionsT) -> None: | ||
print(options) | ||
static_variables = get_static_variables(submission=submission) | ||
static_variables_dict = { | ||
variable.key: variable.initial_value for variable in static_variables | ||
} | ||
|
||
# TODO-4908: what should the behaviour be when a form | ||
# variable is not in the data or static variables? | ||
values = { | ||
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} | ||
|
||
def check_config(self): | ||
pass |