-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
230 lines (206 loc) · 9.61 KB
/
app.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
import gviz_api
import json
import functools
from flask import Flask, render_template, request, flash
import databaze
import mail
import gunicorn
import logging
app = Flask("MojeAppka")
app.secret_key = b'_5#y2L"F4Q8z\n\xec]/'
@app.route('/')
def index ():
return render_template("index.html")
@app.route('/registrace_ku')
def zobraz_registraci_ku ():
return render_template("registrace_ku.html")
@app.route('/registrace_ku', methods=('GET', 'POST'))
def registrace_ku():
if request.method == 'POST':
first_name = request.form['first_name']
last_name = request.form['last_name']
position_name = request.form['position_name']
email = request.form['email']
password = request.form['password']
phone = request.form['phone']
databaze.registrace_ku(first_name, last_name, position_name, email, password, phone)
return render_template('/success.html')
@app.route('/registrace_nr')
def zobraz_registraci_nr ():
return render_template("registrace_nr.html")
@app.route('/registrace_nr', methods=('GET', 'POST'))
def registrace_nr ():
if request.method == 'POST':
email = request.form['email']
password = request.form['password']
id_uzivatele = databaze.registrace_nr(email, password)
if id_uzivatele:
mail.email_dotaznik(email, id_uzivatele)
else:
flash ('Někde se stala chyba, zkuste to prosím znovu', "warning")
return render_template("success.html")
@app.route('/dotaznik/<account_id>', methods=['GET'])
def zobraz_dotaznik(account_id):
return render_template("dotaznik.html", account_id=account_id)
@app.route('/dotaznik/<account_id>', methods=['GET'])
def dotaznik_get(family_id):
if request.method == 'GET':
family_id = request.form["family_id"]
@app.route('/dotaznik/<account_id>', methods=['POST'])
def dotaznik_post (account_id):
if request.method == 'POST':
# vyplni tabulku family
file_number = request.form["file_number"]
approval_type_id = request.form["approval_type_id"]
regional_office_id = request.form["regional_office_id"]
expectation_status_id = request.form["expectation_status_id"]
district_id = request.form["district_id"]
carer_info_id = request.form["carer_info_id"]
prepcourse = request.form["prepcourse"]
account_id = request.form["account_id"]
note = request.form.get("note")
approval_date = request.form["approval_date"]
number_child_in_care = request.form.get('number_child_in_care')
family_id = databaze.insert_family(file_number, approval_type_id, regional_office_id, expectation_status_id, district_id, carer_info_id, prepcourse, account_id, note, approval_date, number_child_in_care)
# vyplni tabulku family_parent pro prvního rodiče
parent1_sex_id = request.form["parent1_sex_id"]
parent1_year_of_birth = request.form["parent1_year_of_birth"]
databaze.insert_parent1(family_id, parent1_sex_id, parent1_year_of_birth)
# vyplni tabulku family_parent pro druhého rodiče
parent2_sex_id = request.form.get("parent2_sex_id")
parent2_year_of_birth = request.form.get("parent2_year_of_birth")
# if parent2_sex_id is not None and parent2_year_of_birth is not None:
databaze.insert_parent1(family_id, parent2_sex_id, parent2_year_of_birth)
# vyplni tabulku child_in_care pro nejmladší dítě v péči
youngest_child_sex_id = request.form.get("youngest_child_sex_id")
youngest_child_year_of_birth = request.form.get("youngest_child_year_of_birth")
relationship_id = request.form.get("relationship_id")
# if youngest_child_sex_id is not None and youngest_child_year_of_birth is not None and relationship_id is not None:
databaze.insert_child_in_care(family_id, youngest_child_sex_id, youngest_child_year_of_birth, relationship_id)
# vyplni tabulku expectation
sex_id = request.form["expectation_sex_id"]
# vyplni tabulku expectation_sibling_info
expectation_id = databaze.insert_expectation(family_id, sex_id)
sibling_info_id = request.form.getlist("sibling_info_id")
databaze.insert_expectation_sibling_info(expectation_id, sibling_info_id)
# vyplni tabulku expectation_mental_handicap
mental_handicap_id = request.form["mental_handicap_id"]
databaze.insert_expectation_mental_handicap(expectation_id, mental_handicap_id)
# vyplni tabulku expectation_physical_handicap
physical_handicap_id = request.form["physical_handicap_id"]
databaze.insert_expectation_physical_handicap(expectation_id, physical_handicap_id)
# vyplni tabulku expectation_ethnicity
expectation_ethnicity_id = request.form.getlist("expectation_ethnicity_id")
databaze.insert_expectation_ethnicity(expectation_id, expectation_ethnicity_id)
# vyplni tabulku expectation_legal_status
expectation_legal_status = request.form.getlist("expectation_legal_status")
databaze.insert_expectation_legal_status(expectation_id, expectation_legal_status)
# vyplni tabulku expectation_age
expectation_age = request.form.getlist("expectation_age")
databaze.insert_expectation_age(expectation_id, expectation_age)
# vyplni tabulku expectation_anamnesis
expectation_anamnesis_id = request.form.getlist("expectation_anamnesis_id")
databaze.insert_expectation_anamnesis(expectation_id, expectation_anamnesis_id)
return render_template("success.html")
@app.route('/search')
def search ():
return render_template("search.html",
)
@app.route('/search', methods=['POST'])
def search_post():
if request.method == 'POST':
approval_type_id = request.form.get("approval_type_id")
legal_status_id= request.form.get("legal_status_id")
district_id= request.form.get("district_id")
age= request.form.get("child_age")
sex= request.form.get("expectation_sex_id")
sibling_info= request.form.get("siblings")
physical_handicap= request.form.get("physical_handicap")
mental_handicap= request.form.get("mental_handicap_id")
ethnicity= request.form.get("ethnicity")
anamnesis= request.form.get("anamnesis_id")
expectation_table = databaze.tabulka_ku_search(approval_type_id, legal_status_id, district_id, age, sex, sibling_info, physical_handicap, mental_handicap, ethnicity, anamnesis)
print(expectation_table)
return render_template("tabulka_search.html",
expectation_table=expectation_table
)
@app.route('/login')
def login ():
return render_template("login.html",
)
@app.route('/success')
def success ():
return render_template("success.html",
)
@app.route('/tabulka')
def tabulka_zobraz():
family_table = databaze.tabulka_vypis()
return render_template("tabulka.html",
family_table=family_table
)
@app.route('/tabulka_ku')
def tabulka_ku ():
expectation_table = databaze.tabulka_ku_vypis()
print(expectation_table)
return render_template("tabulka_ku.html",
expectation_table=expectation_table,
)
@app.route('/graf')
def graf():
return render_template("graf.html")
@app.route("/graf-data")
def graf_data():
description = {"kraj": ("string", "Kraj"),"osvojitele": ("number", "Osvojitelé"), "pestouni": ("number", "Pěstouni")}
data = databaze.volni()
data_table = gviz_api.DataTable(description)
data_table.LoadData(data)
return data_table.ToJSon(columns_order=("kraj", "osvojitele", "pestouni"), order_by="osvojitele")
@app.route('/profil')
def profile ():
return render_template("profil.html",)
@app.route('/profil/<int:family_id>', methods=['GET'])
def family_profile(family_id):
family_profile = databaze.tabulka_ku_vypis_family(family_id)
return render_template("profil.html",
family_profile=family_profile,
)
@app.route('/tabulka/<region_id>', methods=['GET'])
def table_region (region_id):
family_table = databaze.table_region(region_id)
print(family_table)
return render_template("tabulka.html",
family_table = family_table
)
@app.route('/video')
def video():
return render_template("video.html")
if __name__ != '__main__':
gunicorn_logger = logging.getLogger('gunicorn.error')
app.logger.handlers = gunicorn_logger.handlers
#app.logger.setLevel(gunicorn_logger.level)
# @app.route('/login', , methods=['POST'])
# def login_post ():
# if request.method == 'POST':
# email = request.form["login_email"]
# heslo = request.form["login_password"]
# uzivatel = najdi_uzivatele(email)
# # uspesne_prihlasen = False
# if uzivatel:
# if sha512(heslo.encode()).hexdigest() != uzivatel.password_hash:
# flash ('Špatně zadané heslo.', "danger")
# elif sha512(heslo.encode()).hexdigest() == uzivatel.password_hash:
# if login_user(uzivatel, force=True):
# flash ('Uživatel byl úspěšně přihlášen.', "success")
# if next.endswith('prihlaseni') or next.endswith('registrace'):
# return redirect(url_for('zavody_bp.show_zavody'))
# return redirect(next)
# if not uzivatel:
# flash ("Zadaný e-mail není v naší databázi. Nejprve se, prosím, zaregistruj.", "danger")
# return render_template('nevim.html', form=form)
# provided_password = request.form["login_password"]
# result = databaze.verify_password(stored_password, provided_password)
# if result = True:
# return render_template("login.html"
# else:
# flash
# )