forked from hd016/business_analytics_systementwicklung
-
Notifications
You must be signed in to change notification settings - Fork 0
/
API.py
209 lines (118 loc) · 4.17 KB
/
API.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import DB
from fpdf import FPDF, HTMLMixin
"""Logik/Applikationsschicht der Applikation. Hier befinden sich die Funktionen die die Verbindung zwischen der
Benutzeroberfläche und der Datenschicht (DB) aufbauen, und den Datenfluss regeln. """
# DB Verbindung aufbauen
conn = DB.DatabaseConnection()
# Initalisierung der PDF mit HTML Features
class HTML2PDF(FPDF, HTMLMixin):
pass
# Fetchen von aktuellen Matrikelnnummern aus der DB
def update_matrikel_dropdowns():
matrikels = conn.get_matrikelnummer()
return matrikels
# Aktualisieren der Matrikeldropdowns
def refresh_matrikel_dropdown(optionmenu, auswahl):
matrikellist = update_matrikel_dropdowns()
menu = optionmenu['menu']
menu.delete(0, "end")
for name in matrikellist:
menu.add_command(label=name, command=lambda name=name: selection(name, auswahl))
# Selektierung der Auswahl
def selection(name, auswahl) :
auswahl.set(name)
# Anlegen eines Studenten
def student_anlegen(info):
conn.create_student(info)
return info
# Löschung eines Studenten
def drop_student(info):
conn.drop_student(info)
return info
# Fetchen von aktuellen Prüfungsnummern aus der DB
def update_klausur_dropdowns():
klausuren = conn.get_klausurnummer()
return klausuren
# Aktualisieren der Klausurdropdowns
def refresh_klausur_dropdown(optionmenu, auswahl):
klausurlist = update_klausur_dropdowns()
menu = optionmenu['menu']
menu.delete(0, "end")
for name in klausurlist:
menu.add_command(label=name, command=lambda name=name: kl_selection(name, auswahl))
# Selektierung der Auswahl
def kl_selection(name, auswahl) :
auswahl.set(name)
# Anlegen einer Prüfung
def klausur_anlegen(info):
conn.create_klausur(info)
return info
# Löschung einer Prüfung
def drop_klausur(info):
conn.drop_klausur(info)
return info
# Einfügen einer Note
def insert_note(info):
conn.insert_note(info)
return info
# Löschen einer Note
def delete_note(info):
cursor_status = conn.delete_note(info)
return cursor_status
# Closure Function für die gleichzeitige Ausführen von zwei Funktionen
def combine_update_and_write_commands(*funcs):
def combined_func(*args, **kwargs):
for f in funcs:
f(*args, **kwargs)
return combined_func
# Generierung des Notenspiegels als PDF eines Studierenden
def generate_pdf(info):
noten = conn.get_all_noten_by_student(info)
try:
pdf = HTML2PDF()
# Eine Seite hinzufügen:
pdf.add_page()
# Schriftart festlegen:
pdf.set_font("Arial", size=18)
#Logo
pdf.image("Ressources/images-12.jpeg")
# Überschrift
pdf.cell(30, 10, 'Notenliste')
pdf.ln(10)
#Name
pdf.set_font("Arial", size=12)
stammdaten = "Name: {} Matrikelnummer: {} Geburtsdatum: {}".format(noten[1][1], noten[1][0], str(noten[1][2]))
pdf.cell(180, 10, stammdaten , 1, 0, 'C')
pdf.ln(15)
#Noten
pdf.cell(30, 10, 'Auflistung der Noten: ')
pdf.ln(5)
if "Keine Note(n)" == str(noten[0]):
pdf.write(5, "Es sind keine Noten vorhanden.")
else:
noten.pop(0)
row_list = ["<tr><td>{}</td><td>{}</td><td>{}</td><td>{}</td></tr>"]*len(noten)
row_list_data = []
for note, row in zip(noten, row_list):
row = row.format(str(note[6]), str(note[3]), str(note[5]), str(note[4]))
row_list_data.append(row)
table = """
<table border="0" align="center" width="100%">
<thead>
<tr>
<th width="25%" align="left" >Prüfungsnummer</th>
<th width="25%" align="left" >Prüfungsname</th>
<th width="25%" align="left" >Prüfungsdatum</th>
<th width="25%" align="left" >Prüfungsnote</th>
</tr>
</thead>
<tbody>
{}
</tbody>
</table>
""".format(row_list_data)
pdf.write_html(table)
pdf.output("Notenspiegel-{}.pdf".format(info))
return True
except Exception:
return False