@@ -65,7 +65,8 @@ def register_submission(
65
65
if key in options ["variables" ]
66
66
}
67
67
values_schema = generate_json_schema (submission .form , options ["variables" ])
68
- post_process (values , values_schema , submission )
68
+ transform_to_list = options .get ("transform_to_list" )
69
+ post_process (values , values_schema , submission , transform_to_list )
69
70
70
71
# Metadata
71
72
# Note: as the metadata contains only static variables no post-processing is
@@ -114,7 +115,10 @@ def get_variables(self) -> list[FormVariable]: # pragma: no cover
114
115
115
116
116
117
def post_process (
117
- values : JSONObject , schema : JSONObject , submission : Submission
118
+ values : JSONObject ,
119
+ schema : JSONObject ,
120
+ submission : Submission ,
121
+ transform_to_list : list | None = None ,
118
122
) -> None :
119
123
"""Post-process the values and schema.
120
124
@@ -127,6 +131,8 @@ def post_process(
127
131
:param values: Mapping from key to value of the data to be sent.
128
132
:param schema: JSON schema describing ``values``.
129
133
:param submission: The corresponding submission instance.
134
+ :param transform_to_list: The list of the variables(keys) which need special handling
135
+ concerning the shape of the data (need transformation to a list).
130
136
"""
131
137
state = submission .load_submission_value_variables_state ()
132
138
@@ -170,7 +176,12 @@ def post_process(
170
176
assert component is not None
171
177
172
178
process_component (
173
- component , values , schema , attachments_dict , configuration_wrapper
179
+ component ,
180
+ values ,
181
+ schema ,
182
+ attachments_dict ,
183
+ configuration_wrapper ,
184
+ transform_to_list = transform_to_list ,
174
185
)
175
186
176
187
@@ -181,6 +192,7 @@ def process_component(
181
192
attachments : dict [str , list [SubmissionFileAttachment ]],
182
193
configuration_wrapper ,
183
194
key_prefix : str = "" ,
195
+ transform_to_list : list | None = None ,
184
196
) -> None :
185
197
"""Process a component.
186
198
@@ -202,6 +214,8 @@ def process_component(
202
214
:param key_prefix: If the component is part of an edit grid component, this key
203
215
prefix includes the parent key and the index of the component as it appears in the
204
216
submitted data list of that edit grid component.
217
+ :param transform_to_list: The list of the variables(keys) which need special handling
218
+ concerning the shape of the data (need transformation to a list).
205
219
"""
206
220
key = component ["key" ]
207
221
@@ -264,6 +278,12 @@ def process_component(
264
278
if not values [key ]:
265
279
schema ["properties" ][key ]["required" ] = [] # type: ignore
266
280
281
+ if transform_to_list and key in transform_to_list and values [key ]:
282
+ schema ["properties" ][key ]["type" ] = "array" # type: ignore
283
+ values [key ] = [
284
+ option for option , is_selected in values [key ].items () if is_selected # type: ignore
285
+ ]
286
+
267
287
case {"type" : "editgrid" }:
268
288
# Note: the schema actually only needs to be processed once for each child
269
289
# component, but will be processed for each submitted repeating group entry
0 commit comments