diff --git a/app/database.py b/app/database.py index fa754f2..d274dec 100644 --- a/app/database.py +++ b/app/database.py @@ -111,20 +111,42 @@ def get_products(): p.id = row[0] p.name = row[1] p.price = row[2] + p.isshown = row[3] products.append(p) return products def get_product_by_id(id): - row = query_db("SELECT * FROM PRODUCTS WHERE ID = ?", str(id), one=True) - print row + row = query_db("SELECT * FROM PRODUCTS WHERE ID = ?", [str(id)], one=True) +# print row p = Product() p.id = row[0] p.name = row[1] p.price = row[2] + p.isshown = row[3] return p +def get_product_by_name(name): + row = query_db("SELECT * FROM PRODUCTS WHERE NAME = ?", [str(name)], one=True) + p = Product() + p.id = row[0] + p.name = row[1] + p.price = row[2] + p.isshown = row[3] + return p + + +def update_product(p): + query_db("UPDATE products SET NAME=?, PRICE=?, ISSHOWN=? WHERE ID=?", (p.name, p.price, p.isshown, p.id)) + get_db().commit() + + +def add_product(p): + query_db("Insert INTO PRODUCTS (NAME, PRICE, ISSHOWN) VALUES (?, ?, ?)", (p.name, p.price, p.isshown)) + get_db().commit() + + def get_consumed(user=None, startdate=None, enddate=None): if user is None and startdate is None and enddate is None: diff --git a/app/product.py b/app/product.py index 98bc1aa..bab3364 100644 --- a/app/product.py +++ b/app/product.py @@ -3,4 +3,5 @@ class Product: def __init__(self): self.id = 0 self.name = "" - self.price = 0.0 \ No newline at end of file + self.price = 0.0 + self.isshown = False diff --git a/app/templates/manage_beverages.html b/app/templates/manage_beverages.html index d1f7db6..d3fedd1 100644 --- a/app/templates/manage_beverages.html +++ b/app/templates/manage_beverages.html @@ -7,8 +7,24 @@
{{ product.id }}, {{product.name}}, {{product.price}} €
| ID | +Name | +Preis | +Wird angezeigt | ++ |
|---|---|---|---|---|
| {{product.id}} | +{{product.name}} | +{{product.price}} | +{% if product.isshown %} ☑ {% else %} ☐ {% endif %} | +bearbeiten | +
Fehler: {{ error }}
+ {% endif %} + {% if success %} +{{ success }}
+ {% endif %} +TODO: many
+ +{% endblock %} \ No newline at end of file diff --git a/app/templates/manage_beverages_edit.html b/app/templates/manage_beverages_edit.html new file mode 100644 index 0000000..22cd882 --- /dev/null +++ b/app/templates/manage_beverages_edit.html @@ -0,0 +1,19 @@ +{% extends "base.html"%} +{% set title = "Konsumat bearbeiten" %} +{% block content %} +Fehler: {{ error }}
+ {% else %} + {% if success %} +{{ success }}
+ {% endif %} + + {% endif %} +{% endblock %} \ No newline at end of file diff --git a/app/templates/manage_products_add.html b/app/templates/manage_products_add.html deleted file mode 100644 index 2207ff7..0000000 --- a/app/templates/manage_products_add.html +++ /dev/null @@ -1,16 +0,0 @@ -{% extends "base.html"%} -{% set title = "Produkt hinzufügen" %} -{% block content %} -Fehler: {{ error }}
- {% endif %} - {% if success %} -{{ success }}
- {% endif %} -TODO: many
- -{% endblock %} \ No newline at end of file diff --git a/app/views.py b/app/views.py index cd298bf..ac22164 100644 --- a/app/views.py +++ b/app/views.py @@ -138,6 +138,65 @@ def manage_beverages(): products = get_products() return render_template('manage_beverages.html', products=products, user=get_user_by_name(session.get('name'))) + +@app.route('/manage_beverages/edit', methods=['POST']) +@app.route('/manage_beverages/edit/