Skip to content

Commit

Permalink
✨ [#4908] Add typing hints for json registration options
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorvanwijk committed Jan 21, 2025
1 parent 4029b69 commit 75bcc5d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
14 changes: 14 additions & 0 deletions src/openforms/registrations/contrib/json/config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Required, TypedDict

from django.utils.translation import gettext_lazy as _

from rest_framework import serializers
Expand Down Expand Up @@ -28,3 +30,15 @@ class JSONOptionsSerializer(JsonSchemaSerializerMixin, serializers.Serializer):
"A comma-separated list of form variables (can also include static variables) to use."
)
)


class JSONOptions(TypedDict):
"""
JSON registration plugin options
This describes the shape of :attr:`JSONOptionsSerializer.validated_data`, after
the input data has been cleaned/validated.
"""
service: Required[Service]
relative_api_endpoint: str
form_variables: Required[list[str]]
7 changes: 3 additions & 4 deletions src/openforms/registrations/contrib/json/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,19 @@
from openforms.submissions.models import Submission
from openforms.variables.service import get_static_variables

from ...base import BasePlugin, OptionsT # openforms.registrations.base
from ...base import BasePlugin # openforms.registrations.base
from ...registry import register # openforms.registrations.registry
from ...utils import execute_unless_result_exists
from .config import JSONOptionsSerializer
from .config import JSONOptions, JSONOptionsSerializer


@register("json")
class JSONRegistration(BasePlugin):
verbose_name = _("JSON registration")
configuration_options = JSONOptionsSerializer

def register_submission(self, submission: Submission, options: OptionsT) -> None:
def register_submission(self, submission: Submission, options: JSONOptions) -> dict:
# TODO-4908: the email plugin works with a EmailConfig singleton model. Is that useful here?
# TODO-4908: add typing for options dict

# TODO-4908: any other form field types that need 'special attention'?

Expand Down

0 comments on commit 75bcc5d

Please sign in to comment.