From 8319fa9fac325f4e8fdb23338159ba5957ffe653 Mon Sep 17 00:00:00 2001 From: ewandor Date: Sun, 12 Mar 2023 13:07:10 +0100 Subject: [PATCH] Translating Entity resource --- back/app/core/models.py | 4 ++-- back/app/entity/models.py | 36 ++++++++++++++++++++++-------------- back/app/entity/schemas.py | 7 +++---- 3 files changed, 27 insertions(+), 20 deletions(-) diff --git a/back/app/core/models.py b/back/app/core/models.py index 205f69ba..0d69d1ef 100644 --- a/back/app/core/models.py +++ b/back/app/core/models.py @@ -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): diff --git a/back/app/entity/models.py b/back/app/entity/models.py index 0690af0f..14ce4592 100644 --- a/back/app/entity/models.py +++ b/back/app/entity/models.py @@ -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') diff --git a/back/app/entity/schemas.py b/back/app/entity/schemas.py index 6ff96e5d..7adcfe38 100644 --- a/back/app/entity/schemas.py +++ b/back/app/entity/schemas.py @@ -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