Translating Entity resource
This commit is contained in:
@@ -6,8 +6,8 @@ from pydantic import BaseModel, Field, validator
|
|||||||
|
|
||||||
class CrudDocument(Document):
|
class CrudDocument(Document):
|
||||||
_id: str
|
_id: str
|
||||||
created_at: datetime = Field(default=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)
|
updated_at: datetime = Field(default_factory=datetime.utcnow, nullable=False, title="Modifié le")
|
||||||
|
|
||||||
@validator("label", always=True, check_fields=False)
|
@validator("label", always=True, check_fields=False)
|
||||||
def generate_label(cls, v, values, **kwargs):
|
def generate_label(cls, v, values, **kwargs):
|
||||||
|
|||||||
@@ -15,15 +15,16 @@ class EntityType(BaseModel):
|
|||||||
|
|
||||||
class Individual(EntityType):
|
class Individual(EntityType):
|
||||||
type: Literal['individual'] = 'individual'
|
type: Literal['individual'] = 'individual'
|
||||||
firstname: Indexed(str)
|
firstname: Indexed(str) = Field(title='Prénom')
|
||||||
middlename: Indexed(str) = ""
|
middlename: Indexed(str) = Field(default="", title='Autres prénoms')
|
||||||
lastname: Indexed(str)
|
lastname: Indexed(str) = Field(title='Nom de famille')
|
||||||
surnames: List[Indexed(str)] = Field(
|
surnames: List[Indexed(str)] = Field(
|
||||||
default=[],
|
default=[],
|
||||||
props={"items-per-row": "4", "numbered": True}
|
props={"items-per-row": "4", "numbered": True},
|
||||||
|
title="Surnoms"
|
||||||
)
|
)
|
||||||
day_of_birth: date
|
day_of_birth: date = Field(title='Date de naissance')
|
||||||
place_of_birth: str = ""
|
place_of_birth: str = Field(default="", title='Lieu de naissance')
|
||||||
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -47,22 +48,22 @@ class Employee(BaseModel):
|
|||||||
|
|
||||||
class Corporation(EntityType):
|
class Corporation(EntityType):
|
||||||
type: Literal['corporation'] = 'corporation'
|
type: Literal['corporation'] = 'corporation'
|
||||||
title: Indexed(str)
|
title: Indexed(str) = Field(title='Dénomination sociale')
|
||||||
activity: Indexed(str)
|
activity: Indexed(str) = Field(title='Activité')
|
||||||
employees: List[Employee] = Field(default=[])
|
employees: List[Employee] = Field(default=[], title='Employés')
|
||||||
|
|
||||||
|
|
||||||
class Institution(EntityType):
|
class Institution(Corporation):
|
||||||
type: Literal['institution'] = 'institution'
|
type: Literal['institution'] = 'institution'
|
||||||
title: Indexed(str)
|
|
||||||
activity: Indexed(str)
|
|
||||||
employees: List[Employee] = Field(default=[])
|
|
||||||
|
|
||||||
|
|
||||||
class Entity(CrudDocument):
|
class Entity(CrudDocument):
|
||||||
|
"""
|
||||||
|
Fiche d'un client
|
||||||
|
"""
|
||||||
entity_data: Individual | Corporation | Institution = Field(..., discriminator='type')
|
entity_data: Individual | Corporation | Institution = Field(..., discriminator='type')
|
||||||
label: str = None
|
label: str = None
|
||||||
address: Optional[str] = ""
|
address: str = Field(default="", title='Adresse')
|
||||||
|
|
||||||
@validator("label", always=True)
|
@validator("label", always=True)
|
||||||
def generate_label(cls, v, values, **kwargs):
|
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,
|
else datetime(year=dt.year, month=dt.month, day=dt.day,
|
||||||
hour=0, minute=0, second=0)
|
hour=0, minute=0, second=0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
title = 'Client'
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def get_create_resource(cls):
|
||||||
|
print('coucou')
|
||||||
|
|||||||
@@ -11,9 +11,8 @@ class EntityRead(Entity):
|
|||||||
|
|
||||||
class EntityCreate(Writer):
|
class EntityCreate(Writer):
|
||||||
entity_data: Individual | Corporation | Institution = Field(..., discriminator='type')
|
entity_data: Individual | Corporation | Institution = Field(..., discriminator='type')
|
||||||
address: Optional[str] = ""
|
address: str = Field(default="", title='Adresse')
|
||||||
|
|
||||||
|
|
||||||
class EntityUpdate(BaseModel):
|
class EntityUpdate(EntityCreate):
|
||||||
entity_data: Individual | Corporation | Institution = Field(..., discriminator='type')
|
pass
|
||||||
address: Optional[str] = ""
|
|
||||||
|
|||||||
Reference in New Issue
Block a user