updating contract preview

This commit is contained in:
2023-03-06 20:22:41 +01:00
parent 9035824248
commit 8bb3d0f44e
5 changed files with 26 additions and 20 deletions

View File

@@ -2,6 +2,8 @@ from fastapi import APIRouter
from fastapi.responses import HTMLResponse, FileResponse from fastapi.responses import HTMLResponse, FileResponse
from fastapi.templating import Jinja2Templates from fastapi.templating import Jinja2Templates
from beanie.operators import ElemMatch
from weasyprint import HTML, CSS from weasyprint import HTML, CSS
from weasyprint.text.fonts import FontConfiguration from weasyprint.text.fonts import FontConfiguration
@@ -9,7 +11,7 @@ from pathlib import Path
from app.entity.models import Entity from app.entity.models import Entity
from app.template.models import ProvisionTemplate from app.template.models import ProvisionTemplate
from ..schemas import ContractDraft from ..schemas import ContractDraft, Contract
async def build_model(model): async def build_model(model):
@@ -47,10 +49,10 @@ print_router = APIRouter()
templates = Jinja2Templates(directory=str(BASE_PATH / "templates")) 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") template = templates.get_template("print.html")
return template.render({ return template.render({
"draft": draft, "contract": contract,
"lawyer": lawyer, "lawyer": lawyer,
"static_host": host "static_host": host
}) })
@@ -64,15 +66,19 @@ async def render_css(host, draft):
}) })
@print_router.get("/", response_class=HTMLResponse) @print_router.get("/preview/{signatureId}", response_class=HTMLResponse)
async def create() -> str: async def create(signatureId: str) -> str:
draft = await build_model(await ContractDraft.get("63e92534aafed8b509f229c4")) # 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 = { lawyer = {
"firstname": "Nathaniel", "firstname": "Nathaniel",
"lastname": "Toshi", "lastname": "Toshi",
} }
return await render_print('localhost', draft, lawyer) return await render_print('localhost', contract, lawyer)
@print_router.get("/pdf", response_class=FileResponse) @print_router.get("/pdf", response_class=FileResponse)

View File

@@ -8,7 +8,7 @@
<div class="content"> <div class="content">
<h2>Conditions g&eacute;n&eacute;rales & particuli&egrave;res</h2> <h2>Conditions g&eacute;n&eacute;rales & particuli&egrave;res</h2>
{% for provision in draft.provisions %} {% for provision in contract.provisions %}
<div class="provision"> <div class="provision">
<h3>Article {{loop.index}} - {{ provision.title|safe }}</h3> <h3>Article {{loop.index}} - {{ provision.title|safe }}</h3>
<p>{{ provision.body|safe }}</p> <p>{{ provision.body|safe }}</p>
@@ -17,11 +17,11 @@
<div class="footer"> <div class="footer">
<hr/> <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> <p class="mention">(Signatures précédée de la mention « Lu et approuvé »)</p>
<table class="signatures"> <table class="signatures">
<tr> <tr>
{% for party in draft.parties %}<td>{{ party.part|safe }}:</td>{% endfor %} {% for party in contract.parties %}<td>{{ party.part|safe }}:</td>{% endfor %}
</tr> </tr>
</table> </table>
</div> </div>

View File

@@ -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> <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> </tr></table>
</div> </div>
<h1>{{ draft.title|upper }}</h1> <h1>{{ contract.title|upper }}</h1>
<div class="intro"> <div class="intro">
<h2>Introduction</h2> <h2>Introduction</h2>
<p>Le {{ draft.date }} &agrave; {{ draft.location}}</p> <p>Le {{ contract.date.strftime('%d/%m/%Y') }} &agrave; {{ contract.location}}</p>
<p>Entre les soussign&eacute;s :</p> <p>Entre les soussign&eacute;s :</p>
{% for party in draft.parties %} {% for party in contract.parties %}
<div class="party"> <div class="party">
{% if not loop.first %} {% if not loop.first %}
<p>ET</p> <p>ET</p>

View File

@@ -11,13 +11,13 @@
<td><img id="top-logo" src="http://{{ static_host }}/assets/logotransparent.png" alt="Cooper, Hillman & Toshi logo"></td> <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> <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> </tr></table>
<h1>{{ draft.title|upper }}</h1> <h1>{{ contract.title|upper }}</h1>
</div> </div>
<div class="intro"> <div class="intro">
<h2>Introduction</h2> <h2>Introduction</h2>
<p>Le {{ draft.date }} &agrave; {{ draft.location}}</p> <p>Le {{ contract.date.strftime('%d/%m/%Y') }} &agrave; {{ contract.location}}</p>
<p>Entre les soussign&eacute;s :</p> <p>Entre les soussign&eacute;s :</p>
{% for party in draft.parties %} {% for party in contract.parties %}
<div class="party"> <div class="party">
{% if not loop.first %} {% if not loop.first %}
<p>ET</p> <p>ET</p>
@@ -47,7 +47,7 @@
<div class="content"> <div class="content">
<h2>Conditions g&eacute;n&eacute;rales & particuli&egrave;res</h2> <h2>Conditions g&eacute;n&eacute;rales & particuli&egrave;res</h2>
{% for provision in draft.provisions %} {% for provision in contract.provisions %}
<div class="provision"> <div class="provision">
<h3>Article {{loop.index}} - {{ provision.title|safe }}</h3> <h3>Article {{loop.index}} - {{ provision.title|safe }}</h3>
<p>{{ provision.body|safe }}</p> <p>{{ provision.body|safe }}</p>
@@ -56,11 +56,11 @@
<div class="footer"> <div class="footer">
<hr/> <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> <p class="mention">(Signatures précédée de la mention « Lu et approuvé »)</p>
<table class="signatures"> <table class="signatures">
<tr> <tr>
{% for party in draft.parties %}<td>{{ party.part|safe }}:</td>{% endfor %} {% for party in contract.parties %}<td>{{ party.part|safe }}:</td>{% endfor %}
</tr> </tr>
</table> </table>
</div> </div>

View File

@@ -28,7 +28,7 @@
margin: 2cm 2cm 2cm 2cm; margin: 2cm 2cm 2cm 2cm;
counter-increment: page; counter-increment: page;
@bottom-center { @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; font-size: 0.8em;
} }
background: url('http://{{ static_host }}/assets/watermark.png') no-repeat; background: url('http://{{ static_host }}/assets/watermark.png') no-repeat;