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

20
shop.py
View File

@ -123,10 +123,17 @@ def index():
if session.get('id') is None:
data = {"title":"Login"}
return render_template("auth.html", data=data)
#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"], "list_ids": session["list_ids"]}
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)
@ -134,6 +141,7 @@ def index():
@app.route('/post', methods=['POST'])
def handle_data():
if "addValue" in request.form:
for x in request.form:
if request.form[x] == '':
@ -177,6 +185,10 @@ def handle_data():
if "logout" in request.form:
session.clear()
if "changeList" in request.form:
pprint(request.form["changeList"])
return redirect(url_for('index'))
@app.route("/admin")

View File

@ -1,5 +1,5 @@
* {
color: azure;
color: azure;
}
aside {
width: 20%;

View File

@ -1,7 +1,21 @@
{% include "header.html" %}
<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> -->
<div id="addForm">
{% include "addForm.html" %}
@ -26,7 +40,7 @@
</i></button></a>
</div>
<div>
{{data["list_ids"]}}
</div>
</div>
<!-- jQuery library -->