|
18 | 18 |
|
19 | 19 | from pydantic.functional_validators import field_validator, model_validator
|
20 | 20 |
|
| 21 | +# We externalize the custom yaml constructors to create an easier entrypoint |
| 22 | +# to manage both default custom constructors, as well as end-user logic, see |
| 23 | +# https://github.com/signebedi/libreforms-fastapi/issues/150 |
| 24 | +from libreforms_fastapi.utils.custom_yaml import get_yaml_constructors |
| 25 | + |
21 | 26 | class ImproperUsernameFormat(Exception):
|
22 | 27 | """Raised when the username does not meet the regular expression defined in the app config"""
|
23 | 28 | pass
|
@@ -276,56 +281,6 @@ def password_pattern(cls, value):
|
276 | 281 | description: This is a file field
|
277 | 282 | """
|
278 | 283 |
|
279 |
| -def get_yaml_constructors(**kwargs): |
280 |
| - """ |
281 |
| - This factory is used to build a dictionary of built-in and custom constructors that |
282 |
| - will be used in building the internal, dictionary representation of the form config. |
283 |
| - """ |
284 |
| - |
285 |
| - # Default constructors for returning Python types |
286 |
| - def type_constructor_int(loader, node): |
287 |
| - return int |
288 |
| - |
289 |
| - def type_constructor_str(loader, node): |
290 |
| - return str |
291 |
| - |
292 |
| - def type_constructor_date(loader, node): |
293 |
| - return date |
294 |
| - |
295 |
| - def type_constructor_datetime(loader, node): |
296 |
| - return datetime |
297 |
| - |
298 |
| - def type_constructor_time(loader, node): |
299 |
| - return time |
300 |
| - |
301 |
| - def type_constructor_timedelta(loader, node): |
302 |
| - return timedelta |
303 |
| - |
304 |
| - def type_constructor_list(loader, node): |
305 |
| - return list |
306 |
| - |
307 |
| - def type_constructor_tuple(loader, node): |
308 |
| - return tuple |
309 |
| - |
310 |
| - def type_constructor_bytes(loader, node): |
311 |
| - return bytes |
312 |
| - |
313 |
| - # We create a constructor mapping that we'll use later to |
314 |
| - # register the constructors. |
315 |
| - constructor_mapping = { |
316 |
| - '!int': type_constructor_int, |
317 |
| - '!str': type_constructor_str, |
318 |
| - '!date': type_constructor_date, |
319 |
| - '!type_datetime': type_constructor_datetime, |
320 |
| - '!type_time': type_constructor_time, |
321 |
| - '!type_timedelta': type_constructor_time, |
322 |
| - '!list': type_constructor_list, |
323 |
| - '!tuple': type_constructor_list, |
324 |
| - '!bytes': type_constructor_bytes, |
325 |
| - **kwargs, |
326 |
| - } |
327 |
| - return constructor_mapping |
328 |
| - |
329 | 284 | # Register the type constructors
|
330 | 285 | for key, value in get_yaml_constructors().items():
|
331 | 286 | yaml.add_constructor(key, value)
|
|
0 commit comments