|
2 | 2 | Models a study's project document
|
3 | 3 | """
|
4 | 4 | from copy import deepcopy
|
5 |
| -from typing import Dict, List, Optional, Any |
| 5 | +from typing import Any, Dict, List, Optional, Union |
6 | 6 | from uuid import UUID
|
7 | 7 |
|
8 |
| -from pydantic import BaseModel, EmailStr, Extra, Field, HttpUrl |
| 8 | +from pydantic import BaseModel, EmailStr, Extra, Field, HttpUrl, validator |
9 | 9 |
|
10 | 10 | from .basic_regex import DATE_RE
|
11 | 11 | from .projects_access import AccessRights, GroupID
|
@@ -40,7 +40,9 @@ class Project(BaseModel):
|
40 | 40 | description="longer one-line description about the project",
|
41 | 41 | examples=["Dabbling in temporal transitions ..."],
|
42 | 42 | )
|
43 |
| - thumbnail: HttpUrl = Field( |
| 43 | + # NOTE: str is necessary because HttpUrl will not accept and empty string and the |
| 44 | + # frontend sometimes sends this empty string, which is removed by the validator |
| 45 | + thumbnail: Union[str, HttpUrl] = Field( |
44 | 46 | ...,
|
45 | 47 | description="url of the project thumbnail",
|
46 | 48 | examples=["https://placeimg.com/171/96/tech/grayscale/?0.jpg"],
|
@@ -88,9 +90,14 @@ class Project(BaseModel):
|
88 | 90 | quality: Dict[str, Any] = {}
|
89 | 91 |
|
90 | 92 | # Dev only
|
91 |
| - dev: Optional[Dict] = Field( |
92 |
| - description="object used for development purposes only" |
93 |
| - ) |
| 93 | + dev: Optional[Dict] = Field(description="object used for development purposes only") |
| 94 | + |
| 95 | + @classmethod |
| 96 | + @validator("thumbnail") |
| 97 | + def null_thumbnail(cls, v): |
| 98 | + if isinstance(v, str) and v == "": |
| 99 | + return None |
| 100 | + return v |
94 | 101 |
|
95 | 102 | class Config:
|
96 | 103 | description = "Document that stores metadata, pipeline and UI setup of a study"
|
|
0 commit comments