From 7082dc86fef551aba7536c08ebcae13d534537d1 Mon Sep 17 00:00:00 2001 From: Benjamyn Love Date: Mon, 10 Feb 2020 19:11:28 +1100 Subject: [PATCH] Added list selection on index --- shop.py | 20 ++++++++++++++++---- static/css/main.css | 2 +- templates/index.html | 18 ++++++++++++++++-- 3 files changed, 33 insertions(+), 7 deletions(-) diff --git a/shop.py b/shop.py index 9dd9d03..98ba8c1 100644 --- a/shop.py +++ b/shop.py @@ -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") diff --git a/static/css/main.css b/static/css/main.css index f9bad10..33de747 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -1,5 +1,5 @@ * { - color: azure; + color: azure; } aside { width: 20%; diff --git a/templates/index.html b/templates/index.html index df23087..7f57c8f 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1,7 +1,21 @@ {% include "header.html" %} -

{{ data["title"] }}, {{data["username"].title()}}

+

{{ data["title"] }}, {{data["username"].title()}} + +

{% include "addForm.html" %} @@ -26,7 +40,7 @@
- {{data["list_ids"]}} +