Made the session handle the active list
This commit is contained in:
parent
7082dc86fe
commit
a3254343cc
BIN
__pycache__/shop.cpython-38.pyc
Normal file
BIN
__pycache__/shop.cpython-38.pyc
Normal file
Binary file not shown.
36
shop.py
36
shop.py
@ -120,28 +120,38 @@ app.secret_key = b'*$#@U9423jr92jioJKL_)_;dasfj()12'
|
||||
|
||||
@app.route('/')
|
||||
def index():
|
||||
print(f"ID in session is: {session['active_id']}")
|
||||
if session.get('id') is None:
|
||||
data = {"title":"Login"}
|
||||
return render_template("auth.html", data=data)
|
||||
try:
|
||||
if request.args["list"]:
|
||||
print(request.args["list"])
|
||||
res = get_items(session["id"], request.args["list"])
|
||||
|
||||
if session["active_id"] == "0":
|
||||
print("Heres")
|
||||
res = get_items(session["id"])
|
||||
else:
|
||||
res = get_items(session["id"])
|
||||
data = {"title": "Shopping List", "results": res, "username": session["username"], "list_ids": session["list_ids"]}
|
||||
except KeyError:
|
||||
#Get initial data, contains all lists the user is apart of unless list is defined
|
||||
res = get_items(session["id"])
|
||||
data = {"title": "Shopping List", "results": res, "username": session["username"], "list_ids": session["list_ids"]}
|
||||
res = get_items(session["id"], session["active_id"])
|
||||
data = {"title": "Shopping List", "results": res, "session": session, "list_ids": session["list_ids"]}
|
||||
#Store active list in the session
|
||||
# try:
|
||||
# if request.args["list"]:
|
||||
# print(request.args["list"])
|
||||
# res = get_items(session["id"], request.args["list"])
|
||||
# else:
|
||||
# res = get_items(session["id"])
|
||||
# data = {"title": "Shopping List", "results": res, "username": session["username"], "list_ids": session["list_ids"]}
|
||||
# except KeyError:
|
||||
# #Get initial data, contains all lists the user is apart of unless list is defined
|
||||
# res = get_items(session["id"])
|
||||
# data = {"title": "Shopping List", "results": res, "username": session["username"], "list_ids": session["list_ids"]}
|
||||
for device in MOBILES:
|
||||
if device in request.user_agent.platform:
|
||||
return render_template('mobile.html', data=data)
|
||||
print(session["list_ids"])
|
||||
return render_template('index.html', data=data)
|
||||
|
||||
@app.route('/post', methods=['POST'])
|
||||
def handle_data():
|
||||
|
||||
print(request.form)
|
||||
if "addValue" in request.form:
|
||||
for x in request.form:
|
||||
if request.form[x] == '':
|
||||
@ -166,6 +176,7 @@ def handle_data():
|
||||
session["username"] = res[0][1]
|
||||
session["isAdmin"] = res[0][2]
|
||||
session["list_ids"] = list_ids
|
||||
session["active_id"] = "0"
|
||||
|
||||
if "newuser" in request.form:
|
||||
#first check if the user exists
|
||||
@ -188,6 +199,9 @@ def handle_data():
|
||||
|
||||
if "changeList" in request.form:
|
||||
pprint(request.form["changeList"])
|
||||
if "list" in request.form:
|
||||
print(f"Change session to {request.form['list']}")
|
||||
session["active_id"] = request.form['list']
|
||||
|
||||
return redirect(url_for('index'))
|
||||
|
||||
|
||||
@ -1,14 +1,14 @@
|
||||
{% include "header.html" %}
|
||||
|
||||
<body>
|
||||
<h1 class="container" style="text-align: center">{{ data["title"] }}, {{data["username"].title()}}
|
||||
<h1 class="container" style="text-align: center">{{ data["title"] }}, {{data["session"]["username"].title()}}
|
||||
<div class="dropdown">
|
||||
<form action="/" method="get" id="test">
|
||||
<form action="/post" method="post" id="test">
|
||||
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
|
||||
Lists
|
||||
{{data["session"]["active_id"]}}
|
||||
</button>
|
||||
<div class="dropdown-menu" aria-labelledby="dropdownMenu2">
|
||||
<button class="dropdown-item" type="submit" value="" id="" name="list">All</button>
|
||||
<button class="dropdown-item" type="submit" value="0" id="" name="list">All</button>
|
||||
{% for id, name in data["list_ids"] %}
|
||||
<button class="dropdown-item" type="submit" value="{{id}}" id="{{id}}" name="list">{{name}}</button>
|
||||
{% endfor %}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user