diff --git a/shop.py b/shop.py index 385b8e5..b38f22b 100644 --- a/shop.py +++ b/shop.py @@ -99,6 +99,15 @@ def update_pass(user_id, newpass): data = (newpass, user_id) runQuery(query, data) +def get_items(user_id, list_id=None): + if list_id != None: + query = "select SHOPLIST.id, SHOPLIST.item, SHOPLIST.gotten, USERS.username from SHOPLIST inner join USERS on SHOPLIST.user_id = USERS.id inner join USER_META on SHOPLIST.list_id = USER_META.list_id where USER_META.user_id = %s and SHOPLIST.list_id = %s" + data = (user_id, list_id) + return runQuery(query, data) + query = "select SHOPLIST.id, SHOPLIST.item, SHOPLIST.gotten, USERS.username from SHOPLIST inner join USERS on SHOPLIST.user_id = USERS.id inner join USER_META on SHOPLIST.list_id = USER_META.list_id where USER_META.user_id = %s" + data = (user_id,) + return runQuery(query, data) + app = Flask(__name__) app.config["DEBUG"] = True app.secret_key = b'*$#@U9423jr92jioJKL_)_;dasfj()12' @@ -109,8 +118,9 @@ def index(): data = {"title":"Login"} return render_template("auth.html", data=data) - query = readFromDB() - data = {"title": "Shopping List", "results": query, "username": session["username"]} + #Get initial data, contains all lists the user is apart of + res = get_items(session["id"]) + data = {"title": "Shopping List", "results": res, "username": session["username"]} for device in MOBILES: if device in request.user_agent.platform: return render_template('mobile.html', data=data)