]> wagnertech.de Git - SVBaL.git/blob - python/eh_util/eh_app/AWK/routines.py
Fehlermeldung kommt jetzt gar nicht mehr, da sich 0 nicht als Wert in
[SVBaL.git] / python / eh_util / eh_app / AWK / routines.py
1 import os
2 from eh_app.AWK import config
3 '''
4 def handle_uploaded_file(csv_file):
5     csv_file_name = str(csv_file)
6     data_path = config.getInstance().requireConfig("data_path")
7     path = os.path.join(data_path, csv_file_name)
8     with open(path, 'wb+') as destination:
9         for chunk in csv_file.chunks():
10             destination.write(chunk)
11 '''
12 def aktualisiere_config(config, data, file):
13
14     if file:
15         uploaded_file = file.name
16         data_path = config.requireConfig("data_path")
17         # copy briefpapier into data_path
18         with open(os.path.join(data_path, uploaded_file), 'wb+') as destination:
19             for chunk in file.chunks():
20                 destination.write(chunk)
21         config.setConfig("briefpapier", uploaded_file)
22
23     if data["basisbeitrag"]:
24         config.setConfig("beitrag_basis", data["basisbeitrag"])
25
26     if data["zusatzbeitrag"]:
27         config.setConfig("beitrag_zusatz", data["zusatzbeitrag"])
28     
29 def erstelle_ehmeldung(data):
30     from PyPDF2 import PdfFileWriter, PdfFileReader
31     from datetime import date
32     import io
33     from reportlab.pdfgen import canvas
34     from reportlab.lib.pagesizes import letter
35    
36     packet = io.BytesIO()
37     can = canvas.Canvas(packet, pagesize=letter)
38     
39     # Adressfeld
40     can.setFont("Helvetica", 14)
41     can.drawString(80, 770, "Siedlervereinigung Berg am Laim")
42     can.setFont("Helvetica", 12)
43     can.drawString(205, 618, data["VorZuname"])
44     can.drawString(205, 600, data["VorZunamePartner"])
45     can.drawString(205, 583, data["Wohnanschrift"])
46     can.drawString(205, 566, data["Telefon"])
47     can.drawString(365, 566, data["Email"])
48     can.drawString(205, 549, data["Geburtsdatum"])
49     versichertes_object = data["VersichertesObjekt"]
50     if versichertes_object == "":
51         versichertes_object = data["Wohnanschrift"]
52     can.drawString(205, 500, versichertes_object)
53     can.drawString(193, 466, str(data["AnzahlWohnungen"]))
54     if data["Selbstgenutzt"]:
55         can.drawString(360, 466, "X")
56     if data["Eigentumswohnung"]:
57         can.drawString(192, 449, "X")
58     if data["Gewerblich"]:
59         can.drawString(360, 449, "X")
60     can.drawString(140, 376, date.today().strftime('%d.%m.%Y'))
61     can.drawString(350, 376, "Maschinell erstellt.")
62         
63     can.save()
64     
65     #move to the beginning of the StringIO buffer
66     packet.seek(0)
67     
68     # create a new PDF with Reportlab
69     new_pdf = PdfFileReader(packet)
70     # read your existing PDF
71     existing_pdf = PdfFileReader(open("/home/sparky2021/SVBaL/Aktuell/BeitrittserklarungSVBaL.pdf", "rb"))
72     output = PdfFileWriter()
73     # add the "watermark" (which is the new pdf) on the existing page
74     page = existing_pdf.pages[0]
75     page.mergePage(new_pdf.pages[0])
76     output.addPage(page)
77     # finally, write "output" to a real file
78     output_stream = open("meldung.pdf", "wb")
79     output.write(output_stream)
80     output_stream.close()
81       
82 def pdfs_erstellen(request, verein):
83     from django.template import loader
84     
85     # lese alle Miglieder
86     cf = config.getInstance("svbal")
87     cf.setConfig("DataFile", "../../Test/etc/Export.csv")
88     from eh_app.qmodels import Mitglied
89     mm = Mitglied.objects.all()
90     template = loader.get_template("brief.tex")
91     
92     from eh_app.AWK.pdf_ersteller import PdfErsteller
93     pe = PdfErsteller(request, template, "../../latex")
94     
95     # Erstelle PDFs
96     for m in mm:
97         pe.erstellepdf(m)
98