-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.py
209 lines (173 loc) · 8.99 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
from flask import Flask, render_template, request
from dataCleaning import main_proc
import query_manager as query
import json
import global_param
app = Flask(__name__)
@app.route('/')
def hello_world():
# return main_proc()
return render_template('/index.html')
@app.route("/query/find_by_type", methods=['POST'])
def find_by_type():
if request.method == 'POST':
type = request.form['type']
global_param.query_result = query.filter_by_type(type)
global_param.title = "Ricerca " + type
global_param.number_of_pages = int(len(global_param.query_result) / global_param.limit) + 1
return render_template('/query.html', results=global_param.query_result[0:11],
size=len(global_param.query_result), title=global_param.title, page=1,
max_pages=global_param.number_of_pages)
return json.dumps({"ok": True})
@app.route("/query/show_update", methods=['POST'])
def show_update():
title = request.form["title"]
res = query.find_by_title_equals(title=title)
return render_template('/update.html', element=res)
@app.route("/query/update", methods=['POST'])
def update():
type = request.form["type"]
title = request.form["title"]
description = request.form["description"]
director = request.form["director"]
cast = request.form["cast"]
locations = request.form["locations"]
date_added = request.form["date_added"]
release_year = request.form["release_year"]
rating = request.form["rating"]
film_duration = request.form["film_duration"]
number_of_seasons = request.form["number_of_seasons"]
genres = request.form["genres"]
present_in = request.form["present_in"]
res = query.modify(type, title, director, cast, locations, date_added, release_year, rating, genres, description,
present_in)
return render_template('/index.html')
@app.route("/query/insert", methods=['POST'])
def insert():
type = request.form["type"]
title = request.form["title"]
description = request.form["description"]
director = request.form["director"]
cast = request.form["cast"]
locations = request.form["locations"]
date_added = request.form["date_added"]
release_year = request.form["release_year"]
rating = request.form["rating"]
film_duration = request.form["film_duration"]
number_of_seasons = request.form["number_of_seasons"]
genres = request.form["genres"]
present_in = request.form["present_in"]
res = query.insert(type, title, director, cast, locations, date_added, release_year, rating, genres, description,
present_in)
return render_template('/index.html')
@app.route("/query/find_by_genre", methods=['POST'])
def find_by_genre():
if request.method == 'POST':
genre = request.form['genre']
global_param.query_result = query.find_by_genres(genre)
global_param.title = "Ricerca per genere " + genre
global_param.number_of_pages = int(len(global_param.query_result) / global_param.limit) + 1
return render_template('/query.html', results=global_param.query_result[0:11],
size=len(global_param.query_result), title=global_param.title, page=1,
max_pages=global_param.number_of_pages)
return json.dumps({"ok": True})
@app.route("/query/find_by_title", methods=['POST'])
def find_by_title():
if request.method == 'POST':
title = request.form['title']
global_param.query_result = query.find_by_title(title)
global_param.title = "Ricerca per titolo:" + title
global_param.number_of_pages = int(len(global_param.query_result) / global_param.limit) + 1
return render_template('/query.html', results=global_param.query_result[0:11],
size=len(global_param.query_result), title=global_param.title, page=1,
max_pages=global_param.number_of_pages)
return json.dumps({"ok": True})
@app.route("/query/find_by_year", methods=['POST'])
def find_by_year():
if request.method == 'POST':
year = request.form['year']
global_param.query_result = query.find_by_year(year)
global_param.title = "Ricerca per anno: " + year
global_param.number_of_pages = int(len(global_param.query_result) / global_param.limit) + 1
return render_template('/query.html', results=global_param.query_result[0:11],
size=len(global_param.query_result), title=global_param.title, page=1,
max_pages=global_param.number_of_pages)
return json.dumps({"ok": True})
@app.route("/query/change_page", methods=['POST'])
def change_page():
if request.method == 'POST':
page = int(request.form['page'])
modifier = int(request.form['modifier'])
start = 0
end = 0
if modifier == -1:
start = global_param.limit * (page - 1)
end = global_param.limit * page
else:
start = global_param.limit * page
end = global_param.limit * (page + 1)
return render_template('/query.html',
results=global_param.query_result[
start: end + 1],
size=len(global_param.query_result), title=global_param.title, page=page + modifier,
max_pages=global_param.number_of_pages)
return json.dumps({"ok": True})
@app.route("/query/find_by_year_range", methods=['POST'])
def find_by_year_range():
if request.method == 'POST':
min = request.form['min_year']
max = request.form['max_year']
global_param.title = "Ricerca tra il: " + min + "e il " + max
global_param.query_result = query.find_by_year_range(min, max)
global_param.number_of_pages = int(len(global_param.query_result) / global_param.limit) + 1
return render_template('/query.html', results=global_param.query_result[0:11],
size=len(global_param.query_result), title=global_param.title, page=1,
max_pages=global_param.number_of_pages)
return json.dumps({"ok": True})
@app.route("/query/find_by_director", methods=['POST'])
def find_by_director():
if request.method == 'POST':
director = request.form['director']
global_param.title = "Ricerca per regista:" + director
global_param.query_result = query.find_by_director(director)
global_param.number_of_pages = int(len(global_param.query_result) / global_param.limit) + 1
return render_template('/query.html', results=global_param.query_result[0:11],
size=len(global_param.query_result), title=global_param.title, page=1,
max_pages=global_param.number_of_pages)
return json.dumps({"ok": True})
@app.route("/query/find_series_by_at_least_season_count", methods=['POST'])
def find_series_by_at_least_season_count():
if request.method == 'POST':
seasons = request.form['seasons']
global_param.title = "Ricerca per numero di stagioni:" + seasons
global_param.query_result = query.find_series_by_at_least_season_count(seasons)
global_param.number_of_pages = int(len(global_param.query_result) / global_param.limit) + 1
return render_template('/query.html', results=global_param.query_result[0:11],
size=len(global_param.query_result), title=global_param.title, page=1,
max_pages=global_param.number_of_pages)
return json.dumps({"ok": True})
@app.route("/query/find_by_rating", methods=['POST'])
def find_by_rating():
if request.method == 'POST':
rating = request.form['rating']
global_param.title = "Ricerca per rating:" + rating
global_param.query_result = query.find_by_rating(rating)
global_param.number_of_pages = int(len(global_param.query_result) / global_param.limit) + 1
return render_template('/query.html', results=global_param.query_result[0:11],
size=len(global_param.query_result), title=global_param.title, page=1,
max_pages=global_param.number_of_pages)
return json.dumps({"ok": True})
@app.route("/query/find_orderby_date", methods=['POST'])
def find_orderby_date():
if request.method == 'POST':
order = request.form['order']
global_param.title = "Ricerca ordinata per data:" + "decrescente" if order == 1 else "ascendente"
global_param.query_result = query.find_orderby_date(order)
global_param.number_of_pages = int(len(global_param.query_result) / global_param.limit) + 1
return render_template('/query.html', results=global_param.query_result[0:11],
size=len(global_param.query_result), title=global_param.title, page=1,
max_pages=global_param.number_of_pages)
return;
return json.dumps({"ok": True})
if __name__ == '__main__':
app.run()