|
1 | 1 | from __future__ import annotations
|
2 | 2 |
|
| 3 | +import logging |
3 | 4 | from dataclasses import dataclass, field
|
4 | 5 | from datetime import date, datetime, time
|
5 | 6 | from typing import TYPE_CHECKING, Any, Literal, overload
|
|
11 | 12 | from django.utils.functional import empty
|
12 | 13 | from django.utils.translation import gettext_lazy as _
|
13 | 14 |
|
| 15 | +from glom import glom |
| 16 | + |
14 | 17 | from openforms.formio.service import FormioData
|
15 | 18 | from openforms.forms.models.form_variable import FormVariable
|
16 | 19 | from openforms.typing import DataMapping, JSONEncodable, JSONObject, JSONSerializable
|
|
19 | 22 | from openforms.variables.service import VariablesRegistry, get_static_variables
|
20 | 23 |
|
21 | 24 | from ..constants import SubmissionValueVariableSources
|
| 25 | +from ..transform_data import TRANSFORM_DATA_MAPPING |
22 | 26 | from .submission import Submission
|
23 | 27 |
|
24 | 28 | if TYPE_CHECKING:
|
25 | 29 | from .submission_step import SubmissionStep
|
26 | 30 |
|
| 31 | +logger = logging.getLogger(__name__) |
| 32 | + |
27 | 33 |
|
28 | 34 | class ValueEncoder(DjangoJSONEncoder):
|
29 | 35 | def default(self, obj: JSONEncodable | JSONSerializable) -> JSONEncodable:
|
@@ -104,7 +110,26 @@ def get_data(
|
104 | 110 | continue
|
105 | 111 |
|
106 | 112 | if variable.source != SubmissionValueVariableSources.sensitive_data_cleaner:
|
107 |
| - formio_data[variable_key] = variable.value |
| 113 | + component_configuration = ( |
| 114 | + variable.submission.total_configuration_wrapper[variable.key] |
| 115 | + ) |
| 116 | + |
| 117 | + if glom( |
| 118 | + component_configuration, "openForms.transformData", default=None |
| 119 | + ): |
| 120 | + transform_function = TRANSFORM_DATA_MAPPING.get( |
| 121 | + component_configuration["type"] |
| 122 | + ) |
| 123 | + if not transform_function: |
| 124 | + logger.warning( |
| 125 | + "Incorrect configuration, component of type `%s` has `openForms.transformData` " |
| 126 | + "set to true, but no transform function is defined in TRANSFORM_DATA_MAPPING", |
| 127 | + component_configuration["type"], |
| 128 | + ) |
| 129 | + transform_function = lambda value: value |
| 130 | + formio_data[variable_key] = transform_function(variable.value) |
| 131 | + else: |
| 132 | + formio_data[variable_key] = variable.value |
108 | 133 | return formio_data if as_formio_data else formio_data.data
|
109 | 134 |
|
110 | 135 | def get_variables_in_submission_step(
|
|
0 commit comments