changes to the current app
This commit is contained in:
@@ -6,6 +6,7 @@ import time
|
|||||||
import os
|
import os
|
||||||
import tempfile
|
import tempfile
|
||||||
from fpdf import FPDF
|
from fpdf import FPDF
|
||||||
|
from flask import current_app
|
||||||
|
|
||||||
|
|
||||||
def _build_smtp_client():
|
def _build_smtp_client():
|
||||||
@@ -345,15 +346,15 @@ def send_accreditation_email(
|
|||||||
price: str = "250,00",
|
price: str = "250,00",
|
||||||
date: str = "[Ort, Datum]",
|
date: str = "[Ort, Datum]",
|
||||||
software_name: str = "Invario Inventarsystem",
|
software_name: str = "Invario Inventarsystem",
|
||||||
|
invoice_path: str = None
|
||||||
) -> bool:
|
) -> bool:
|
||||||
"""Generiert den Hauptvertrag temporär und versendet ihn zusammen mit Rechnung, AGB & AVV per E-Mail."""
|
"""Generiert den Hauptvertrag temporär und versendet ihn zusammen mit Rechnung, AGB & AVV per E-Mail."""
|
||||||
|
|
||||||
# Clean Sanitization für Dateinamen
|
# 1. Hauptvertrag dynamisch erzeugen
|
||||||
safe_school_name = "".join([c for c in school_name if c.isalnum() or c in (' ', '_', '-')]).rstrip()
|
safe_school_name = "".join([c for c in school_name if c.isalnum() or c in (' ', '_', '-')]).rstrip()
|
||||||
contract_filename = f"Hauptvertrag_Invario_{safe_school_name}.pdf"
|
contract_filename = f"Hauptvertrag_Invario_{safe_school_name}.pdf"
|
||||||
contract_pdf_path = os.path.join(tempfile.gettempdir(), contract_filename)
|
contract_pdf_path = os.path.join(tempfile.gettempdir(), contract_filename)
|
||||||
|
|
||||||
# 1. Hauptvertrag dynamisch erzeugen
|
|
||||||
generate_main_contract_pdf(
|
generate_main_contract_pdf(
|
||||||
school_name=school_name,
|
school_name=school_name,
|
||||||
address=address,
|
address=address,
|
||||||
@@ -363,17 +364,39 @@ def send_accreditation_email(
|
|||||||
output_path=contract_pdf_path
|
output_path=contract_pdf_path
|
||||||
)
|
)
|
||||||
|
|
||||||
# 2. Pfade zu den statischen Dokumenten
|
# 2. Statischen Ordner aus Flask dynamisch ermitteln (verhindert Pfadfehler im Container)
|
||||||
agb_pdf_path = os.path.join("/opt", "Key-service-Server", "Website", "static", "download", "AGB Invario.pdf")
|
if current_app:
|
||||||
avv_pdf_path = os.path.join("/opt", "Key-service-Server", "Website", "static", "download", "AVV Invario.pdf")
|
static_dir = current_app.static_folder
|
||||||
|
else:
|
||||||
|
static_dir = os.path.join(os.getcwd(), "static")
|
||||||
|
|
||||||
# 3. E-Mail Inhalte anpassen
|
# Hilfsfunktion zur flexiblen Pfadfindung ('download' vs 'downloads')
|
||||||
|
def get_valid_pdf_path(filename):
|
||||||
|
possible_paths = [
|
||||||
|
os.path.join(static_dir, "downloads", filename),
|
||||||
|
os.path.join(static_dir, "download", filename),
|
||||||
|
os.path.join("/opt/Key-service-Server/Website/static/downloads", filename),
|
||||||
|
os.path.join("/opt/Key-service-Server/Website/static/download", filename),
|
||||||
|
]
|
||||||
|
for path in possible_paths:
|
||||||
|
if os.path.exists(path):
|
||||||
|
return path
|
||||||
|
return None
|
||||||
|
|
||||||
|
agb_pdf_path = get_valid_pdf_path("AGB Invario.pdf")
|
||||||
|
avv_pdf_path = get_valid_pdf_path("AVV Invario.pdf")
|
||||||
|
|
||||||
|
# Standard-Musterrechnung suchen, falls kein Pfad explizit übergeben wurde
|
||||||
|
if not invoice_path:
|
||||||
|
invoice_path = get_valid_pdf_path("rechnung_INV-20260730-100002-577983.pdf")
|
||||||
|
|
||||||
|
# 3. E-Mail Inhalte
|
||||||
subject = "Ihre Zugangsdaten und Unterlagen für Invario"
|
subject = "Ihre Zugangsdaten und Unterlagen für Invario"
|
||||||
|
|
||||||
text_note = (
|
text_note = (
|
||||||
f"Sehr geehrte/r {username},\n\n"
|
f"Sehr geehrte/r {username},\n\n"
|
||||||
"Vielen Dank für Ihre Akkreditierung bei Invario. "
|
"Vielen Dank für Ihre Akkreditierung bei Invario. "
|
||||||
"Im Anhang finden Sie Ihre Rechnung, den Hauptvertrag sowie die AGB und den AVV.\n\n"
|
"Im Anhang finden Sie Ihre Unterlagen (Hauptvertrag, Rechnung, AGB und AVV).\n\n"
|
||||||
f"Ihre Zugangsdaten:\n"
|
f"Ihre Zugangsdaten:\n"
|
||||||
f"Domain: https://{domain}\n"
|
f"Domain: https://{domain}\n"
|
||||||
f"Benutzername: {username}\n"
|
f"Benutzername: {username}\n"
|
||||||
@@ -385,7 +408,7 @@ def send_accreditation_email(
|
|||||||
<div style="font-family: Arial, Helvetica, sans-serif; color: #333333;">
|
<div style="font-family: Arial, Helvetica, sans-serif; color: #333333;">
|
||||||
<h2 style="color: #2c3e50; margin-top: 0;">Willkommen bei Invario!</h2>
|
<h2 style="color: #2c3e50; margin-top: 0;">Willkommen bei Invario!</h2>
|
||||||
<p style="font-size: 15px; line-height: 1.6;">
|
<p style="font-size: 15px; line-height: 1.6;">
|
||||||
Vielen Dank für Ihre Akkreditierung. Im Anhang finden Sie Ihre Rechnung, den Hauptvertrag sowie die AGB und den AVV.
|
Vielen Dank für Ihre Akkreditierung. Im Anhang finden Sie Ihren Hauptvertrag, Ihre Rechnung sowie AGB und AVV.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<h3 style="color: #2c3e50;">Ihre Zugangsdaten:</h3>
|
<h3 style="color: #2c3e50;">Ihre Zugangsdaten:</h3>
|
||||||
@@ -401,25 +424,28 @@ def send_accreditation_email(
|
|||||||
</div>
|
</div>
|
||||||
"""
|
"""
|
||||||
|
|
||||||
# 4. Vorhandene Anhänge einsammeln
|
# 4. Vorhandene Anhänge sammeln
|
||||||
attachments = []
|
attachments = []
|
||||||
|
|
||||||
# Hauptvertrag anfügen
|
|
||||||
if os.path.exists(contract_pdf_path):
|
if os.path.exists(contract_pdf_path):
|
||||||
attachments.append(contract_pdf_path)
|
attachments.append(contract_pdf_path)
|
||||||
|
|
||||||
# AGB & AVV anfügen
|
if invoice_path and os.path.exists(invoice_path):
|
||||||
if os.path.exists(agb_pdf_path):
|
attachments.append(invoice_path)
|
||||||
|
else:
|
||||||
|
print("[WARNING] Keine Rechnungs-PDF gefunden.")
|
||||||
|
|
||||||
|
if agb_pdf_path:
|
||||||
attachments.append(agb_pdf_path)
|
attachments.append(agb_pdf_path)
|
||||||
else:
|
else:
|
||||||
print(f"[WARNING] AGB unter {agb_pdf_path} nicht gefunden.")
|
print(f"[WARNING] AGB unter static/(downloads) nicht gefunden.")
|
||||||
|
|
||||||
if os.path.exists(avv_pdf_path):
|
if avv_pdf_path:
|
||||||
attachments.append(avv_pdf_path)
|
attachments.append(avv_pdf_path)
|
||||||
else:
|
else:
|
||||||
print(f"[WARNING] AVV unter {avv_pdf_path} nicht gefunden.")
|
print(f"[WARNING] AVV unter static/(downloads) nicht gefunden.")
|
||||||
|
|
||||||
# 5. E-Mail versenden & temporäre Datei aufräumen
|
# 5. E-Mail versenden & temporären Vertrag aufräumen
|
||||||
try:
|
try:
|
||||||
success = send(recipient, subject, text_body=text_note, html_body=html_note, attachments=attachments)
|
success = send(recipient, subject, text_body=text_note, html_body=html_note, attachments=attachments)
|
||||||
return success
|
return success
|
||||||
|
|||||||
Reference in New Issue
Block a user