- add: add beverages
This commit is contained in:
@@ -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:
|
||||
|
||||
BIN
app/database.pyc
BIN
app/database.pyc
Binary file not shown.
@@ -4,3 +4,4 @@ class Product:
|
||||
self.id = 0
|
||||
self.name = ""
|
||||
self.price = 0.0
|
||||
self.isshown = False
|
||||
|
||||
BIN
app/product.pyc
BIN
app/product.pyc
Binary file not shown.
@@ -7,8 +7,24 @@
|
||||
</ul>
|
||||
<h1> Konsumatverwaltung </h1>
|
||||
|
||||
{% for product in products %}
|
||||
<div><p> {{ product.id }}, {{product.name}}, {{product.price}} €</p></div>
|
||||
{% endfor %}
|
||||
<a href=/manage_beverages/add>Getränk Hinzufügen</a></li>
|
||||
<table>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Name</th>
|
||||
<th>Preis</th>
|
||||
<th>Wird angezeigt</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
{% for product in products %}
|
||||
<tr>
|
||||
<td>{{product.id}}</td>
|
||||
<td>{{product.name}}</td>
|
||||
<td>{{product.price}}</td>
|
||||
<td>{% if product.isshown %} ☑ {% else %} ☐ {% endif %} </td>
|
||||
<td> <a href="/manage_beverages/edit/{{product.name}}">bearbeiten</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
<br />
|
||||
<a href=/manage_beverages/add>Getränk Hinzufügen</a></li>
|
||||
{% endblock %}
|
||||
18
app/templates/manage_beverages_add.html
Normal file
18
app/templates/manage_beverages_add.html
Normal file
@@ -0,0 +1,18 @@
|
||||
{% extends "base.html"%}
|
||||
{% set title = "Produkt hinzufügen" %}
|
||||
{% block content %}
|
||||
<h1> Produkt hinzufügen</h1>
|
||||
{% if error %}
|
||||
<p>Fehler: {{ error }}</p>
|
||||
{% endif %}
|
||||
{% if success %}
|
||||
<p>{{ success }}</p>
|
||||
{% endif %}
|
||||
<p> TODO: many </p>
|
||||
<form name="user" method="post" action="/manage_beverages/add">
|
||||
Produktname:<input type="text" name="name" required><br>
|
||||
Preis:<input type="number" name="price" step="any" required value="0.0" /> € <br>
|
||||
Angezeigt: <input type="checkbox" name="isshown" checked /><br>
|
||||
<input type="submit" value="Hinzufügen">
|
||||
</form>
|
||||
{% endblock %}
|
||||
19
app/templates/manage_beverages_edit.html
Normal file
19
app/templates/manage_beverages_edit.html
Normal file
@@ -0,0 +1,19 @@
|
||||
{% extends "base.html"%}
|
||||
{% set title = "Konsumat bearbeiten" %}
|
||||
{% block content %}
|
||||
<h1> {{product_to_edit.name}} bearbeiten</h1>
|
||||
{% if error %}
|
||||
<p>Fehler: {{ error }}</p>
|
||||
{% else %}
|
||||
{% if success %}
|
||||
<p>{{ success }}</p>
|
||||
{% endif %}
|
||||
<form name="product" method="post" action="/manage_beverages/edit">
|
||||
Userid: <input type="text" name="id" required value="{{product_to_edit.id}}" readonly="readonly" /> <br>
|
||||
Username:<input type="text" name="name" required value="{{product_to_edit.name}}" /> <br>
|
||||
Preis:<input type="number" name="price" step="any" required value="{{product_to_edit.price}}" /> € <br>
|
||||
Angezeigt: <input type="checkbox" name="isshown" {% if product_to_edit.isshown %} checked {% endif %} /><br>
|
||||
<input type="submit" value="Übernehmen" />
|
||||
</form>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
@@ -1,16 +0,0 @@
|
||||
{% extends "base.html"%}
|
||||
{% set title = "Produkt hinzufügen" %}
|
||||
{% block content %}
|
||||
<h1> Produkt hinzufügen</h1>
|
||||
{% if error %}
|
||||
<p>Fehler: {{ error }}</p>
|
||||
{% endif %}
|
||||
{% if success %}
|
||||
<p>{{ success }}</p>
|
||||
{% endif %}
|
||||
<p> TODO: many </p>
|
||||
<form name="user" method="post" action="/manage_users/add">
|
||||
Produktname:<input type="text" name=username required placeholder="Username"><br>
|
||||
Preis:<input type="password" name=password1 required placeholder="Password"><br>
|
||||
</form>
|
||||
{% endblock %}
|
||||
59
app/views.py
59
app/views.py
@@ -136,6 +136,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/<name>', methods=['GET'])
|
||||
@requires_baron
|
||||
def manage_beverages_edit(name=None):
|
||||
if request.method == 'GET':
|
||||
error = None
|
||||
p = get_product_by_name(name);
|
||||
|
||||
if p is None:
|
||||
error = "Product existiert nicht"
|
||||
|
||||
return render_template('manage_beverages_edit.html', product_to_edit=p, error=error, user=get_user_by_name(session.get('name')))
|
||||
|
||||
if request.method == 'POST':
|
||||
p = Product()
|
||||
#print request.form
|
||||
p.id = request.form['id']
|
||||
p.name = request.form['name']
|
||||
p.price = float(request.form['price'])
|
||||
|
||||
if 'isshown' in request.form:
|
||||
p.isshown = True
|
||||
else:
|
||||
p.isshown = False
|
||||
|
||||
update_product(p)
|
||||
|
||||
# update_user(u)
|
||||
|
||||
return redirect('/manage_beverages')
|
||||
|
||||
|
||||
@app.route('/manage_beverages/add', methods=['POST', 'GET'])
|
||||
@requires_baron
|
||||
def manage_beverages_add():
|
||||
if request.method == 'POST':
|
||||
p = Product()
|
||||
error = None
|
||||
print request
|
||||
p.name = request.form['name']
|
||||
#if request.form['price'].isnumeric():
|
||||
p.price = float(request.form['price'])
|
||||
#else:
|
||||
# error = "Preis muss eine Nummer sein."
|
||||
|
||||
if 'isshown' in request.form:
|
||||
p.isshown = True
|
||||
else:
|
||||
p.isshown = False
|
||||
|
||||
if error is None:
|
||||
add_product(p)
|
||||
return render_template('manage_beverages_add.html', success="Konsumat hinzugefuegt.", user=get_user_by_name(session.get('name')))
|
||||
|
||||
return render_template('manage_beverages_add.html', error=error, user=get_user_by_name(session.get('name')))
|
||||
return render_template('manage_beverages_add.html', user=get_user_by_name(session.get('name')))
|
||||
|
||||
|
||||
@app.route('/consume')
|
||||
@requires_login
|
||||
def consume():
|
||||
|
||||
BIN
app/views.pyc
BIN
app/views.pyc
Binary file not shown.
@@ -32,7 +32,8 @@ CREATE TABLE USERS(
|
||||
CREATE TABLE PRODUCTS(
|
||||
ID INTEGER PRIMARY KEY,
|
||||
NAME TEXT NOT NULL,
|
||||
PRICE REAK NOT NULL
|
||||
PRICE REAL NOT NULL,
|
||||
ISSHOWN BOOLEAN DEFAULT 0
|
||||
);
|
||||
|
||||
# The table CONSUMED contains all products that have been consumed, who it consumend, when it was consumed, and also if they have been payed allready, this is important because we do not want to have redunant data.
|
||||
|
||||
6
run.py
6
run.py
@@ -7,10 +7,10 @@ import thread
|
||||
|
||||
if __name__ == '__main__':
|
||||
#start gui
|
||||
wx = wx.App()
|
||||
gui.MainWindow(None)
|
||||
#wx = wx.App()
|
||||
#gui.MainWindow(None)
|
||||
|
||||
thread.start_new_thread(wx.MainLoop,())
|
||||
#thread.start_new_thread(wx.MainLoop,())
|
||||
|
||||
# start flask
|
||||
app.secret_key = urandom(24)
|
||||
|
||||
BIN
test/database.db
BIN
test/database.db
Binary file not shown.
Reference in New Issue
Block a user