From 3591da05f7062112f3518a31ebc34ef0163aff35 Mon Sep 17 00:00:00 2001 From: Xtrah <12988459+Xtrah@users.noreply.github.com> Date: Tue, 30 May 2023 14:04:54 +0200 Subject: [PATCH] move comment to the bottom, handle newlines and set max characters --- kaaf/handler.py | 10 ++++++++-- kaaf/mail.py | 4 ++-- webapp/components/Form.tsx | 23 ++++++++++++----------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/kaaf/handler.py b/kaaf/handler.py index a4ce837..129e0bb 100644 --- a/kaaf/handler.py +++ b/kaaf/handler.py @@ -26,10 +26,10 @@ class UnsupportedFileException(Exception): "distance": "Antall kilometer:", "team": "Reisefølge:", "numberOfTravelers": "Antall reisende:", - "comment": "Kommentar:", "accountNumber": "Kontonummer:", "amount": "Beløp:", "maxRefund": "(Autogenerert) Maks HS støtte:", + "comment": "Kommentar:", } temporary_files = [] @@ -145,7 +145,7 @@ def create_pdf(data, signature=None, images=None): fitz.Point(50, 150), left_text, fontname="Helvetica-Bold", fontsize=11 ) page.insert_text( - fitz.Point(250, 150), right_text, fontname="Helvetica", fontsize=11 + fitz.Point(240, 150), right_text, fontname="Helvetica", fontsize=11 ) # Add the signature image @@ -246,6 +246,12 @@ def handle(data): data["amount"] = data["amount"].replace(".", ",") # Norwegian standard is comma as decimal separator data["maxRefund"] = calculate_traveling_refund(data) + data["comment"] = data["comment"].replace("\n", " ") # Strip newlines from comment + # If comment is longer than 50 characters, add newline after every 50 characters to avoid overflowing the pdf + if len(data["comment"]) > 50: + data["comment"] = "\n".join( + data["comment"][i : i + 50] for i in range(0, len(data["comment"]), 50) + ) try: file = create_pdf(data, data["signature"], data["images"]) diff --git a/kaaf/mail.py b/kaaf/mail.py index de169ad..8f6c615 100644 --- a/kaaf/mail.py +++ b/kaaf/mail.py @@ -44,12 +44,12 @@ def create_mail(msg, body): text += f'Antall kilometer: {body.get("distance", "")}\n' text += f'Reisefølge: {body.get("team", "")}\n' text += f'Antall reisende: {body.get("numberOfTravelers", "")}\n' - text += f'Kommentar: {body.get("comment", "")}\n' text += f'Kontonummer: {body.get("accountNumber", "")}\n' text += f'Beløp: {body.get("amount", "")}\n' text += f'(Autogenerert) Maks HS støtte: {body.get("maxRefund", "")}\n' + text += f'Kommentar: {body.get("comment", "")}\n' text += f'\n' - text += f"Reiseregning er generert og vedlagt. Ved spørsmål ta kontakt med kasserer@ntnui.no!" + text += f"Reiseregning er generert og vedlagt. Ved spørsmål, ta kontakt med kasserer@ntnui.no!" msg.attach(MIMEText(text)) diff --git a/webapp/components/Form.tsx b/webapp/components/Form.tsx index 86f0e79..c6d9dba 100644 --- a/webapp/components/Form.tsx +++ b/webapp/components/Form.tsx @@ -91,7 +91,7 @@ const Form = (): JSX.Element => { value={mailfrom} required updateForm={setMailfrom} - helperText="Din kopi av skjema går hit" + helperText="Din kopi av skjema sendes hit" /> { name="Antall kilometer" required value={distance} + type="number" updateForm={setDistance} adornment={'km'} helperText="Uavhengig av reisemetode" /> { /> - @@ -200,6 +193,14 @@ const Form = (): JSX.Element => { adornment={'kr'} helperText="Totalsum av utlegg" /> +