data_models: disable raising errors when only end_date is provided

This commit is contained in:
Sina Atalay 2024-03-11 20:29:22 +01:00
parent 62dfa9d1d8
commit 2847b1ef6d
1 changed files with 8 additions and 7 deletions

View File

@ -20,6 +20,7 @@ import importlib.util
import importlib.machinery import importlib.machinery
import functools import functools
from urllib.request import urlopen, HTTPError from urllib.request import urlopen, HTTPError
from http.client import InvalidURL
import json import json
import re import re
import ssl import ssl
@ -215,12 +216,10 @@ class EntryBase(RenderCVBaseModel):
raise ValueError(str(e), "date", str(model.date)) raise ValueError(str(e), "date", str(model.date))
elif not start_date_is_provided and end_date_is_provided: elif not start_date_is_provided and end_date_is_provided:
raise ValueError( # If only end_date is provided, assume it is a one-day event:
'"end_date" is provided, but "start_date" is not. Either provide both' model.date = model.end_date
' "start_date" and "end_date" or provide "date".', model.start_date = None
"start_date", # this is the location of the error model.end_date = None
"", # this supposed to be the value of the error
)
elif start_date_is_provided: elif start_date_is_provided:
if not end_date_is_provided: if not end_date_is_provided:
# Then it means only the start_date is provided, so it is an ongoing # Then it means only the start_date is provided, so it is an ongoing
@ -311,7 +310,7 @@ class EntryBase(RenderCVBaseModel):
if self.date is not None: if self.date is not None:
try: try:
date_object = get_date_object(self.date) date_object = get_date_object(self.date)
date_string = format_date(date_object) date_string = str(date_object.year)
except ValueError: except ValueError:
# Then it is a custom date string (e.g., "My Custom Date") # Then it is a custom date string (e.g., "My Custom Date")
date_string = str(self.date) date_string = str(self.date)
@ -530,6 +529,8 @@ class PublicationEntry(RenderCVBaseModel):
except HTTPError as err: except HTTPError as err:
if err.code == 404: if err.code == 404:
raise ValueError("DOI cannot be found in the DOI System!") raise ValueError("DOI cannot be found in the DOI System!")
except InvalidURL:
raise ValueError("This DOI is not valid!")
return doi return doi