-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata.py
More file actions
96 lines (81 loc) · 2.7 KB
/
data.py
File metadata and controls
96 lines (81 loc) · 2.7 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
from flask import Flask, flash, redirect, render_template, request, session, abort
import os
from sqlalchemy.orm import sessionmaker
from table import *
# http://mindmapengineers.com/mmeblog/creating-web-app-scratch-using-python-flask-and-mysql-part-3
# implementing bucketList database
engine = create_engine('sqlite:///bucketlist.db', echo=True)
app = Flask(__name__)
# the start-up html page
@app.route('/')
def home():
if not session.get('logged_in'):
return render_template('signin.html')
else:
return "Hello User!"
# the page that is entered after signing in
@app.route('/showBucketList', methods=['POST'])
def do_admin_showBucketList():
POST_USERNAME = str(request.form['username'])
POST_PASSWORD = str(request.form['password'])
print("POST_USERNAME: ", POST_USERNAME)
print("POST_PASSWORD: ", POST_PASSWORD)
Session = sessionmaker(bind=engine)
s = Session()
query = s.query(User).filter(User.username.in_([POST_USERNAME]), User.password.in_([POST_PASSWORD]))
result = query.first()
if result:
session['logged_in'] = True
else:
flash('wrong password!')
return home()
# the logout method
@app.route("/logout")
def logout():
session['logged_in'] = False
return home()
"""
# calls to get a wish
@app.route('/getBucketList')
def getBucketList():
try:
if session.get('user'):
_user = session.get('user')
con = mysql.connect()
cursor = con.cursor()
cursor.callproc('sp_GetBucketListByUser', (_user,))
bucketList = cursor.fetchall()
wishes_dict = []
for wish in bucketList:
wish_dict = {
'Title': bucketList[1],
'Description': bucketList[2]
wishes_dict.append(wish_dict)
return json.dumps(wishes_dict)
else:
return render_template('/')
except Exception as e:
return render_template('/', error=str(e))
# calls to add to bucketList
@app.route('/addBucketList', methods=['POST'])
def addBucketList():
try:
if session.get('user'):
_title = request.form['inputTitle']
_description = request.form['inputDescription']
_user = session.get('user')
conn = mysql.connect()
cursor = conn.cursor()
cursor.callproc('sp_addBucketList', (_title, _description, _user))
data = cursor.fetchall()
if len(data) is 0:
conn.commit()
return redirect('/signin')
finally:
cursor.close()
conn.close()
"""
# method to run application
if __name__ == "__main__":
app.secret_key = os.urandom(12)
app.run()