/
app.py
297 lines (243 loc) · 9.26 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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
from flask import Flask, render_template, request, redirect, session
import database
app = Flask(__name__)
app.secret_key = "YOLOSWAG"
@app.route('/testDB')
def testDB():
cur.execute("SELECT sno FROM test")
print cur.fetchall()
return 'hi'
@app.route('/')
def library_system():
school_name = 'Georgia Tech'
return render_template('index.html', school_name = school_name)
@app.route('/hello', methods=['POST', 'GET'])
def hello_world():
if request.method == 'GET':
name = 'Pujun GET'
return render_template('hello.html', name=name)
elif request.method == 'POST':
name = 'Pujun POST'
return render_template('hello.html', name=name)
else:
return 'wtf'
@app.route('/register/', methods=['POST', 'GET'])
def register_user():
f = request.form
if f['password'] != f['confirm_password']:
return render_template('index.html', register_error="Passwords don't match")
u = database.new_user(f['username'], f['password'])
print u
session['username'] = u
return redirect('/create-profile/')
@app.route('/login/', methods=['POST', 'GET'])
def login():
if request.method == 'GET':
return render_template('index.html')
elif request.method == 'POST':
f = request.form
if database.login(f['username'], f['password']):
session['username'] = f['username']
user = database.get_user(f['username'])
if user[2]: # user is staff
return render_template('staff-dashboard.html')
else:
return redirect('/search-books/')
else:
return render_template('index.html', login_error='Invalid username and password')
else:
return 'wtf!'
@app.route('/create-profile/', methods=['POST','GET'])
def create_profile():
if request.method == 'GET':
return render_template('create-profile.html')
elif request.method == 'POST':
f = request.form
username = session.get("username", None)
print "SEE THIS ", username
if database.create_profile(username, f['first-name'] + f['last-name'], f['dob'], f['gender'], f['email'], f['is-faculty'], f['address'], f['department']):
return redirect('/search-books/')
else:
return render_template('index.html', login_error='Invalid username and password')
# return logged in view
return 'logged in!'
else:
return 'wtf!'
@app.route('/search-books/', methods=['POST','GET'])
def search_books():
if request.method == 'GET':
return render_template('search-books.html')
elif request.method == 'POST':
f = {}
# clean form
for k,v in request.form.items():
f[k] = v.strip()
if f[k] == '': f[k] = None
if f['isbn'] != None: f['isbn'] = int(f['isbn'])
# validate
if f['isbn'] == None and f['title'] == None and f['author'] == None:
return render_template('search-books.html', search_error="Either ISBN, Title, or Author must be filled.")
#search
print "HELLLLLO"
checkout_books = database.search_books(
isbn=f['isbn'],
title=f['title'],
author=f['author'],
publisher=f['publisher'],
edition=f['edition'],
reserved= 0)
reserved_books = database.search_books(
isbn=f['isbn'],
title=f['title'],
author=f['author'],
publisher=f['publisher'],
edition=f['edition'],
reserved= 1)
# return render_template('search-results.html', books=books)
session['checkout_books'] = checkout_books
session['reserved_books'] = reserved_books
print checkout_books, "BOOKS"
return redirect('/request-hold/')
else:
return 'wtf!'
@app.route('/book-confirmation', methods=['GET', 'POST'])
def book_confirmation():
# print "this is the beginning"
# if request.method == 'POST':
# print "THIS IS GEORGIAAAA"
# print "hello bitches"
# print "hello", request.form['selected-book-isbn']
# database.create_issue(f['selected-book-isbn'], f['selected-book-isbn'], f['selected-book-isbn'])
# return render_template("book-confirmation.html", issue_id = issue_id)
# else:
# return render_template("book-confirmation.html")
if request.method == 'GET':
name = 'Pujun GET'
return render_template('book-confirmation.html', name=name)
elif request.method == 'POST':
print "THIS IS GEORGIAAA"
print "hello bitches"
name = "chill dude"
f = request.form
print f.values
database.create_issue(f['selected-book-isbn'], f['hold-request-date'], f['estimated-return-date'])
return render_template('book-confirmation.html', issue_id=name)
else:
return 'wtf'
@app.route('/request-extension')
def request_extension():
return render_template('request-extension.html')
@app.route('/future-hold-request')
def future_hold_request():
return render_template('future-hold-request.html')
@app.route('/track-book-location', methods=['GET', 'POST'])
def track_book_location():
if request.method == 'GET':
return render_template('track-book-location.html')
elif request.method == 'POST':
f = request.form
location_info = database.track_book(f['isbn'])
return render_template('track-book-location.html', location_info = location_info)
@app.route('/request-hold/', methods=['GET', 'POST'])
def hold_request():
if request.method == 'GET':
checkout_books = session.get("checkout_books", None)
reserved_books = session.get("reserved_books", None)
return render_template('request-hold.html', checkout_books = checkout_books, reserved_books = reserved_books)
elif request.method == 'POST':
print 'posting'
f = request.form
database.hold_request(f['selected-book-isbn'], session['username'])
message = "You have successfully requested a hold on the selected book"
return render_template('search-books.html', message = message)
else:
return 'wtf!'
@app.route('/book-checkout/', methods=['POST'])
def book_checkout():
f = request.form
print f.items()
issue_id = database.book_checkout(
isbn=f['isbn'],
copy_number=f['copy-number'],
username=f['username'])
return render_template('staff-dashboard.html', checkout_message="Issue id: " + str(issue_id))
@app.route('/return-book/', methods=['GET', 'POST'])
def return_book_screen():
if request.method == 'GET':
return "return-book-screen.html"
elif request.method == "POST":
f = request.form
issue_id = f['issue-id']
is_damaged = False
if 'is-damaged' in f: is_damaged = True
issue_details = []
issue_details = database.return_book(issue_id, is_damaged)
return render_template('staff-dashboard.html', return_book_message="Returned!", issue_details=issue_details)
else:
return "wtf"
@app.route('/lost-damaged-book/', methods=['GET', 'POST'])
def lost_damaged_book():
if request.method == 'GET':
return "return-book-screen.html"
elif request.method == "POST":
f = request.form
isbn = f['isbn']
book_copy = f['book-copy']
last_user = database.last_user(isbn, book_copy)
print "here is the culprit", last_user
return render_template('staff-dashboard.html', last_user = last_user)
else:
return "wtf"
# @app.route('/lost-damaged-book')
# def lost_damaged_book():
# return render_template('lost-damaged-book.html')
@app.route('/update-penalty/', methods=['GET', 'POST'])
def update_penalty():
if request.method == 'GET':
return "return-book-screen.html"
elif request.method == "POST":
f = request.form
last_user = f['last-user']
amount_to_be_charged = f['amount-to-be-charged']
database.update_penalty(last_user, amount_to_be_charged)
update_penalty_message = last_user + " has been charged"
return render_template('staff-dashboard.html', update_penalty_message = update_penalty_message)
@app.route('/popular-books-report')
def popular_books_report():
#find the most popular books for Jan
popular_book_jan = database.find_popular_books(1)
print "HAHAHAHA", popular_book_jan
popular_book_feb = database.find_popular_books(2)
return render_template('popular-books-report.html', popular_book_jan = popular_book_jan, popular_book_feb = popular_book_feb)
@app.route('/frequent-users-report')
def frequent_users_report():
frequent_users_jan = database.frequent_users(1)
frequent_users_feb = database.frequent_users(2)
return render_template('frequent-users-report.html', frequent_users_jan = frequent_users_jan, frequent_users_feb = frequent_users_feb)
@app.route('/popular-subjects-report')
def popular_subjects_report():
popular_subjects_jan = database.popular_subjects(1)
popular_subjects_feb = database.popular_subjects(2)
return render_template('popular-subjects-report.html', popular_subjects_jan = popular_subjects_jan, popular_subjects_feb = popular_subjects_feb)
@app.route('/damaged-books-report', methods=['POST', 'GET'])
def damaged_books_report():
#find all the subjects
subjects = database.get_subjects();
subject_list = [s[0] for s in subjects]
print "LIST OF RETURNED SUBJECTS", subject_list
if request.method == 'GET':
return render_template('damaged-books-report.html', subjects = subject_list)
elif request.method == 'POST':
table_contents = [];
f = request.form
print "this is sparta"
print f['subject_1']
# print f['month']
print f.items()
table_contents.append((f['subject_1'], database.find_num_damaged_books(f['month'], f['subject_1'])))
table_contents.append((f['subject_2'], database.find_num_damaged_books(f['month'], f['subject_2'])))
table_contents.append((f['subject_3'], database.find_num_damaged_books(f['month'], f['subject_3'])))
print "THINGS THAT WILL GO IN THE TABLE", table_contents
return render_template('damaged-books-report.html', subjects = subject_list, table_contents = table_contents, month = database.month_name_finder(f['month']))
if __name__ == '__main__':
app.run(debug=True)