updating contract preview
This commit is contained in:
@@ -2,6 +2,8 @@ from fastapi import APIRouter
|
||||
from fastapi.responses import HTMLResponse, FileResponse
|
||||
from fastapi.templating import Jinja2Templates
|
||||
|
||||
from beanie.operators import ElemMatch
|
||||
|
||||
from weasyprint import HTML, CSS
|
||||
from weasyprint.text.fonts import FontConfiguration
|
||||
|
||||
@@ -9,7 +11,7 @@ from pathlib import Path
|
||||
|
||||
from app.entity.models import Entity
|
||||
from app.template.models import ProvisionTemplate
|
||||
from ..schemas import ContractDraft
|
||||
from ..schemas import ContractDraft, Contract
|
||||
|
||||
|
||||
async def build_model(model):
|
||||
@@ -47,10 +49,10 @@ print_router = APIRouter()
|
||||
templates = Jinja2Templates(directory=str(BASE_PATH / "templates"))
|
||||
|
||||
|
||||
async def render_print(host, draft, lawyer):
|
||||
async def render_print(host, contract, lawyer):
|
||||
template = templates.get_template("print.html")
|
||||
return template.render({
|
||||
"draft": draft,
|
||||
"contract": contract,
|
||||
"lawyer": lawyer,
|
||||
"static_host": host
|
||||
})
|
||||
@@ -64,15 +66,19 @@ async def render_css(host, draft):
|
||||
})
|
||||
|
||||
|
||||
@print_router.get("/", response_class=HTMLResponse)
|
||||
async def create() -> str:
|
||||
draft = await build_model(await ContractDraft.get("63e92534aafed8b509f229c4"))
|
||||
@print_router.get("/preview/{signatureId}", response_class=HTMLResponse)
|
||||
async def create(signatureId: str) -> str:
|
||||
# await build_model(await ContractDraft.get("63e92534aafed8b509f229c4"))
|
||||
|
||||
crit = ElemMatch(Contract.parties, {"signature_uuid": "85476dc8-8b98-4f25-8e7d-1542c152074f"})
|
||||
contract = await Contract.find_one(crit)
|
||||
|
||||
lawyer = {
|
||||
"firstname": "Nathaniel",
|
||||
"lastname": "Toshi",
|
||||
}
|
||||
|
||||
return await render_print('localhost', draft, lawyer)
|
||||
return await render_print('localhost', contract, lawyer)
|
||||
|
||||
|
||||
@print_router.get("/pdf", response_class=FileResponse)
|
||||
|
||||
Reference in New Issue
Block a user