app.py
3.66 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
# -*- coding: utf8 -*-
from flask import request, render_template, redirect, session, flash, Flask
from Users import *
from ReservationControl import *
from datetime import datetime
app = Flask(__name__)
app.secret_key = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'
@app.route('/', redirect_to="/login")
def http_prepost_response():
return "helloworld"
@app.route('/login', methods=["GET"])
def login():
if session.get('ID'):
return redirect('/myhome')
elif request.args.get('retry') == 'true':
return render_template("login.html", retry=True)
return render_template("login.html", retry=False)
@app.route('/join')
def join():
return render_template('join.html')
@app.route('/join/confirm', methods=['POST'])
def join_confirm():
join_item = request.form
print(join_item)
if UserJoin(join_item.get('id'),join_item.get('deptid'),join_item.get('name'),join_item.get('password'),join_item.get('phone'),join_item.get('email')):
flash('회원가입 성공!')
return redirect('/login')
flash('회원가입 실패!')
return redirect('/join')
@app.route('/logincheck', methods=["POST"])
def login_check():
IDPW = request.form
if UserLogin(IDPW.get('id'),IDPW.get('pw')):
session['ID'] = IDPW.get('id')
welcome = IDPW.get('id')+" 님 안녕하세요!"
flash(welcome)
return redirect('/myhome')
flash("ID와 비밀번호를 확인해주세요.")
return redirect('/login?retry=true')
@app.route('/myhome')
def mystat():
return render_template("myhome.html", ID=session['ID'])
@app.route('/viewresv')
def view_resv():
resv_list = getReservations(session['ID'])
print(resv_list)
return render_template('resv_view.html', resv_list=resv_list)
@app.route('/deleteresv', methods=['POST'])
def delete_resv():
resv_id = request.form
if deleteReservations(resv_id.get('resv_id')):
flash("예약이 삭제되었습니다")
else:
flash("예약 삭제에 실패했습니다")
return redirect('/viewresv')
@app.route('/search')
def book():
return render_template("resv_sch.html", ID=session['ID'])
@app.route('/search/result', methods=['POST'])
def search_result():
searchdata = request.form
starttime = datetime.strptime(searchdata.get('starttime'),'%Y-%m-%dT%H:%M')
endtime = datetime.strptime(searchdata.get('endtime'),'%Y-%m-%dT%H:%M')
if(starttime.strftime('%Y%m%d') == endtime.strftime('%Y%m%d')):
result = getAvailableFacilities(searchdata.get('deptid'),searchdata.get('capacity'),starttime,endtime)
print(result)
return render_template("searchresult.html", resv_list=result, starttime=starttime, endtime=endtime)
else:
flash("2일 이상의 일정으로 예약 불가합니다")
return redirect("/search")
@app.route('/search/resv', methods=['POST'])
def book_confirm():
book_query=request.form
print(book_query)
starttime = datetime.strptime(book_query.get('start_time'), '%Y-%m-%d%H:%M')
endtime = datetime.strptime(book_query.get('end_time'), '%Y-%m-%d%H:%M')
if addReservations(session['ID'],book_query.get('fac_id'),starttime,endtime):
flash("예약에 성공했습니다")
return redirect('/myhome')
else:
flash("예약에 실패했습니다.")
return redirect('/search')
@app.route('/logout')
def logout():
session.clear()
flash("로그아웃 되었습니다.")
return redirect('/login')
if __name__ == '__main__':
print("done")
app.config['SESSION_TYPE'] = 'filesystem'
app.run(host="0.0.0.0", port=80)