From 9e2f502f9a7c0add5962b7609b5dc2ea65232fbf Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Tue, 30 Apr 2024 20:01:19 +0300 Subject: [PATCH] data_models: improve `set_or_update_a_value` --- rendercv/data_models.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/rendercv/data_models.py b/rendercv/data_models.py index 54cfa80..96938a5 100644 --- a/rendercv/data_models.py +++ b/rendercv/data_models.py @@ -1114,7 +1114,7 @@ class RenderCVDataModel(RenderCVBaseModel): ) ThemeDataModel = getattr( - theme_module, f"{theme_name.title()}ThemeOptions" # type: ignore + theme_module, f"{theme_name.capitalize()}ThemeOptions" # type: ignore ) # initialize and validate the custom theme data model: @@ -1161,6 +1161,10 @@ def set_or_update_a_value( if len(keys) == 1: # set the value: + if value.startswith("{") and value.endswith("}"): + # allow users to assign dictionaries directly in the input file: + value = eval(value) + if isinstance(model, pydantic.BaseModel): setattr(model, key, value) elif isinstance(model, dict): @@ -1173,7 +1177,10 @@ def set_or_update_a_value( " list.", ) - data_model.model_validate(data_model.model_dump(by_alias=True)) + data_model = type(data_model).model_validate( + (data_model.model_dump(by_alias=True)) + ) + return data_model else: # get the first key and call the function with remaining keys: first_key = keys[0]