Translating Entity resource

This commit is contained in:
2023-03-12 13:07:10 +01:00
parent ad19a50346
commit 8319fa9fac
3 changed files with 27 additions and 20 deletions

View File

@@ -6,8 +6,8 @@ from pydantic import BaseModel, Field, validator
class CrudDocument(Document):
_id: str
created_at: datetime = Field(default=datetime.utcnow(), nullable=False)
updated_at: datetime = Field(default_factory=datetime.utcnow, nullable=False)
created_at: datetime = Field(default=datetime.utcnow(), nullable=False, title="Créé le")
updated_at: datetime = Field(default_factory=datetime.utcnow, nullable=False, title="Modifié le")
@validator("label", always=True, check_fields=False)
def generate_label(cls, v, values, **kwargs):

View File

@@ -15,15 +15,16 @@ class EntityType(BaseModel):
class Individual(EntityType):
type: Literal['individual'] = 'individual'
firstname: Indexed(str)
middlename: Indexed(str) = ""
lastname: Indexed(str)
firstname: Indexed(str) = Field(title='Prénom')
middlename: Indexed(str) = Field(default="", title='Autres prénoms')
lastname: Indexed(str) = Field(title='Nom de famille')
surnames: List[Indexed(str)] = Field(
default=[],
props={"items-per-row": "4", "numbered": True}
props={"items-per-row": "4", "numbered": True},
title="Surnoms"
)
day_of_birth: date
place_of_birth: str = ""
day_of_birth: date = Field(title='Date de naissance')
place_of_birth: str = Field(default="", title='Lieu de naissance')
@property
@@ -47,22 +48,22 @@ class Employee(BaseModel):
class Corporation(EntityType):
type: Literal['corporation'] = 'corporation'
title: Indexed(str)
activity: Indexed(str)
employees: List[Employee] = Field(default=[])
title: Indexed(str) = Field(title='Dénomination sociale')
activity: Indexed(str) = Field(title='Activité')
employees: List[Employee] = Field(default=[], title='Employés')
class Institution(EntityType):
class Institution(Corporation):
type: Literal['institution'] = 'institution'
title: Indexed(str)
activity: Indexed(str)
employees: List[Employee] = Field(default=[])
class Entity(CrudDocument):
"""
Fiche d'un client
"""
entity_data: Individual | Corporation | Institution = Field(..., discriminator='type')
label: str = None
address: Optional[str] = ""
address: str = Field(default="", title='Adresse')
@validator("label", always=True)
def generate_label(cls, v, values, **kwargs):
@@ -78,3 +79,10 @@ class Entity(CrudDocument):
else datetime(year=dt.year, month=dt.month, day=dt.day,
hour=0, minute=0, second=0)
}
class Config:
title = 'Client'
@classmethod
def get_create_resource(cls):
print('coucou')

View File

@@ -11,9 +11,8 @@ class EntityRead(Entity):
class EntityCreate(Writer):
entity_data: Individual | Corporation | Institution = Field(..., discriminator='type')
address: Optional[str] = ""
address: str = Field(default="", title='Adresse')
class EntityUpdate(BaseModel):
entity_data: Individual | Corporation | Institution = Field(..., discriminator='type')
address: Optional[str] = ""
class EntityUpdate(EntityCreate):
pass