mirror of https://github.com/eyhc1/rendercv.git
improve section validation
This commit is contained in:
parent
0ca6b8428d
commit
67bab3b3b3
|
@ -672,21 +672,16 @@ def get_entry_and_section_type(
|
||||||
section type.
|
section type.
|
||||||
"""
|
"""
|
||||||
if isinstance(entry, dict):
|
if isinstance(entry, dict):
|
||||||
if "details" in entry and "name" in entry:
|
if "details" in entry:
|
||||||
entry_type = "OneLineEntry"
|
entry_type = "OneLineEntry"
|
||||||
section_type = SectionWithOneLineEntries
|
section_type = SectionWithOneLineEntries
|
||||||
elif "company" in entry and "position" in entry:
|
elif "company" in entry or "position" in entry:
|
||||||
entry_type = "ExperienceEntry"
|
entry_type = "ExperienceEntry"
|
||||||
section_type = SectionWithExperienceEntries
|
section_type = SectionWithExperienceEntries
|
||||||
elif "institution" in entry and "area" in entry and "degree" in entry:
|
elif "institution" in entry or "area" in entry or "degree" in entry:
|
||||||
entry_type = "EducationEntry"
|
entry_type = "EducationEntry"
|
||||||
section_type = SectionWithEducationEntries
|
section_type = SectionWithEducationEntries
|
||||||
elif (
|
elif "title" in entry or "authors" in entry or "doi" in entry:
|
||||||
"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:
|
||||||
|
@ -751,7 +746,10 @@ def validate_section_input(
|
||||||
|
|
||||||
if entry_type is None or section_type is None:
|
if entry_type is None or section_type is None:
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
"Please check your entries. They are not provided correctly."
|
"RenderCV couldn't match this section with any entry type! Please check"
|
||||||
|
" the entries and make sure they are provided correctly.",
|
||||||
|
"", # this is the location of the error
|
||||||
|
"", # this is value of the error
|
||||||
)
|
)
|
||||||
|
|
||||||
test_section = {
|
test_section = {
|
||||||
|
@ -780,8 +778,7 @@ def validate_section_input(
|
||||||
# Create a custom type called SectionInput so that it can be validated with
|
# Create a custom type called SectionInput so that it can be validated with
|
||||||
# `validate_section_input` function.
|
# `validate_section_input` function.
|
||||||
SectionInput = Annotated[
|
SectionInput = Annotated[
|
||||||
Section
|
list[
|
||||||
| list[
|
|
||||||
EducationEntry
|
EducationEntry
|
||||||
| ExperienceEntry
|
| ExperienceEntry
|
||||||
| PublicationEntry
|
| PublicationEntry
|
||||||
|
@ -917,12 +914,6 @@ class CurriculumVitae(RenderCVBaseModel):
|
||||||
)
|
)
|
||||||
sections.append(section)
|
sections.append(section)
|
||||||
|
|
||||||
elif hasattr(section_or_entries, "entry_type"):
|
|
||||||
if section_or_entries.title is None:
|
|
||||||
section_or_entries.title = title
|
|
||||||
|
|
||||||
sections.append(section_or_entries)
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise RuntimeError(
|
raise RuntimeError(
|
||||||
"This error shouldn't have been raised. Please open an"
|
"This error shouldn't have been raised. Please open an"
|
||||||
|
@ -1089,7 +1080,7 @@ def read_input_file(
|
||||||
return rendercv_data_model
|
return rendercv_data_model
|
||||||
|
|
||||||
|
|
||||||
def get_a_sample_data_model(name: str) -> RenderCVDataModel:
|
def get_a_sample_data_model(name: str = "John Doe") -> RenderCVDataModel:
|
||||||
"""Return a sample data model for new users to start with."""
|
"""Return a sample data model for new users to start with."""
|
||||||
sections = {
|
sections = {
|
||||||
"summary": [
|
"summary": [
|
||||||
|
@ -1174,38 +1165,32 @@ def get_a_sample_data_model(name: str) -> RenderCVDataModel:
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
"my_custom_section": SectionWithExperienceEntries(
|
"my_custom_section": [
|
||||||
entry_type="ExperienceEntry",
|
ExperienceEntry(
|
||||||
entries=[
|
company="Your Company",
|
||||||
ExperienceEntry(
|
position="Your Position",
|
||||||
company="Your Company",
|
date="My Whole Life",
|
||||||
position="Your Position",
|
location="USA",
|
||||||
date="My Whole Life",
|
highlights=[
|
||||||
location="USA",
|
"Did something great.",
|
||||||
highlights=[
|
"Did something else great.",
|
||||||
"Did something great.",
|
],
|
||||||
"Did something else great.",
|
),
|
||||||
],
|
ExperienceEntry(
|
||||||
),
|
company="Your Company",
|
||||||
ExperienceEntry(
|
position="Your Position",
|
||||||
company="Your Company",
|
),
|
||||||
position="Your Position",
|
],
|
||||||
),
|
"This Format Is Also Accepted": [
|
||||||
],
|
OneLineEntry(
|
||||||
),
|
name="Your Entry",
|
||||||
"This Format Is Also Accepted": SectionWithOneLineEntries(
|
details="Your details.",
|
||||||
entry_type="OneLineEntry",
|
),
|
||||||
entries=[
|
OneLineEntry(
|
||||||
OneLineEntry(
|
name="Your *Entry*",
|
||||||
name="Your Entry",
|
details="Your details.",
|
||||||
details="Your details.",
|
),
|
||||||
),
|
],
|
||||||
OneLineEntry(
|
|
||||||
name="Your *Entry*",
|
|
||||||
details="Your details.",
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
}
|
}
|
||||||
|
|
||||||
cv = CurriculumVitae(
|
cv = CurriculumVitae(
|
||||||
|
|
Loading…
Reference in New Issue