3 def handle_uploaded_file(csv_file):
4 csv_file_name = str(csv_file)
5 data_path = config.getInstance().requireConfig("data_path")
6 path = os.path.join(data_path, csv_file_name)
7 with open(path, 'wb+') as destination:
8 for chunk in csv_file.chunks():
9 destination.write(chunk)
11 def aktualisiere_config(config, data, file):
14 uploaded_file = file.name
15 data_path = config.requireConfig("data_path")
16 # copy briefpapier into data_path
17 with open(os.path.join(data_path, uploaded_file), 'wb+') as destination:
18 for chunk in file.chunks():
19 destination.write(chunk)
20 config.setConfig("briefpapier", uploaded_file)
22 if data["basisbeitrag"]:
23 config.setConfig("beitrag_basis", data["basisbeitrag"])
25 if data["zusatzbeitrag"]:
26 config.setConfig("beitrag_zusatz", data["zusatzbeitrag"])
28 def erstellepdf(text):
29 with open(r'G:\SVBaL\python\eh_util\eh_app\test.tex', 'w') as f: # öffnet ein neues Dokument mit dem Namen test.tex
30 f.write(text) # schreibt in dieses neue Dokument
32 # TODO: AUfruf PDF latex tex -> pdf
34 def erstelle_ehmeldung(data):
35 from PyPDF2 import PdfFileWriter, PdfFileReader
36 from datetime import date
38 from reportlab.pdfgen import canvas
39 from reportlab.lib.pagesizes import letter
42 can = canvas.Canvas(packet, pagesize=letter)
45 can.setFont("Helvetica", 12)
46 can.drawString(205, 618, data["VorZuname"])
47 can.drawString(205, 600, data["VorZunamePartner"])
48 can.drawString(205, 583, data["Wohnanschrift"])
49 can.drawString(205, 566, data["Telefon"])
50 can.drawString(365, 566, data["Email"])
51 can.drawString(205, 549, data["Geburtsdatum"])
52 versichertes_object = data["VersichertesObjekt"]
53 if versichertes_object == "":
54 versichertes_object = data["Wohnanschrift"]
55 can.drawString(205, 500, versichertes_object)
56 can.drawString(193, 466, str(data["AnzahlWohnungen"]))
57 if data["Selbstgenutzt"]:
58 can.drawString(350, 466, "X")
59 if data["Eigentumswohnung"]:
60 can.drawString(188, 449, "X")
61 if data["Gewerblich"]:
62 can.drawString(350, 449, "X")
63 can.drawString(140, 376, date.today().strftime('%d.%m.%Y'))
64 can.drawString(350, 376, "Maschinell erstellt.")
68 #move to the beginning of the StringIO buffer
71 # create a new PDF with Reportlab
72 new_pdf = PdfFileReader(packet)
73 # read your existing PDF
74 existing_pdf = PdfFileReader(open("/home/sparky2021/SVBaL/Aktuell/BeitrittserklarungSVBaL.pdf", "rb"))
75 output = PdfFileWriter()
76 # add the "watermark" (which is the new pdf) on the existing page
77 page = existing_pdf.pages[0]
78 page.mergePage(new_pdf.pages[0])
80 # finally, write "output" to a real file
81 output_stream = open("meldung.pdf", "wb")
82 output.write(output_stream)