This repository has been archived by the owner on Oct 28, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
routes.py
55 lines (45 loc) · 2.25 KB
/
routes.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
from __init__ import app
from flask import render_template, request, url_for, redirect, session
from user_system.user_forms import LoginForm
from user_system.user_models import buyer_valid_login
from user_system.user_route import *
from ticket_book.ticket_route import *
@app.route('/', methods=['POST','GET'])
@app.route('/index', methods=['POST','GET'])
def index():
loginform = LoginForm()
querygood = QueryGoodsForm()
if request.method == "GET":
literatures = show_good_l(category='literature')
knowledges = show_good_k(category='knowledge')
lifes = show_good_li(category='life')
managements = show_good_m(category='management')
techs = show_good_t(category='tech')
wanteds = show_good_w(category='wanteds')
return render_template("ticket_template/tourist_index.html",logform=loginform, goodform=querygood,literatures=literatures,knowledges=knowledges,lifes=lifes,managements=managements,techs=techs,wanteds=wanteds)
else:
if request.form['key'] == "login":
loginform = LoginForm(formdata=request.form)
if loginform.validate():
username = loginform.data['username']
password = loginform.data['password']
if buyer_valid_login(username, password):
session['username'] = username
print("success")
return redirect(url_for("buyer_index"))
else :
return render_template('ticket_template/tourist_index.html', logform=loginform, goodform=querygood)
elif request.form['key'] == 'query':
querygoodform = QueryGoodsForm(form=request.form)
loginform = LoginForm()
if querygoodform.validate():
bookname = querygoodform.data['bookname']
query = book_info_query(bookname)
return render_template('ticket_template/tourist_index.html', title='Home', logform=loginform, goodform=querygoodform,query=query)
return redirect(url_for("index"))
@app.route('/logout',methods=['POST', "GET"])
def logout():
session.pop('username', None)
return redirect(url_for('index'))
if __name__ == '__main__':
app.run()