|
11 | 11 | from models_library.basic_types import ConstrainedStr |
12 | 12 | from models_library.folders import FolderID |
13 | 13 | from models_library.workspaces import WorkspaceID |
14 | | -from pydantic import BaseModel, ConfigDict, Field, HttpUrl, field_validator |
| 14 | +from pydantic import ( |
| 15 | + BaseModel, |
| 16 | + BeforeValidator, |
| 17 | + ConfigDict, |
| 18 | + Field, |
| 19 | + HttpUrl, |
| 20 | + field_validator, |
| 21 | +) |
15 | 22 |
|
16 | 23 | from .basic_regex import DATE_RE, UUID_RE_BASE |
17 | 24 | from .emails import LowerCaseEmailStr |
@@ -65,32 +72,28 @@ class BaseProjectModel(BaseModel): |
65 | 72 | name: str = Field( |
66 | 73 | ..., description="project name", examples=["Temporal Distortion Simulator"] |
67 | 74 | ) |
68 | | - description: str = Field( |
69 | | - ..., |
70 | | - description="longer one-line description about the project", |
71 | | - examples=["Dabbling in temporal transitions ..."], |
72 | | - ) |
73 | | - thumbnail: HttpUrl | None = Field( |
74 | | - ..., |
75 | | - description="url of the project thumbnail", |
76 | | - examples=["https://placeimg.com/171/96/tech/grayscale/?0.jpg"], |
77 | | - ) |
| 75 | + description: Annotated[ |
| 76 | + str, |
| 77 | + BeforeValidator(none_to_empty_str_pre_validator), |
| 78 | + Field( |
| 79 | + ..., |
| 80 | + description="longer one-line description about the project", |
| 81 | + examples=["Dabbling in temporal transitions ..."], |
| 82 | + ), |
| 83 | + ] |
| 84 | + thumbnail: Annotated[ |
| 85 | + HttpUrl | None, |
| 86 | + BeforeValidator(empty_str_to_none_pre_validator), |
| 87 | + Field( |
| 88 | + ..., |
| 89 | + description="url of the project thumbnail", |
| 90 | + examples=["https://placeimg.com/171/96/tech/grayscale/?0.jpg"], |
| 91 | + ), |
| 92 | + ] |
78 | 93 |
|
79 | 94 | creation_date: datetime = Field(...) |
80 | 95 | last_change_date: datetime = Field(...) |
81 | 96 |
|
82 | | - # Pipeline of nodes (SEE projects_nodes.py) |
83 | | - workbench: Annotated[NodesDict, Field(..., description="Project's pipeline")] |
84 | | - |
85 | | - # validators |
86 | | - _empty_thumbnail_is_none = field_validator("thumbnail", mode="before")( |
87 | | - empty_str_to_none_pre_validator |
88 | | - ) |
89 | | - |
90 | | - _none_description_is_empty = field_validator("description", mode="before")( |
91 | | - none_to_empty_str_pre_validator |
92 | | - ) |
93 | | - |
94 | 97 |
|
95 | 98 | class ProjectAtDB(BaseProjectModel): |
96 | 99 | # Model used to READ from database |
|
0 commit comments