diff --git a/rendercv/data/content.py b/rendercv/data/content.py index 28fdfc0..cb851c1 100644 --- a/rendercv/data/content.py +++ b/rendercv/data/content.py @@ -1,4 +1,4 @@ -from pydantic import BaseModel, HttpUrl +from pydantic import BaseModel, HttpUrl, model_validator from pydantic_extra_types.phone_numbers import PhoneNumber from typing import Literal from datetime import date as Date @@ -19,18 +19,6 @@ class Skill(BaseModel): details: str = None -class Activity(BaseModel): - # 1) Mandotory user inputs: - organization: str - position: str - location: Location - # 2) Optional user inputs: - start_date: Date = None - end_date: Date = None - company_url: HttpUrl = None - highlights: list[str] = None - - class TestScore(BaseModel): # 1) Mandotory user inputs: name: str @@ -45,13 +33,13 @@ class Project(BaseModel): name: str location: Location # 2) Optional user inputs: - start_date: Date= None + start_date: Date = None end_date: Date = None url: HttpUrl = None highlights: list[str] = None -class WorkExperience(BaseModel): +class Experience(BaseModel): # 1) Mandotory user inputs: company: str position: str @@ -78,10 +66,13 @@ class Education(BaseModel): class SocialNetwork(BaseModel): # 1) Mandotory user inputs: - network: Literal["LinkedIn", "GitHub", "Twitter", "Facebook", "Instagram"] + network: Literal["LinkedIn", "GitHub", "Instagram"] username: str - url: HttpUrl +class Connection(BaseModel): + # 3) Derived fields (not user inputs): + name: Literal["LinkedIn", "GitHub", "Instagram", "phone", "email", "website"] + value: str class CurriculumVitae(BaseModel): # 1) Mandotory user inputs: @@ -93,8 +84,31 @@ class CurriculumVitae(BaseModel): location: Location = None social_networks: list[SocialNetwork] = None education: list[Education] = None - work_experience: list[WorkExperience] = None + work_experience: list[Experience] = None academic_projects: list[Project] = None - extracurricular_activities: list[Activity] = None + extracurricular_activities: list[Experience] = None test_scores: list[TestScore] = None skills: list[Skill] = None + + # 3) Derived fields (not user inputs): + connections: list[SocialNetwork] = [] + + @model_validator(mode="after") + @classmethod + def derive_connections(cls, model): + connections = [] + if model.email is not None: + connections.append(Connection(name="email", value=model.email)) + if model.phone is not None: + connections.append(Connection(name="phone", value=model.phone)) + if model.website is not None: + connections.append(Connection(name="website", value=model.website)) + if model.social_networks is not None: + for social_network in model.social_networks: + connections.append(Connection( + name=social_network.network, + value=social_network.username + )) + model.connections = connections + return model + \ No newline at end of file