From 631e9d594c273fb99d5aa60b5f6199f310bfa46e Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Fri, 17 Nov 2023 01:04:29 +0100 Subject: [PATCH] add more sections --- rendercv/data_model.py | 58 ++++++++++++++++++++++-------------------- schema.json | 50 ++++++++++++++---------------------- 2 files changed, 50 insertions(+), 58 deletions(-) diff --git a/rendercv/data_model.py b/rendercv/data_model.py index d25c40c..219d03e 100644 --- a/rendercv/data_model.py +++ b/rendercv/data_model.py @@ -272,9 +272,15 @@ def generate_json_schema(output_directory: str) -> str: # Don't allow additional properties value["additionalProperties"] = False + # I don't want the docstrings in the schema, so remove them: if "This class" in value["description"]: del value["description"] + # If a type is optional, then Pydantic sets the type to a list of two + # types, one of which is null. The null type can be removed since we + # already have the required field. Moreover, we would like to warn + # users if they provide null values. They can remove the fields if they + # don't want to provide them. null_type_dict = {} null_type_dict["type"] = "null" for field in value["properties"].values(): @@ -286,6 +292,18 @@ def generate_json_schema(output_directory: str) -> str: field["allOf"] = [field["anyOf"][0]] del field["anyOf"] + # In date field, we both accept normal strings and Date objects. They + # are both strings, therefore, if user provides a Date object, then + # JSON schema will complain that it matches two different types. + # Remember that all of the anyOfs are changed to oneOfs. Only one of + # the types can be matched. Therefore, we remove the first type, which + # is the string with the YYYY-MM-DD format. + if ( + "date" in value["properties"] + and "anyOf" in value["properties"]["date"] + ): + del value["properties"]["date"]["anyOf"][0] + return json_schema schema = RenderCVDataModel.model_json_schema( @@ -365,16 +383,11 @@ class ClassicThemeEntryAreaMargins(BaseModel): [ExperienceEntry](../user_guide.md#experienceentry). """ - left: LaTeXDimension = Field( + left_and_right: LaTeXDimension = Field( default="0.2 cm", title="Left Margin", description="The left margin of entry areas.", ) - right: LaTeXDimension = Field( - default="0.2 cm", - title="Right Margin", - description="The right margin of entry areas.", - ) vertical_between: LaTeXDimension = Field( default="0.12 cm", @@ -578,9 +591,7 @@ class Design(BaseModel): LaTeXString = Annotated[str, AfterValidator(escape_latex_characters)] PastDate = Annotated[ - str, - Field(pattern=r"\d{4}-?(\d{2})?-?(\d{2})?"), - AfterValidator(parse_date_string), + str, Field(pattern=r"\d{4}-?(\d{2})?-?(\d{2})?"), AfterValidator(parse_date_string) ] @@ -1166,6 +1177,7 @@ class CurriculumVitae(BaseModel): title="Summary", description="The summary of the person.", ) + # Sections: section_order: Optional[list[str]] = Field( default=None, title="Section Order", @@ -1223,7 +1235,7 @@ class CurriculumVitae(BaseModel): title="Test Scores", description="The test score entries of the person.", ) - programming_skills: Optional[list[OneLineEntry]] = Field( + programming_skills: Optional[list[NormalEntry]] = Field( default=None, title="Programming Skills", description="The programming skill entries of the person.", @@ -1233,6 +1245,11 @@ class CurriculumVitae(BaseModel): title="Skills", description="The skill entries of the person.", ) + other_skills: Optional[list[OneLineEntry]] = Field( + default=None, + title="Skills", + description="The skill entries of the person.", + ) awards: Optional[list[OneLineEntry]] = Field( default=None, title="Awards", @@ -1317,6 +1334,7 @@ class CurriculumVitae(BaseModel): "Education": self.education, "Experience": self.experience, "Work Experience": self.work_experience, + "Publications": self.publications, "Projects": self.projects, "Academic Projects": self.academic_projects, "Personal Projects": self.personal_projects, @@ -1324,30 +1342,16 @@ class CurriculumVitae(BaseModel): "Extracurricular Activities": self.extracurricular_activities, "Test Scores": self.test_scores, "Skills": self.skills, + "Programming Skills": self.programming_skills, + "Other Skills": self.other_skills, "Awards": self.awards, "Interests": self.interests, "Programming Skills": self.programming_skills, - "Publications": self.publications, } if self.section_order is None: # If the user didn't specify the section order, then use the default order: - self.section_order = [ - "Education", - "Experience", - "Work Experience", - "Projects", - "Academic Projects", - "Personal Projects", - "Skills", - "Awards", - "Interests", - "Programming Skills", - "Test Scores", - "Certificates", - "Extracurricular Activities", - "Publications", - ] + self.section_order = list(pre_defined_sections.keys()) if self.custom_sections is not None: # If the user specified custom sections, then add them to the end of the # section order with the same order as they are in the input file: diff --git a/schema.json b/schema.json index b581509..140a1e0 100644 --- a/schema.json +++ b/schema.json @@ -2,20 +2,13 @@ "$defs": { "ClassicThemeEntryAreaMargins": { "properties": { - "left": { + "left_and_right": { "default": "0.2 cm", "description": "The left margin of entry areas.", "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", "title": "Left Margin", "type": "string" }, - "right": { - "default": "0.2 cm", - "description": "The right margin of entry areas.", - "pattern": "\\d+\\.?\\d* *(cm|in|pt|mm|ex|em)", - "title": "Right Margin", - "type": "string" - }, "vertical_between": { "default": "0.12 cm", "description": "The vertical margin between entry areas.", @@ -93,8 +86,7 @@ } ], "default": { - "left": "0.2 cm", - "right": "0.2 cm", + "left_and_right": "0.2 cm", "vertical_between": "0.12 cm" }, "description": "Entry area margins for the classic theme.", @@ -164,8 +156,7 @@ ], "default": { "entry_area": { - "left": "0.2 cm", - "right": "0.2 cm", + "left_and_right": "0.2 cm", "vertical_between": "0.12 cm" }, "highlights_area": { @@ -482,7 +473,7 @@ "allOf": [ { "items": { - "$ref": "#/$defs/OneLineEntry" + "$ref": "#/$defs/NormalEntry" }, "type": "array" } @@ -501,6 +492,19 @@ } ] }, + "other_skills": { + "default": null, + "description": "The skill entries of the person.", + "title": "Skills", + "allOf": [ + { + "items": { + "$ref": "#/$defs/OneLineEntry" + }, + "type": "array" + } + ] + }, "awards": { "default": null, "description": "The award entries of the person.", @@ -668,10 +672,6 @@ }, "date": { "oneOf": [ - { - "pattern": "\\d{4}-?(\\d{2})?-?(\\d{2})?", - "type": "string" - }, { "type": "string" }, @@ -838,10 +838,6 @@ }, "date": { "oneOf": [ - { - "pattern": "\\d{4}-?(\\d{2})?-?(\\d{2})?", - "type": "string" - }, { "type": "string" }, @@ -957,10 +953,6 @@ }, "date": { "oneOf": [ - { - "pattern": "\\d{4}-?(\\d{2})?-?(\\d{2})?", - "type": "string" - }, { "type": "string" }, @@ -1070,10 +1062,6 @@ }, "date": { "oneOf": [ - { - "pattern": "\\d{4}-?(\\d{2})?-?(\\d{2})?", - "type": "string" - }, { "type": "string" }, @@ -1566,8 +1554,7 @@ "date_and_location_width": "3.6 cm", "margins": { "entry_area": { - "left": "0.2 cm", - "right": "0.2 cm", + "left_and_right": "0.2 cm", "vertical_between": "0.12 cm" }, "highlights_area": { @@ -1616,6 +1603,7 @@ "label": null, "location": null, "name": "John Doe", + "other_skills": null, "personal_projects": null, "phone": null, "programming_skills": null,