From 2bd1e98617a9af32cf64f64b7330acfe3026d986 Mon Sep 17 00:00:00 2001 From: Sina Atalay <79940989+sinaatalay@users.noreply.github.com> Date: Mon, 8 Apr 2024 19:25:41 +0000 Subject: [PATCH] data_models: add a computed field `connections` to `CurriculumVitae` --- rendercv/data_models.py | 58 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/rendercv/data_models.py b/rendercv/data_models.py index 9872937..b367e5f 100644 --- a/rendercv/data_models.py +++ b/rendercv/data_models.py @@ -896,6 +896,64 @@ class CurriculumVitae(RenderCVBaseModel): alias="sections", ) + @functools.cached_property + def connections(self) -> list[dict[str, str]]: + """Return all the connections of the person.""" + connections: list[dict[str, str]] = [] + + if self.email is not None: + connections.append( + { + "latex_icon": "\\faEnvelope[regular]", + "url": f"mailto:{self.email}", + "clean_url": self.email, + "placeholder": self.email, + } + ) + if self.phone is not None: + phone_placeholder = self.phone.replace("tel:", "").replace("-", " ") + connections.append( + { + "latex_icon": "\\faPhone*", + "url": f"{self.phone}", + "clean_url": phone_placeholder, + "placeholder": phone_placeholder, + } + ) + + if self.website is not None: + website_placeholder = str(self.website).replace("https://", "").rstrip("/") + connections.append( + { + "latex_icon": "\\faLink", + "url": self.website, + "clean_url": website_placeholder, + "placeholder": website_placeholder, + } + ) + + if self.social_networks is not None: + icon_dictionary = { + "LinkedIn": "\\faLinkedinIn", + "GitHub": "\\faGithub", + "Instagram": "\\faInstagram", + "Mastodon": "\\faMastodon", + "Orcid": "\\faOrcid", + "Twitter": "\\faTwitter", + } + for social_network in self.social_networks: + clean_url = social_network.url.replace("https://", "").rstrip("/") + connections.append( + { + "latex_icon": icon_dictionary[social_network.network], + "url": social_network.url, + "clean_url": clean_url, + "placeholder": social_network.username, + } + ) + + return connections + @functools.cached_property def sections(self) -> list[SectionBase]: """Return all the sections of the CV with their titles."""