Dynamic lawyer
This commit is contained in:
@@ -114,6 +114,7 @@ class Contract(CrudDocument):
|
||||
props={"items-per-row": "1", "numbered": True}
|
||||
)
|
||||
status: ContractStatus = ContractStatus.published
|
||||
lawyer: Entity
|
||||
location: str
|
||||
date: datetime.date
|
||||
|
||||
|
||||
@@ -46,6 +46,10 @@ async def build_model(model):
|
||||
model = model.dict()
|
||||
model['location'] = "Los Santos, SA"
|
||||
model['date'] = datetime.date(1970, 1, 1)
|
||||
model['lawyer'] = {'entity_data': {
|
||||
"firstname": "prénom avocat",
|
||||
"lastname": "nom avocat",
|
||||
}}
|
||||
return model
|
||||
|
||||
|
||||
@@ -57,58 +61,43 @@ print_router = APIRouter()
|
||||
templates = Jinja2Templates(directory=str(BASE_PATH / "templates"))
|
||||
|
||||
|
||||
async def render_print(host, contract, lawyer):
|
||||
async def render_print(host, contract):
|
||||
template = templates.get_template("print.html")
|
||||
return template.render({
|
||||
"contract": contract,
|
||||
"lawyer": lawyer,
|
||||
"static_host": host
|
||||
})
|
||||
|
||||
|
||||
async def render_css(host, draft):
|
||||
async def render_css(host, contract):
|
||||
template = templates.get_template("styles.css")
|
||||
return template.render({
|
||||
"draft": draft,
|
||||
"contract": contract,
|
||||
"static_host": host
|
||||
})
|
||||
|
||||
|
||||
@print_router.get("/preview/draft/{draftId}", response_class=HTMLResponse)
|
||||
async def create(draftId: str) -> str:
|
||||
async def preview_draft(draftId: str) -> str:
|
||||
draft = await build_model(await ContractDraft.get(draftId))
|
||||
|
||||
lawyer = {
|
||||
"firstname": "Nathaniel",
|
||||
"lastname": "Toshi",
|
||||
}
|
||||
|
||||
return await render_print('localhost', draft, lawyer)
|
||||
return await render_print('localhost', draft)
|
||||
|
||||
|
||||
@print_router.get("/preview/{signature_id}", response_class=HTMLResponse)
|
||||
async def create(signature_id: str) -> str:
|
||||
async def preview_contract(signature_id: str) -> str:
|
||||
crit = ElemMatch(Contract.parties, {"signature_uuid": signature_id})
|
||||
contract = await Contract.find_one(crit)
|
||||
|
||||
lawyer = {
|
||||
"firstname": "Nathaniel",
|
||||
"lastname": "Toshi",
|
||||
}
|
||||
|
||||
return await render_print('localhost', contract, lawyer)
|
||||
return await render_print('localhost', contract)
|
||||
|
||||
|
||||
@print_router.get("/pdf", response_class=FileResponse)
|
||||
async def create_pdf() -> str:
|
||||
draft = await build_model(await ContractDraft.get("63e92534aafed8b509f229c4"))
|
||||
lawyer = {
|
||||
"firstname": "Nathaniel",
|
||||
"lastname": "Toshi",
|
||||
}
|
||||
|
||||
font_config = FontConfiguration()
|
||||
html = HTML(string=await render_print('nginx', draft, lawyer))
|
||||
html = HTML(string=await render_print('nginx', draft))
|
||||
css = CSS(string=await render_css('nginx', draft), font_config=font_config)
|
||||
|
||||
html.write_pdf('out.pdf', stylesheets=[css], font_config=font_config)
|
||||
|
||||
@@ -40,7 +40,7 @@
|
||||
</div>
|
||||
{% endfor %}
|
||||
<p class="part">d'autre part</p>
|
||||
<p>Sous la supervision légale de Maître <strong>{{ lawyer.firstname }} {{ lawyer.lastname }}</strong></p>
|
||||
<p>Sous la supervision légale de Maître <strong>{{ contract.lawyer.entity_data.firstname }} {{ contract.lawyer.entity_data.lastname }}</strong></p>
|
||||
<p>Il a été convenu l'exécution des prestations ci-dessous, conformément aux conditions générales et particulières ci-après:</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -51,6 +51,7 @@ class PartyRead(BaseModel):
|
||||
|
||||
class ContractRead(Contract):
|
||||
parties: List[PartyRead]
|
||||
lawyer: EntityRead
|
||||
|
||||
|
||||
class ContractCreate(Writer):
|
||||
|
||||
Reference in New Issue
Block a user