From 875c63d5e5d56846a3ccf6e28562e74214f07b38 Mon Sep 17 00:00:00 2001 From: Sina Atalay Date: Fri, 9 Feb 2024 20:14:17 +0100 Subject: [PATCH] update data_models.py --- rendercv/data_models.py | 43 ++++++++++++++------------------ schema.json | 55 ++++++++++++++++++++++++++++------------- 2 files changed, 56 insertions(+), 42 deletions(-) diff --git a/rendercv/data_models.py b/rendercv/data_models.py index 7603b49..5811e55 100644 --- a/rendercv/data_models.py +++ b/rendercv/data_models.py @@ -197,17 +197,20 @@ class EntryBase(RenderCVBaseModel): if model.end_date is not None: end_date_is_provided = True - if date_is_provided and start_date_is_provided and end_date_is_provided: - model.start_date = None - model.end_date = None - - elif date_is_provided and start_date_is_provided and not end_date_is_provided: - model.start_date = None - model.end_date = None - - elif date_is_provided and end_date_is_provided and not start_date_is_provided: - model.start_date = None - model.end_date = None + if date_is_provided: + try: + date_object = get_date_object(model.date) # type: ignore + except ValueError: + # Then it is a custom date string (e.g., "My Custom Date") + pass + else: + today_object = Date.today() + if date_object > today_object: + raise ValueError( + '"date" cannot be in the future.', + "date", # this is the location of the error + model.date, # this is value of the error + ) elif start_date_is_provided and not end_date_is_provided: model.end_date = "present" @@ -243,12 +246,6 @@ class EntryBase(RenderCVBaseModel): "end_date", # this is the location of the error model.end_date, # this is value of the error ) - elif start_date > Date.today(): - raise ValueError( - '"start_date" cannot be in the future.', - "start_date", # this is the location of the error - model.start_date, # this is value of the error - ) return model @@ -520,8 +517,6 @@ class PublicationEntry(RenderCVBaseModel): elif isinstance(self.date, str): date_object = get_date_object(self.date) date_string = format_date(date_object) - else: - date_string = "" return date_string @@ -645,10 +640,7 @@ def get_entry_and_section_type( section type. """ if isinstance(entry, dict): - if isinstance(entry, str): - entry_type = "TextEntry" - section_type = SectionWithTextEntries - elif "details" in entry: + if "details" in entry: entry_type = "OneLineEntry" section_type = SectionWithOneLineEntries elif "company" in entry: @@ -887,6 +879,7 @@ class RenderCVDataModel(RenderCVBaseModel): description="The data of the CV.", ) design: Design = pydantic.Field( + default=ClassicThemeOptions(theme="classic"), title="Design", description="The design information of the CV.", discriminator="theme", @@ -1313,9 +1306,9 @@ def generate_json_schema() -> dict: # is the string with the YYYY-MM-DD format. if ( "date" in value["properties"] - and "anyOf" in value["properties"]["date"] + and "oneOf" in value["properties"]["date"] ): - del value["properties"]["date"]["anyOf"][0] + del value["properties"]["date"]["oneOf"][0] return json_schema diff --git a/schema.json b/schema.json index cde4cc7..7ff52ed 100644 --- a/schema.json +++ b/schema.json @@ -543,10 +543,6 @@ ], "title": "Date", "oneOf": [ - { - "pattern": "\\d{4}-\\d{2}(-\\d{2})?", - "type": "string" - }, { "type": "integer" }, @@ -703,10 +699,6 @@ ], "title": "Date", "oneOf": [ - { - "pattern": "\\d{4}-\\d{2}(-\\d{2})?", - "type": "string" - }, { "type": "integer" }, @@ -844,10 +836,6 @@ ], "title": "Date", "oneOf": [ - { - "pattern": "\\d{4}-\\d{2}(-\\d{2})?", - "type": "string" - }, { "type": "integer" }, @@ -977,9 +965,6 @@ ], "title": "Publication Date", "oneOf": [ - { - "type": "integer" - }, { "pattern": "\\d{4}-\\d{2}(-\\d{2})?", "type": "string" @@ -1254,6 +1239,43 @@ "title": "Curriculum Vitae" }, "design": { + "default": { + "theme": "classic", + "font": "SourceSans3", + "font_size": "10pt", + "page_size": "a4paper", + "primary_color": "#004f90", + "date_and_location_width": "4.1 cm", + "text_alignment": "left-aligned", + "show_timespan_in": [], + "show_last_updated_date": true, + "header_font_size": "30 pt", + "margins": { + "entry_area": { + "left_and_right": "0.2 cm", + "vertical_between": "0.12 cm" + }, + "header": { + "bottom": "0.2 cm", + "vertical_between_name_and_connections": "0.2 cm" + }, + "highlights_area": { + "left": "0.4 cm", + "top": "0.10 cm", + "vertical_between_bullet_points": "0.10 cm" + }, + "page": { + "bottom": "2 cm", + "left": "1.24 cm", + "right": "1.24 cm", + "top": "2 cm" + }, + "section_title": { + "bottom": "0.2 cm", + "top": "0.2 cm" + } + } + }, "description": "The design information of the CV.", "discriminator": { "mapping": { @@ -1270,8 +1292,7 @@ } }, "required": [ - "cv", - "design" + "cv" ], "title": "RenderCV", "type": "object",