Skip to content

Commit

Permalink
🚚 [#4980] Make few functions public API
Browse files Browse the repository at this point in the history
to_multiple, rewrite_formio_components, and DataContainer need to be used in the JSON dump plugin
  • Loading branch information
viktorvanwijk committed Jan 24, 2025
1 parent b19056e commit e84e3e1
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/openforms/formio/components/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from openforms.submissions.models import Submission
from openforms.typing import DataMapping, JSONObject
from openforms.utils.date import TIMEZONE_AMS, datetime_in_amsterdam, format_date_value
from openforms.utils.json_schema import to_multiple
from openforms.utils.validators import BSNValidator, IBANValidator
from openforms.validations.service import PluginValidator

Expand All @@ -43,7 +44,7 @@
from .np_family_members.haal_centraal import get_np_family_members_haal_centraal
from .np_family_members.models import FamilyMembersTypeConfig
from .np_family_members.stuf_bg import get_np_family_members_stuf_bg
from .utils import _normalize_pattern, salt_location_message, to_multiple
from .utils import _normalize_pattern, salt_location_message

logger = logging.getLogger(__name__)

Expand Down
14 changes: 0 additions & 14 deletions src/openforms/formio/components/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,3 @@ def salt_location_message(message_bits: dict[str, str]) -> str:
computed_message = f"{message_bits['postcode']}/{message_bits['number']}/{message_bits['city']}/{message_bits['street_name']}"
computed_hmac = salted_hmac("location_check", value=computed_message).hexdigest()
return computed_hmac


def to_multiple(schema: JSONObject) -> JSONObject:
"""Convert a JSON schema of a component to a schema of multiple components.
:param schema: JSON schema of a component.
:returns: JSON schema of multiple components.
"""
title = schema.pop("title")
return {
"title": title,
"type": "array",
"items": schema,
}
3 changes: 2 additions & 1 deletion src/openforms/formio/components/vanilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from openforms.submissions.attachments import temporary_upload_from_url
from openforms.submissions.models import EmailVerification
from openforms.typing import DataMapping, JSONObject
from openforms.utils.json_schema import to_multiple
from openforms.utils.urls import build_absolute_uri
from openforms.validations.service import PluginValidator

Expand Down Expand Up @@ -68,7 +69,7 @@
)
from ..typing.base import OpenFormsConfig
from .translations import translate_options
from .utils import _normalize_pattern, to_multiple
from .utils import _normalize_pattern

if TYPE_CHECKING:
from openforms.submissions.models import Submission
Expand Down
1 change: 1 addition & 0 deletions src/openforms/formio/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"iterate_data_with_components",
"recursive_apply",
"build_serializer",
"rewrite_formio_components",
]


Expand Down
3 changes: 3 additions & 0 deletions src/openforms/submissions/service.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .logic.datastructures import DataContainer

__all__ = ["DataContainer"]
15 changes: 15 additions & 0 deletions src/openforms/utils/json_schema.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from openforms.typing import JSONObject


def to_multiple(schema: JSONObject) -> JSONObject:
"""Convert a JSON schema of a component to a schema of multiple components.
:param schema: JSON schema of a component.
:returns: JSON schema of multiple components.
"""
title = schema.pop("title")
return {
"title": title,
"type": "array",
"items": schema,
}

0 comments on commit e84e3e1

Please sign in to comment.