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)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
<div class="content">
|
||||
<h2>Conditions générales & particulières</h2>
|
||||
|
||||
{% for provision in draft.provisions %}
|
||||
{% for provision in contract.provisions %}
|
||||
<div class="provision">
|
||||
<h3>Article {{loop.index}} - {{ provision.title|safe }}</h3>
|
||||
<p>{{ provision.body|safe }}</p>
|
||||
@@ -17,11 +17,11 @@
|
||||
|
||||
<div class="footer">
|
||||
<hr/>
|
||||
<p>À {{ draft.location }} le {{ draft.date }}</p>
|
||||
<p>À {{ contract.location }} le {{ contract.date.strftime('%d/%m/%Y') }}</p>
|
||||
<p class="mention">(Signatures précédée de la mention « Lu et approuvé »)</p>
|
||||
<table class="signatures">
|
||||
<tr>
|
||||
{% for party in draft.parties %}<td>{{ party.part|safe }}:</td>{% endfor %}
|
||||
{% for party in contract.parties %}<td>{{ party.part|safe }}:</td>{% endfor %}
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@@ -12,12 +12,12 @@
|
||||
<td id="office-info">Cooper, Hillman & Toshi LLP<br />6834 Innocence Boulevard<br />LOS SANTOS - SA<br /><a href="#">consulting@cht.law.com</a></td>
|
||||
</tr></table>
|
||||
</div>
|
||||
<h1>{{ draft.title|upper }}</h1>
|
||||
<h1>{{ contract.title|upper }}</h1>
|
||||
<div class="intro">
|
||||
<h2>Introduction</h2>
|
||||
<p>Le {{ draft.date }} à {{ draft.location}}</p>
|
||||
<p>Le {{ contract.date.strftime('%d/%m/%Y') }} à {{ contract.location}}</p>
|
||||
<p>Entre les soussignés :</p>
|
||||
{% for party in draft.parties %}
|
||||
{% for party in contract.parties %}
|
||||
<div class="party">
|
||||
{% if not loop.first %}
|
||||
<p>ET</p>
|
||||
|
||||
@@ -11,13 +11,13 @@
|
||||
<td><img id="top-logo" src="http://{{ static_host }}/assets/logotransparent.png" alt="Cooper, Hillman & Toshi logo"></td>
|
||||
<td id="office-info">Cooper, Hillman & Toshi LLP<br />6834 Innocence Boulevard<br />LOS SANTOS - SA<br /><a href="#">consulting@cht.law.com</a></td>
|
||||
</tr></table>
|
||||
<h1>{{ draft.title|upper }}</h1>
|
||||
<h1>{{ contract.title|upper }}</h1>
|
||||
</div>
|
||||
<div class="intro">
|
||||
<h2>Introduction</h2>
|
||||
<p>Le {{ draft.date }} à {{ draft.location}}</p>
|
||||
<p>Le {{ contract.date.strftime('%d/%m/%Y') }} à {{ contract.location}}</p>
|
||||
<p>Entre les soussignés :</p>
|
||||
{% for party in draft.parties %}
|
||||
{% for party in contract.parties %}
|
||||
<div class="party">
|
||||
{% if not loop.first %}
|
||||
<p>ET</p>
|
||||
@@ -47,7 +47,7 @@
|
||||
<div class="content">
|
||||
<h2>Conditions générales & particulières</h2>
|
||||
|
||||
{% for provision in draft.provisions %}
|
||||
{% for provision in contract.provisions %}
|
||||
<div class="provision">
|
||||
<h3>Article {{loop.index}} - {{ provision.title|safe }}</h3>
|
||||
<p>{{ provision.body|safe }}</p>
|
||||
@@ -56,11 +56,11 @@
|
||||
|
||||
<div class="footer">
|
||||
<hr/>
|
||||
<p>À {{ draft.location }} le {{ draft.date }}</p>
|
||||
<p>À {{ contract.location }} le {{ contract.date.strftime('%d/%m/%Y') }}</p>
|
||||
<p class="mention">(Signatures précédée de la mention « Lu et approuvé »)</p>
|
||||
<table class="signatures">
|
||||
<tr>
|
||||
{% for party in draft.parties %}<td>{{ party.part|safe }}:</td>{% endfor %}
|
||||
{% for party in contract.parties %}<td>{{ party.part|safe }}:</td>{% endfor %}
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user