diff --git a/ancv/data/models/resume.py b/ancv/data/models/resume.py index d380876..540ab70 100644 --- a/ancv/data/models/resume.py +++ b/ancv/data/models/resume.py @@ -115,10 +115,10 @@ class Config: class TemplateConfig(BaseModel): - template: str = "Sequential" - theme: str = "basic" - translation: str = "en" - ascii_only: bool = False + template: Optional[str] + theme: Optional[str] + translation: Optional[str] + ascii_only: Optional[bool] class Meta(BaseModel): @@ -134,8 +134,8 @@ class Config: lastModified: Optional[datetime] = Field( None, description="Using ISO 8601 with YYYY-MM-DDThh:mm:ss" ) - config: TemplateConfig = Field( - TemplateConfig(), + config: Optional[TemplateConfig] = Field( + None, alias="ancv", description="Template configuration to control display", ) diff --git a/ancv/visualization/templates.py b/ancv/visualization/templates.py index 499c0ef..824d0cc 100644 --- a/ancv/visualization/templates.py +++ b/ancv/visualization/templates.py @@ -30,6 +30,7 @@ ResumeItem, ResumeItemContainer, ResumeSchema, + TemplateConfig, VolunteerItem, WorkItem, ) @@ -92,30 +93,38 @@ def subclasses(cls) -> dict[str, type["Template"]]: @classmethod def from_model_config(cls, model: ResumeSchema) -> "Template": + if (config := model.meta.config) is None: + config = TemplateConfig() + + if (theme_name := config.theme) is None: + theme_name = "basic" try: - theme = THEMES[model.meta.config.theme] + theme = THEMES[theme_name] except KeyError as e: - raise ResumeConfigError(f"Unknown theme: {model.meta.config.theme}") from e + raise ResumeConfigError(f"Unknown theme: {theme_name}") from e + if (translation_name := config.translation) is None: + translation_name = "en" try: - translation = TRANSLATIONS[model.meta.config.translation] + translation = TRANSLATIONS[translation_name] except KeyError as e: - raise ResumeConfigError( - f"Unknown translation: {model.meta.config.translation}" - ) from e + raise ResumeConfigError(f"Unknown translation: {translation_name}") from e + if (template_name := config.template) is None: + template_name = Sequential.__name__ try: - template = cls.subclasses()[model.meta.config.template] + template = cls.subclasses()[template_name] except KeyError as e: - raise ResumeConfigError( - f"Unknown template: {model.meta.config.template}" - ) from e + raise ResumeConfigError(f"Unknown template: {template_name}") from e + + if (ascii_only := config.ascii_only) is None: + ascii_only = False return template( model=model, theme=theme, translation=translation, - ascii_only=model.meta.config.ascii_only, + ascii_only=ascii_only, ) @classmethod