-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
726 lines (651 loc) · 30.9 KB
/
main.py
File metadata and controls
726 lines (651 loc) · 30.9 KB
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
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
from os import error, execle, write
import re
from typing import Counter
import MySQLdb
from flask import Flask, render_template, redirect, request, redirect, url_for
from flask.helpers import flash
from werkzeug import datastructures
import yaml
from flask_mysqldb import MySQL
import hashlib
app = Flask(__name__)
db = yaml.load(open('db.yaml'))
app.config['MYSQL_HOST'] = db['mysql_host']
app.config['MYSQL_USER'] = db['mysql_user']
app.config['MYSQL_PASSWORD'] = db['mysql_password']
app.config['MYSQL_DB'] = db['mysql_db']
mysql = MySQL(app)
@app.route('/', methods=['GET', 'POST'])
def login():
if request.method == 'POST':
message = None
userDetails = request.form
username = userDetails['username']
password = userDetails['password']
h = hashlib.md5(password.encode())
cur = mysql.connection.cursor()
resultValue = cur.execute(f"SELECT * from user_account where username = '{username}' and password = SHA2('{password}', 224)")
userDetail = cur.fetchall()
try:
userDetail[0]
global nameprof
global userid
global user_role
nameprof = userDetail[0][1]
userid = userDetail[0][0]
user_role = userDetail[0][3]
cur.execute("SELECT role from user_information where userid = %s", [userid])
user_role = cur.fetchall()[0][0]
if user_role == 'manager':
return redirect('/manager')
elif user_role == 'booker':
return redirect('/booker')
print(nameprof)
return redirect('/profile')
except IndexError as e:
print(e)
message = "Invalid username or password"
return render_template('login.html', message=message)
return render_template('login.html')
@app.route('/register', methods=['GET', 'POST'])
def sign_up():
if request.method == 'POST':
uersDetails = request.form
username = uersDetails['username']
password = uersDetails['password']
fname = uersDetails['fname']
surname = uersDetails['surname']
address = uersDetails['address']
role = uersDetails['role']
cur = mysql.connection.cursor()
exception =None
try:
cur.execute("INSERT INTO user_account (username, password) VALUES (%s, %s)", (username, password))
sql = "SELECT userid FROM user_account where username = %s"
cur.execute(sql, [username])
result = cur.fetchone()
print(type(result[0]))
print(result[0])
cur.execute("INSERT into user_information (address, fname, surname, role, userid) VALUES (%s, %s, %s, %s, %s)", (address, fname, surname, role, result[0]))
except MySQLdb.OperationalError as e:
exception = e.args[1]
except MySQLdb.IntegrityError as e:
exception = "This username is already in use!"
mysql.connection.commit()
cur.close()
if exception is not None:
print(f"username {username}, password {password}, fname {fname}, surname {surname}, address {address}, role {role}")
return render_template('register.html', exception=exception)
else:
return render_template('signups.html')
return render_template('register.html')
@app.route('/profile', methods=['GET', 'POST'])
def profile():
return render_template('sprofile.html', nameprof=nameprof)
@app.route('/informations', methods=['GET', 'POST'])
def informations():
cur = mysql.connect.cursor()
sql = "SELECT user_account.username, user_information.fname, user_information.surname, user_information.address, user_information.role \
FROM user_account INNER JOIN user_information ON user_information.userid = user_account.userid \
where user_account.userid = %s"
cur.execute(sql, [userid])
res = cur.fetchall()
mysql.connection.commit()
cur.close()
username = res[0][0]
fname = res[0][1]
surname = res[0][2]
address = res[0][4]
role = res[0][3]
print(res[0])
return render_template("information.html", username=username, fname=fname, surname=surname, address=address, role=role)
@app.route('/search', methods=['GET', 'POST'])
def search():
if request.method == "POST":
details = request.form
name = details['name']
write = details['writer']
date = details['date']
version = details['version']
cur = mysql.connect.cursor()
try:
if name != "" and write == "" and date == "" and version == "":
sql = "select bookid, name, writer, types, date, verion, count, price from book where name = %s order by name"
cur.execute(sql, [name])
if name == "" and write != "" and date == "" and version == "":
sql = "select bookid, name, writer, types, date, verion, count, price from book where writer = %s order by name"
cur.execute(sql, [write])
if name == "" and write == "" and date != "" and version == "":
sql = "select bookid, name, writer, types, date, verion, count, price from book where date = %s order by name"
cur.execute(sql, [date])
if name == "" and write == "" and date == "" and version != "":
sql = "select bookid, name, writer, types, date, verion, count, price from book where verion = %s order by name"
cur.execute(sql, [version])
if name != "" and write != "" and date == "" and version == "":
sql = "select bookid, name, writer, types, date, verion, count, price from book where name = %s and writer = %s order by name"
cur.execute(sql, [name, write])
if name != "" and write == "" and date != "" and version == "":
sql = "select bookid, name, writer, types, date, verion, count, price from book where name = %s and date = %s order by name"
cur.execute(sql, [name, date])
if name != "" and write == "" and date == "" and version != "":
sql = "select bookid, name, writer, types, date, verion, count, price from book where verion = %s and name = %s order by name"
cur.execute(sql, [version, name])
if name == "" and write != "" and date != "" and version == "":
sql = "select bookid, name, writer, types, date, verion, count, price from book where writer = %s and date = %s order by name"
cur.execute(sql, [write, date])
if name == "" and write != "" and date == "" and version != "":
sql = "select bookid, name, writer, types, date, verion, count, price from book where verion = %s and writer = %s order by name"
cur.execute(sql, [version, write])
if name == "" and write == "" and date != "" and version != "":
sql = "select bookid, name, writer, types, date, verion, count, pricefrom book where verion = %s and date = %s order by name"
cur.execute(sql, [version, date])
if name != "" and write != "" and date != "" and version == "":
sql = "select bookid, name, writer, types, date, verion, count, price from book where name = %s and writer = %s and date = %s order by name"
cur.execute(sql, [name, write, date])
if name != "" and write != "" and date == "" and version != "":
sql = "select bookid, name, writer, types, date, verion, count, price from book where name = %s and writer = %s and verion = %s order by name"
cur.execute(sql, [name, write, version])
if name != "" and write == "" and date != "" and version != "":
sql = "select bookid, name, writer, types, date, verion, count, price from book where name = %s and verion = %s and date = %s order by name"
cur.execute(sql, [name, version, date])
if name == "" and write != "" and date != "" and version != "":
sql = "select bookid, name, writer, types, date, verion, count, price from book where verion = %s and date = %s and writer = %s order by name"
cur.execute(sql, [version, date, write])
if name != "" and write != "" and date != "" and version != "":
sql = "select bookid, name, writer, types, date, verio, count, price from book where name = %s and verion = %s and date = %s and writer = %s order by name"
cur.execute(sql, [name, version, date, write])
except MySQLdb.OperationalError as e:
print(e)
return render_template('search.html', message="Please enter valid format for date field")
try:
x = cur.fetchall()
x[0][0]
mysql.connection.commit()
cur.close()
except:
return render_template('search.html')
print('----------------')
print(x)
print('----------------')
return render_template('reserve.html', data=x)
return render_template('search.html')
@app.route('/reserve', methods=['GET', 'POST'])
def get_book():
if request.method == 'POST':
details = request.form['reserve']
dbb = MySQLdb.connect(host="localhost",
user="root",
passwd="root",
db="dbproject")
curb = dbb.cursor()
curb.execute("select * from book where bookid = %s", [details])
res = curb.fetchall()
curb.execute("select delay from user_account where userid = %s", [userid])
userdelay = curb.fetchone()
try:
curb.execute("update user_account u join book b set u.money = u.money - ( b.price * 5 ) / 100 where u.userid = %s and b.bookid = %s", [userid, details])
except MySQLdb.OperationalError as e:
print('--')
print(e)
print(e.args[0])
print('--')
if str(e.args[0]) == str(1292):
message = 'کتابی با چنین شناسهای موجود نیست'
else:
message = "موجودی کافی نیست"
res = curb.execute("insert into getbook_opt(message, operation, userid) values (%s, %s, %s)", [message, False, userid])
dbb.commit()
return render_template('getbook.html', message=message)
if userdelay[0] == 4:
curb.close()
message = "به دلیل ۴ بار دیر کرد در تحویل کتاب در بازه ۲ ماه اخیر، اجازه گرفتن کتاب را ندارید"
res = curb.execute("insert into getbook_opt(message, operation, userid) values (%s, %s, %s)", [message, False, userid])
dbb.commit()
return render_template('getbook.html', message=message)
try:
print(res[0])
curb.execute("UPDATE BOOK SET count = count + %s where bookid = %s", [-1, details])
if user_role == 'student':
curb.execute("select * from user_account u join book b where u.role = %s and (b.types = '' or b.types = 'amoozeshi') and u.userid = %s and b.bookid = %s;", [user_role, userid, details])
res = curb.fetchall()
try:
res[0]
except IndexError:
message = "شما مجاز به گرفتن این کتاب نیستید"
res = curb.execute("insert into getbook_opt(message, operation, userid) values (%s, %s, %s)", [message, False, userid])
# dbb.commit()
return render_template('getbook.html', message=message)
if user_role == 'guser':
curb.execute("select * from user_account u join book b where u.role = %s and b.types = '' and u.userid = %s and b.bookid = %s;", [user_role, userid, details])
res = curb.fetchall()
try:
res[0]
except IndexError:
message = "شما مجاز به گرفتن این کتاب نیستید"
res = curb.execute("insert into getbook_opt(message, operation, userid) values (%s, %s, %s)", [message, False, userid])
dbb.commit()
curb.close()
return render_template('getbook.html', message=message)
dbb.commit()
res = curb.fetchall()
message = "کتاب با موفقیت به حساب شما اضافه شد"
res = curb.execute("insert into getbook_opt(message, operation, userid) values (%s, %s, %s)", [message, True, userid])
message2 = "را به صورت موفقیت آمیز درخواست داده است"
res = curb.execute("insert into inbox(message, operation, userid, bookid) values (%s, %s, %s, %s)", [message2, True, userid, details])
dbb.commit()
return render_template('getbook.html', messages=message)
except IndexError:
message = "کتابی با چنین شناسهای موجود نیست"
res = curb.execute("insert into getbook_opt(message, operation, userid) values (%s, %s, %s)", [message, False, userid])
dbb.commit()
return render_template('getbook.html', message=message)
except MySQLdb.OperationalError:
message = "کتاب درخواستی در حال حاضر موجود نیست"
res = curb.execute("insert into getbook_opt(message, operation, userid) values (%s, %s, %s)", [message, False, userid])
dbb.commit()
return render_template('getbook.html', message=message)
return render_template('getbook.html')
return render_template('getbook.html')
@app.route('/payment', methods=['GET', 'POST'])
def payment():
if request.method == 'POST':
money = request.form['payment']
dbb = MySQLdb.connect(host="localhost",
user="root",
passwd="root",
db="dbproject")
curb = dbb.cursor()
try:
curb.execute ("UPDATE user_account SET money = money + %s WHERE userid = %s;", [money, userid])
dbb.commit()
except MySQLdb.OperationalError as e:
message = e.args[1]
if 'Truncated' in message:
message = "مبلغ وارد شده باید به صورت عددی باشد"
curb.execute("select money from user_account where userid = %s", [userid])
res = curb.fetchall()
mysql.connection.commit()
curb.close()
return render_template('payment.html', money=res[0][0], message=message)
except:
message = "مبلغ وارد شده باید به صورت عددی و معقول باشد"
curb.execute("select money from user_account where userid = %s", [userid])
res = curb.fetchall()
return render_template('payment.html', money=res[0][0], message=message)
curb.execute("select money from user_account where userid = %s", [userid])
res = curb.fetchall()
curb.close()
return render_template('payment.html', messages= "موجودی با موفقیت اضافه شد", money=res[0][0])
else:
cur = mysql.connect.cursor()
cur.execute("select money from user_account where userid = %s", [userid])
res = cur.fetchall()
mysql.connection.commit()
cur.close()
return render_template('payment.html', money=res[0][0])
@app.route('/manager', methods=['GET', 'POST'])
def manager():
return render_template('manager.html', nameprof=nameprof)
@app.route('/booker', methods=['GET', 'POST'])
def booker():
return render_template('booker.html', nameprof=nameprof)
@app.route('/addbook', methods=['GET', 'POST'])
def addbook():
if request.method == 'POST':
message = None
detail = request.form
bookname = detail['name']
date = detail['date']
version = detail['version']
type = detail['type']
writer = detail['writer']
count = detail['count']
dbb = MySQLdb.connect(host="localhost",
user="root",
passwd="root",
db="dbproject")
curb = dbb.cursor()
try:
curb.execute("insert into book(name, writer, date, verion, count, types) values (%s, %s, %s, %s, %s, %s)", [bookname, writer, date, version, count, type])
dbb.commit()
message = 'کتاب با موفقیت اضافه شد'
except MySQLdb.OperationalError as e:
print('--')
print(e)
print('--')
if str(e.args[0]) == str(1644):
message = 'نسخه و تعداد کتاب وارد شده باید بزرگتر از صفر باشد'
elif str(e.args[0]) == str(1292):
message = "فرمت تاریخ باید به صورت 12-12-1399 باشد"
return render_template('addbook.html', message=message)
except MySQLdb.DataError:
message = "فرمت داده برای نسخه و تعداد نادرست است"
return render_template('addbook.html', message=message)
except MySQLdb.IntegrityError:
message = "کتاب وارد شده موجود است، برای افزایش تعداد از بخش مربوط استفاده کنید"
return render_template('addbook.html', message=message)
message = 'کتاب با موفقیت اضافه شد'
return render_template('addbook.html', message=message)
return render_template('addbook.html', nameprof=nameprof)
@app.route('/inboxuser', methods=['GET', 'POST'])
def inboxuser():
dbb = MySQLdb.connect(host="localhost",
user="root",
passwd="root",
db="dbproject")
curb = dbb.cursor()
curb.execute("select inbox.inboxid, inbox.bookid, book.name, inbox.delivered from book join inbox where book.bookid = inbox.bookid and inbox.userid = %s;", [userid])
res = curb.fetchall()
print(res)
return render_template("inbox.html", data = res)
@app.route('/delete', methods=['GET', 'POST'])
def delete():
if request.method == 'POST':
dbb = MySQLdb.connect(host="localhost",
user="root",
passwd="root",
db="dbproject")
curb = dbb.cursor()
detail = request.form
userid = detail['userid']
print(userid)
curb.execute("select * from user_account where userid = %s", [userid])
res12 = curb.fetchall()
try:
res12[0]
except IndexError:
return render_template('delete.html', message="کاربر با چنین مشخصاتی وجود ندارد")
curb.execute("DELETE FROM user_account where userid = %s", [userid])
res = curb.fetchall()
dbb.commit()
dbb.close()
return render_template('delete.html', messages="کاربر با موفقیت حذف شد")
return render_template('delete.html')
@app.route('/accepted', methods=['GET', 'POST'])
def accepted():
dbb = MySQLdb.connect(host="localhost",
user="root",
passwd="root",
db="dbproject")
curb = dbb.cursor()
if request.method == "POST":
message = None
try:
page = int(request.form['page'])
curb.execute("select message, date_created, bookid, userid from inbox order by date_created DESC")
res = curb.fetchall()
count = 0
list = []
for i in res:
if count < 5:
list.append(i)
count += 1
count = int(count / 5 + 1)
if page > count:
message= "ورودی داده شده باید کمتر یا برابر با تعداد جدولها باشد"
list = []
tt = 0
for i in res:
print('-----------')
print(tt)
print(i)
print('-----------')
if tt <= page * 5 - 1 and tt >= (page - 1) * 5:
print("**")
print(tt)
print("**")
list.append(i)
tt += 1
except ValueError:
message= "ورودی داده شده نادرست است"
return render_template('accepted.html', message=message)
return render_template('accepted.html', count=count, message=message, data=list)
curb.execute("select message, date_created, bookid, userid from inbox order by date_created DESC")
res = curb.fetchall()
count = 0
list = []
for i in res:
if count < 5:
list.append(i)
count += 1
count = int(count / 5 + 1)
print(f"-----------------------------------------------------------------------------{count}")
print(res)
return render_template('accepted.html', data=list, count=count)
@app.route('/getspecbook', methods=['GET', 'POST'])
def getspecbook():
res = None
natije = None
data2 = None
dbb = MySQLdb.connect(host="localhost",
user="root",
passwd="root",
db="dbproject")
curb = dbb.cursor()
if request.method == 'POST':
message = None
try:
bookid = int(request.form['bookid'])
curb.execute("select message, date_created, bookid, userid from inbox where bookid = %s order by date_created DESC", [bookid])
natije = curb.fetchall()
print('---')
print(natije)
print('---')
count = 0
for i in natije:
count += 1
if count == 0:
message = "اطلاعات موجود نیست"
curb.execute("select message, date_delivered, bookid, userid from deliver_book where bookid = %s order by date_delivered DESC", [bookid])
data2 = curb.fetchall()
except ValueError:
message = "ورودی داده شده نادرست است"
return render_template('getspecbook.html', message=message, data=natije, data2=data2)
return render_template('getspecbook.html', res=res)
@app.route('/searchuser', methods=['GET', 'POST'])
def searchuser():
dbb = MySQLdb.connect(host="localhost",
user="root",
passwd="root",
db="dbproject")
curb = dbb.cursor()
if request.method == 'POST':
details = request.form
surname = details['surname']
username = details['username']
if surname != '' and username != '':
curb.execute("select a.userid, a.username, a.password, i.fname, i.surname, i.address, i.role, a.date_created, a.delay, a.money from user_account a join user_information i where a.userid = i.userid and surname = %s and username = %s", [surname, username])
if surname != '' and username == '':
curb.execute("select a.userid, a.username, a.password, i.fname, i.surname, i.address, i.role, a.date_created, a.delay, a.money from user_account a join user_information i where a.userid = i.userid and surname = %s", [surname])
if surname == '' and username != '':
curb.execute("select a.userid, a.username, a.password, i.fname, i.surname, i.address, i.role, a.date_created, a.delay, a.money from user_account a join user_information i where a.userid = i.userid and username = %s" ,[username])
if surname == '' and username == '':
return render_template('searchuser.html', message='حداقل یکی از فیلدهای جستجو باید پر شود')
global ressearchuser
res = curb.fetchall()
ressearchuser = res
count = 0
for i in res:
count += 1
if count == 0:
message = 'کاربر یا کاربرانی با مشخصات داده شده وجود ندارند'
return render_template('searchuser.html', message=message)
return redirect(url_for('ressearchuser'))
return render_template('searchuser.html')
@app.route('/ressearchuser', methods=['GET', 'POST'])
def ressearchuser():
if request.method == 'POST':
message = ''
count = 0
for i in ressearchuser:
count += 1
count = int(count / 5 + 1)
detail = request.form['page']
print(detail)
try:
page = int(detail)
list = []
if page > count:
count = 0
for i in ressearchuser:
count += 1
count = int(count / 5 + 1)
tt = 0
list = []
for i in ressearchuser:
if tt < 5:
list.append(i)
tt += 1
message= "ورودی داده شده باید کمتر یا برابر با تعداد جدولها باشد"
return render_template('ressearchuser.html', data=list, message=message, count=count)
tt = 0
for i in ressearchuser:
print('-----------')
print(tt)
print(i)
print('-----------')
if tt <= page * 5 - 1 and tt >= (page - 1) * 5:
print("**")
print(tt)
print("**")
list.append(i)
tt += 1
except ValueError:
count = 0
for i in ressearchuser:
count += 1
count = int(count / 5 + 1)
tt = 0
list = []
for i in ressearchuser:
if tt < 5:
list.append(i)
tt += 1
print(count)
return render_template('ressearchuser.html', message='وردی نامعتبر است', count=count, data=list)
return render_template('ressearchuser.html', data=list, message=message, count=count)
count = 0
for i in ressearchuser:
count += 1
count = int(count / 5 + 1)
tt = 0
list = []
for i in ressearchuser:
if tt < 5:
list.append(i)
tt += 1
return render_template('ressearchuser.html', count=count, data=list)
@app.route('/getethg', methods=['GET', 'POST'])
def getethg():
dbb = MySQLdb.connect(host="localhost",
user="root",
passwd="root",
db="dbproject")
curb = dbb.cursor()
if request.method == 'POST':
useridd = request.form['userid']
try:
useridd = int(useridd)
curb.execute("select * from user_information where userid = %s", [useridd])
res1 = curb.fetchall()
infor = []
for i in res1:
infor.append(i)
curb.execute("SELECT * from getbook_opt where userid = %s", [useridd])
res2 = curb.fetchall()
data = []
for i in res2:
data.append(i)
curb.execute("SELECT * from deliver_book where userid = %s", [useridd])
res3 = curb.fetchall()
data2 = []
for i in res3:
data2.append(i)
except ValueError:
return render_template('getethg.html', message='ورودی نامعتبر است')
return render_template('resgetethg.html', data=data, infor=infor, data2=data2)
return render_template('getethg.html')
@app.route('/deliverbook', methods=['GET', 'POST'])
def deliverbook():
dbb = MySQLdb.connect(host="localhost",
user="root",
passwd="root",
db="dbproject")
curb = dbb.cursor()
if request.method == 'POST':
bookid = request.form['bookid']
try:
bookid = int(bookid)
curb.execute("select * from inbox where userid = %s and inboxid = %s and delivered = False", [userid, bookid])
res = curb.fetchall()
count = 0
for i in res:
count += 1
if count == 0:
return render_template('deliverbook.html', message='کتابی به چنین شماره عملیاتی برای شما رزرو نشده است')
print("---------------------------------------------------------------")
print(res)
shomareketab = res[0][4]
print(shomareketab)
print("---------------------------------------------------------------")
sql = 'UPDATE `inbox` SET delivered = True, delays = CASE \
WHEN deliver_date > NOW() THEN False \
WHEN deliver_date < NOW() THEN True\
END\
WHERE inboxid = %s'
curb.execute(sql, [bookid])
dbb.commit()
curb.execute("update book set count = count + 1 where bookid = %s", [shomareketab])
dbb.commit()
curb.execute("INSERT INTO deliver_book(message, userid, bookid) VALUES ('کتاب با موفقیت تحویل داده شد', %s, %s)", [userid, shomareketab])
dbb.commit()
curb.execute("SELECT delays from inbox where inboxid = %s", [bookid])
res = curb.fetchall()[0][0]
if res == True:
curb.execute("UPDATE user_account set delay = delay + 1 where userid = %s", [userid])
dbb.close( )
return render_template('deliverbook.html', messages='کتاب با موفقیت تحویل داده شد')
except ValueError:
return render_template('deliverbook.html', message='ورودی نادرست است')
return render_template('deliverbook.html')
@app.route('/bookhdelay', methods=['GET', 'POST'])
def bookhdelay():
dbb = MySQLdb.connect(host="localhost",
user="root",
passwd="root",
db="dbproject")
curb = dbb.cursor()
curb.execute("SELECT * FROM inbox where deliver_date < CURDATE()")
res = curb.fetchall()
print('--')
print(res)
print('--')
return render_template('bookhdelay.html', data=res)
@app.route('/countbook', methods=['GET', 'POST'])
def countbook():
message = None
dbb = MySQLdb.connect(host="localhost",
user="root",
passwd="root",
db="dbproject")
curb = dbb.cursor()
if request.method == 'POST':
details = request.form
bookidd = details['bookid']
count = details['count']
curb.execute("SELECT * FROM book WHERE bookid = %s", [bookidd])
res = curb.fetchall()
try:
print(res[0])
except IndexError:
return render_template('countbook.html', message='کتاب با چنین شناسه موجود نیست')
try:
curb.execute("update book set count = count + %s where bookid = %s", [count, bookidd])
except MySQLdb.OperationalError:
return render_template('countbook.html', message='نسخه و تعداد کتاب وارد شده باید بزرگتر از صفر باشد')
dbb.commit()
return render_template('countbook.html', messages='افزایش کتاب با موفقیت اعمال شد')
return render_template('countbook.html')
@app.route('/signups', methods=['GET', 'POST'])
def signups():
return render_template('signups.html')