From 50681949cc830d9f9a1a3a85aa7c493f542be975 Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Sun, 2 Jun 2024 03:10:37 +0300 Subject: [PATCH] data_models: fix check_and_adjust_dates --- rendercv/data_models.py | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/rendercv/data_models.py b/rendercv/data_models.py index 30cc5c7..e835bff 100644 --- a/rendercv/data_models.py +++ b/rendercv/data_models.py @@ -389,16 +389,16 @@ class EntryBase(EntryWithDate): # If only start_date is provided, assume it is an ongoing event, i.e., # the end_date is present: self.end_date = "present" - end_date = Date.today() - else: + + if self.end_date != "present": end_date = get_date_object(self.end_date) - if start_date > end_date: - raise ValueError( - '"start_date" can not be after "end_date"!', - "start_date", # This is the location of the error - str(start_date), # This is value of the error - ) + if start_date > end_date: + raise ValueError( + '"start_date" can not be after "end_date"!', + "start_date", # This is the location of the error + str(start_date), # This is value of the error + ) return self @@ -864,6 +864,12 @@ class SocialNetwork(RenderCVBaseModel): @classmethod def check_username(cls, username: str, info: pydantic.ValidationInfo) -> str: """Check if the username is provided correctly.""" + if "network" not in info.data: + # the network is either not provided or not one of the available social + # networks. In this case, don't check the username, since Pydantic will + # raise an error for the network. + return username + network = info.data["network"] if network == "Mastodon":