diff --git a/back/app/contract/print/__init__.py b/back/app/contract/print/__init__.py index 0f60f334..43f90058 100644 --- a/back/app/contract/print/__init__.py +++ b/back/app/contract/print/__init__.py @@ -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) diff --git a/back/app/contract/print/templates/content.html b/back/app/contract/print/templates/content.html index c7fdff47..b5ea9315 100644 --- a/back/app/contract/print/templates/content.html +++ b/back/app/contract/print/templates/content.html @@ -8,7 +8,7 @@

Conditions générales & particulières

- {% for provision in draft.provisions %} + {% for provision in contract.provisions %}

Article {{loop.index}} - {{ provision.title|safe }}

{{ provision.body|safe }}

@@ -17,11 +17,11 @@ diff --git a/back/app/contract/print/templates/frontpage.html b/back/app/contract/print/templates/frontpage.html index 4aecf4f4..9f170be4 100644 --- a/back/app/contract/print/templates/frontpage.html +++ b/back/app/contract/print/templates/frontpage.html @@ -12,12 +12,12 @@ Cooper, Hillman & Toshi LLP
6834 Innocence Boulevard
LOS SANTOS - SA
consulting@cht.law.com
-

{{ draft.title|upper }}

+

{{ contract.title|upper }}

Introduction

-

Le {{ draft.date }} à {{ draft.location}}

+

Le {{ contract.date.strftime('%d/%m/%Y') }} à {{ contract.location}}

Entre les soussignés :

- {% for party in draft.parties %} + {% for party in contract.parties %}
{% if not loop.first %}

ET

diff --git a/back/app/contract/print/templates/print.html b/back/app/contract/print/templates/print.html index 697ac923..4e105e48 100644 --- a/back/app/contract/print/templates/print.html +++ b/back/app/contract/print/templates/print.html @@ -11,13 +11,13 @@ Cooper, Hillman & Toshi LLP
6834 Innocence Boulevard
LOS SANTOS - SA
consulting@cht.law.com -

{{ draft.title|upper }}

+

{{ contract.title|upper }}

Introduction

-

Le {{ draft.date }} à {{ draft.location}}

+

Le {{ contract.date.strftime('%d/%m/%Y') }} à {{ contract.location}}

Entre les soussignés :

- {% for party in draft.parties %} + {% for party in contract.parties %}
{% if not loop.first %}

ET

@@ -47,7 +47,7 @@

Conditions générales & particulières

- {% for provision in draft.provisions %} + {% for provision in contract.provisions %}

Article {{loop.index}} - {{ provision.title|safe }}

{{ provision.body|safe }}

@@ -56,11 +56,11 @@ diff --git a/back/app/contract/print/templates/styles.css b/back/app/contract/print/templates/styles.css index 2e838af2..2807d7d4 100644 --- a/back/app/contract/print/templates/styles.css +++ b/back/app/contract/print/templates/styles.css @@ -28,7 +28,7 @@ margin: 2cm 2cm 2cm 2cm; counter-increment: page; @bottom-center { - content: "© Cooper, Hillman & Toshi LLC - {{ draft.name }} - Page " counter(page) "/" counter(pages); + content: "© Cooper, Hillman & Toshi LLC - {{ contract.name }} - Page " counter(page) "/" counter(pages); font-size: 0.8em; } background: url('http://{{ static_host }}/assets/watermark.png') no-repeat;