-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
210 lines (165 loc) · 5.83 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
from flask import Flask, render_template, request, redirect, url_for, flash, session
from db import DBhandler
import sys
import sqlite3
application = Flask(__name__)
application.secret_key = 'SUPERSECRETKEY'
DB = DBhandler()
@application.route("/")
def hello():
return render_template("index.html")
@application.route("/list")
def view_list():
datas = DB.get_restaurants()
total_count = len(datas)
return render_template("list.html", datas = datas, total_count = total_count)
@application.route("/review")
def view_review():
return render_template("review.html")
@application.route("/register_restaurant")
def reg_restaurant():
return render_template("register_restaurant.html")
@application.route("/submit_restaurant")
def reg_restaurant_submit():
name=request.args.get("name")
addr=request.args.get("addr")
tel=request.args.get("tel")
category=request.args.get("category")
park=request.args.get("park")
time=request.args.get("time")
site=request.args.get("site")
print(name,addr,tel,category,park,time,site)
@application.route("/submit_restaurant_post", methods=['POST'])
def reg_restaurant_submit_post():
image_file=request.files["file"]
image_file.save("static/{}".format(image_file.filename))
data=request.form
if DB.insert_restaurant(data['name'], data, image_file.filename):
return render_template("submit_restaurant_result.html", data=data, image_path="static/"+image_file.filename)
else:
return "Restaurant name already exist!"
@application.route('/dynamicurl/<variable_name>')
def DynamicUrl(variable_name):
return str(variable_name)
# 상세페이지
@application.route("/view_detail/<name>/")
def view_restaurant_detail(name):
data = DB.get_restaurant_byname(str(name))
if str(data) == "None":
flash("올바르지 않은 맛집 이름입니다.")
return view_list()
return render_template("detail.html", name = name, data=data)
@application.route("/remove",methods=['POST'])
def remove():
data = request.form
if(session['id'] != data['writer']):
flash("작성자가 아닙니다.")
return view_restaurant_detail(data['name'])
DB.remove_restaurant(data['name'])
return view_list()
@application.route("/modify",methods=['POST'])
def modify():
data = request.form
if(session['id'] != data['writer']):
flash("작성자가 아닙니다.")
return view_restaurant_detail(data['name'])
datas = DB.get_restaurant_byname(data['name'])
return render_template("modify_info.html", datas=datas)
@application.route("/modify_restaurant_post", methods=['POST'])
def mod_restaurant_submit_post():
image_file=request.files["file"]
data=request.form
if(image_file.filename == ''):
image_file.filename = (data['origin_img_path'])
if DB.modify_restaurant(data['origin_name'], data, image_file.filename):
return view_restaurant_detail(data['name'])
else:
return "Restaurant name already exist!"
@application.route("/register_review")
def reg_review():
return render_template("register_review.html")
@application.route("/board")
def view_board():
return render_template("board.html")
@application.route("/signup")
def signup():
return render_template("signup.html")
@application.route("/signup_post", methods=['POST'])
def register_user():
conn=sqlite3.connect("database.db", check_same_thread=False)
cor = conn.cursor()
conn.row_factory = sqlite3.Row
id_=request.form['id']
pw_=request.form['pw']
cor.execute("INSERT INTO user(id, pw) VALUES(?,?)",(id_,pw_))
cor.close()
conn.commit()
conn.close()
return redirect('/login')
@application.route("/login")
def login():
return render_template("login.html")
@application.route("/login_confirm", methods=['POST'])
def login_user():
if request.method == 'POST':
id_=request.form['id']
pw_=request.form['pw']
if DB.find_user(id_, pw_):
session['logFlag'] = True
session['id']=id_
return redirect(url_for('view_list'))
else:
return redirect(url_for('login'))
else:
return render_template("login.html")
@application.route("/logout", methods=['GET'])
def logout():
session.clear()
return redirect('/')
@application.route("/notice")
def view_notice():
return render_template("notice.html")
# db에서 사용자 비번 조회해서 넘겨주기
@application.route("/myaccount")
def getUser():
if session.get('logFlag') != True:
return redirect('/login')
conn = sqlite3.connect('database.db')
cursor = conn.cursor()
sql = "select pw from user where id = ?"
id= session['id']
cursor.execute(sql, (id,))
row = cursor.fetchone()
user_pw=row[0]
conn.commit()
conn.close()
return render_template('myaccount.html', id=id, pw=user_pw)
# db에서 사용자 비번 조회해서 넘겨주기
@application.route("/myaccount_edit")
def editUser():
if session.get('logFlag') != True:
return redirect('/login')
conn = sqlite3.connect('database.db')
cursor = conn.cursor()
sql = "select pw from user where id = ?"
id= session['id']
cursor.execute(sql, (id,))
row = cursor.fetchone()
user_pw=row[0]
conn.commit()
conn.close()
return render_template('myaccount_edit.html', id=id, pw=user_pw)
# db에서 사용자 정보 수정
@application.route("/myaccount_edit_proc", methods=['POST'])
def myaccount_edit_proc():
uid=session['id']
upw=request.form['pw']
conn = sqlite3.connect('database.db')
cursor = conn.cursor()
sql = "update user set pw=? where id = ?"
cursor.execute(sql, (upw,uid))
conn.commit()
conn.close()
return redirect('/login')
if __name__ == "__main__":
application.run(host='0.0.0.0', port=5000, debug=True)