Added list selection on index

This commit is contained in:
Benjamyn Love 2020-02-10 19:11:28 +11:00
parent 2d4a35814d
commit 7082dc86fe
3 changed files with 33 additions and 7 deletions

16
shop.py
View File

@ -123,8 +123,15 @@ def index():
if session.get('id') is None: if session.get('id') is None:
data = {"title":"Login"} data = {"title":"Login"}
return render_template("auth.html", data=data) return render_template("auth.html", data=data)
try:
#Get initial data, contains all lists the user is apart of 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"]) res = get_items(session["id"])
data = {"title": "Shopping List", "results": res, "username": session["username"], "list_ids": session["list_ids"]} data = {"title": "Shopping List", "results": res, "username": session["username"], "list_ids": session["list_ids"]}
for device in MOBILES: for device in MOBILES:
@ -134,6 +141,7 @@ def index():
@app.route('/post', methods=['POST']) @app.route('/post', methods=['POST'])
def handle_data(): def handle_data():
if "addValue" in request.form: if "addValue" in request.form:
for x in request.form: for x in request.form:
if request.form[x] == '': if request.form[x] == '':
@ -177,6 +185,10 @@ def handle_data():
if "logout" in request.form: if "logout" in request.form:
session.clear() session.clear()
if "changeList" in request.form:
pprint(request.form["changeList"])
return redirect(url_for('index')) return redirect(url_for('index'))
@app.route("/admin") @app.route("/admin")

View File

@ -1,7 +1,21 @@
{% include "header.html" %} {% include "header.html" %}
<body> <body>
<h1 class="container" style="text-align: center">{{ data["title"] }}, {{data["username"].title()}}</h1> <h1 class="container" style="text-align: center">{{ data["title"] }}, {{data["username"].title()}}
<div class="dropdown">
<form action="/" method="get" id="test">
<button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenu2" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Lists
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenu2">
<button class="dropdown-item" type="submit" value="" 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 %}
</div>
</form>
</div>
</h1>
<!-- <aside> --> <!-- <aside> -->
<div id="addForm"> <div id="addForm">
{% include "addForm.html" %} {% include "addForm.html" %}
@ -26,7 +40,7 @@
</i></button></a> </i></button></a>
</div> </div>
<div> <div>
{{data["list_ids"]}}
</div> </div>
</div> </div>
<!-- jQuery library --> <!-- jQuery library -->