-
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.
Merge pull request #3954 from open-formulieren/feature/3688-refactor-…
…reg-plugin [#3688] Refactor Objects API plugin to allow for v2
- Loading branch information
Showing
13 changed files
with
346 additions
and
222 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,41 +1,20 @@ | ||
from typing import TypedDict | ||
from typing import Any | ||
|
||
from openforms.contrib.zgw.clients.utils import ( # TODO: should be moved somewhere more generic? | ||
get_today, | ||
) | ||
from openforms.registrations.constants import REGISTRATION_ATTRIBUTE | ||
from openforms.submissions.mapping import MappingConfig, apply_data_mapping | ||
from openforms.submissions.models import Submission | ||
|
||
from .rendering import render_to_json | ||
|
||
|
||
class PrepareOptions(TypedDict): | ||
content_json: str # Django template syntax | ||
objecttype: str # URL to the objecttype in the Objecttypes API | ||
objecttype_version: int | ||
from openforms.utils.date import get_today | ||
|
||
|
||
def prepare_data_for_registration( | ||
submission: Submission, | ||
context: dict, | ||
options: PrepareOptions, | ||
object_mapping: MappingConfig, | ||
) -> dict: | ||
# Prepare the submission data for sending it to the Objects API. This requires | ||
# rendering the configured JSON template and running some basic checks for | ||
# security and validity, before throwing it over the fence to the Objects API. | ||
|
||
record_data = render_to_json(options["content_json"], context) | ||
|
||
object_data = { | ||
"type": options["objecttype"], | ||
record_data: dict[str, Any], | ||
objecttype: str, | ||
objecttype_version: int, | ||
) -> dict[str, Any]: | ||
"""Prepare the submission data for sending it to the Objects API.""" | ||
|
||
return { | ||
"type": objecttype, | ||
"record": { | ||
"typeVersion": options["objecttype_version"], | ||
"typeVersion": objecttype_version, | ||
"data": record_data, | ||
"startAt": get_today(), | ||
}, | ||
} | ||
apply_data_mapping(submission, object_mapping, REGISTRATION_ATTRIBUTE, object_data) | ||
|
||
return object_data |
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
This file was deleted.
Oops, something went wrong.
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
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
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
Oops, something went wrong.