improve get_entry_and_section_type

This commit is contained in:
Sina Atalay 2024-02-11 22:43:27 +01:00
parent a7a4a943f2
commit ba683e861a
1 changed files with 23 additions and 14 deletions

View File

@ -212,7 +212,7 @@ class EntryBase(RenderCVBaseModel):
today_object = Date.today() today_object = Date.today()
if date_object > today_object: if date_object > today_object:
raise ValueError( raise ValueError(
'"date" cannot be in the future.', '"date" cannot be in the future!',
"date", # this is the location of the error "date", # this is the location of the error
model.date, # this is value of the error model.date, # this is value of the error
) )
@ -241,13 +241,13 @@ class EntryBase(RenderCVBaseModel):
if start_date > end_date: if start_date > end_date:
raise ValueError( raise ValueError(
'"start_date" can not be after "end_date"', '"start_date" can not be after "end_date"!',
"start_date/end_date", # this is the location of the error "start_date", # this is the location of the error
"", # this supposed to be the value of the error model.start_date, # this is value of the error
) )
elif end_date > Date.today(): elif end_date > Date.today():
raise ValueError( raise ValueError(
'"end_date" cannot be in the future.', '"end_date" cannot be in the future!',
"end_date", # this is the location of the error "end_date", # this is the location of the error
model.end_date, # this is value of the error model.end_date, # this is value of the error
) )
@ -694,16 +694,16 @@ def get_entry_and_section_type(
section type. section type.
""" """
if isinstance(entry, dict): if isinstance(entry, dict):
if "details" in entry: if "details" in entry and "name" in entry:
entry_type = "OneLineEntry" entry_type = "OneLineEntry"
section_type = SectionWithOneLineEntries section_type = SectionWithOneLineEntries
elif "company" in entry: elif "company" in entry and "position" in entry:
entry_type = "ExperienceEntry" entry_type = "ExperienceEntry"
section_type = SectionWithExperienceEntries section_type = SectionWithExperienceEntries
elif "institution" in entry: elif "institution" in entry and "area" in entry and "degree" in entry:
entry_type = "EducationEntry" entry_type = "EducationEntry"
section_type = SectionWithEducationEntries section_type = SectionWithEducationEntries
elif "title" in entry: elif "title" in entry and "authors" in entry and "doi" in entry and "date" in entry:
entry_type = "PublicationEntry" entry_type = "PublicationEntry"
section_type = SectionWithPublicationEntries section_type = SectionWithPublicationEntries
elif "name" in entry: elif "name" in entry:
@ -756,11 +756,20 @@ def validate_section_input(
Section | list[Any]: The validated sections input. Section | list[Any]: The validated sections input.
""" """
if isinstance(sections_input, list): if isinstance(sections_input, list):
# find the entry type based on the first element of the list: # find the entry type based on the first identifiable entry:
try: entry_type = None
entry_type, section_type = get_entry_and_section_type(sections_input[0]) section_type = None
except ValueError: for entry in sections_input:
raise ValueError("The entries are not provided correctly.") try:
entry_type, section_type = get_entry_and_section_type(entry)
break
except ValueError:
pass
if entry_type is None or section_type is None:
raise ValueError(
"Please check your entries. They are not provided correctly."
)
test_section = { test_section = {
"title": "Test Section", "title": "Test Section",