Switching to the registry paradigm

This commit is contained in:
2025-04-15 21:11:54 +02:00
parent c7e946f963
commit 8f9c1833b0
6 changed files with 91 additions and 74 deletions

View File

@@ -12,7 +12,7 @@ from weasyprint.text.fonts import FontConfiguration
from pathlib import Path
from firm.core.depends import get_tenant_db_cursor
from firm.core.depends import get_tenant_registry
from firm.entity.models import Entity
from firm.template.models import ProvisionTemplate
from firm.contract.models import ContractDraft, Contract, ContractStatus, replace_variables_in_value
@@ -87,15 +87,15 @@ def retrieve_signature_png(filepath):
preview_router = APIRouter()
@preview_router.get("/draft/{draft_id}", response_class=HTMLResponse, tags=["Contract Draft"])
async def preview_draft(draft_id: str, db=Depends(get_tenant_db_cursor)) -> str:
draft = await build_model(await ContractDraft.get(db, draft_id))
async def preview_draft(draft_id: str, reg=Depends(get_tenant_registry)) -> str:
draft = await build_model(await ContractDraft.get(reg.db, draft_id))
return await render_print('', draft)
@preview_router.get("/signature/{signature_id}", response_class=HTMLResponse, tags=["Signature"])
async def preview_contract_by_signature(signature_id: UUID, db=Depends(get_tenant_db_cursor)) -> str:
contract = await Contract.find_by_signature_id(db, signature_id)
async def preview_contract_by_signature(signature_id: UUID, reg=Depends(get_tenant_registry)) -> str:
contract = await Contract.find_by_signature_id(reg.db, signature_id)
for p in contract.parties:
if p.signature_affixed:
p.signature_png = retrieve_signature_png(f'media/signatures/{p.signature_uuid}.png')
@@ -104,8 +104,8 @@ async def preview_contract_by_signature(signature_id: UUID, db=Depends(get_tenan
@preview_router.get("/{contract_id}", response_class=HTMLResponse, tags=["Contract"])
async def preview_contract(contract_id: str, db=Depends(get_tenant_db_cursor)) -> str:
contract = await Contract.get(db, contract_id)
async def preview_contract(contract_id: str, reg=Depends(get_tenant_registry)) -> str:
contract = await Contract.get(reg.db, contract_id)
for p in contract.parties:
if p.signature_affixed:
p.signature_png = retrieve_signature_png(f'media/signatures/{p.signature_uuid}.png')
@@ -115,8 +115,8 @@ async def preview_contract(contract_id: str, db=Depends(get_tenant_db_cursor)) -
print_router = APIRouter()
@print_router.get("/pdf/{contract_id}", response_class=FileResponse, tags=["Contract"])
async def create_pdf(contract_id: str, db=Depends(get_tenant_db_cursor)) -> str:
contract = await Contract.get(db, contract_id)
async def create_pdf(contract_id: str, reg=Depends(get_tenant_registry)) -> str:
contract = await Contract.get(reg.db, contract_id)
contract_path = "media/contracts/{}.pdf".format(contract_id)
if not os.path.isfile(contract_path):
if contract.status != ContractStatus.signed:
@@ -133,7 +133,7 @@ async def create_pdf(contract_id: str, db=Depends(get_tenant_db_cursor)) -> str:
html.write_pdf(contract_path, stylesheets=[css], font_config=font_config)
await contract.update_status(db, 'printed')
await contract.update_status(reg.db, 'printed')
return FileResponse(
contract_path,
@@ -142,8 +142,8 @@ async def create_pdf(contract_id: str, db=Depends(get_tenant_db_cursor)) -> str:
@print_router.get("/opengraph/{signature_id}", response_class=HTMLResponse, tags=["Signature"])
async def get_signature_opengraph(signature_id: str, request: Request, db=Depends(get_tenant_db_cursor)) -> str:
contract = await Contract.find_by_signature_id(db, signature_id)
async def get_signature_opengraph(signature_id: str, request: Request, reg=Depends(get_tenant_registry)) -> str:
contract = await Contract.find_by_signature_id(reg.db, signature_id)
signature = contract.get_signature(signature_id)
template = templates.get_template("opengraph.html")