- added product photos, some stuff on personal page

This commit is contained in:
Bernhard Stampfer
2016-02-26 17:22:17 +01:00
parent c0d9cf8ff0
commit 70774e892b
7 changed files with 61 additions and 23 deletions

View File

@@ -150,9 +150,10 @@ def add_product(p):
def get_consumed(user=None, startdate=None, enddate=None): def get_consumed(user=None, startdate=None, enddate=None):
if user is None and startdate is None and enddate is None: if user is None:
rows = query_db('SELECT * FROM CONSUMED') rows = query_db('SELECT * FROM CONSUMED')
else:
rows = query_db('SELECT * FROM CONSUMED WHERE CONSUMER=?', [get_user_by_name(user).id])
consumed = [] consumed = []
for row in rows: for row in rows:
#ID|PRODNR|CONSUMER|PRICE|TIME #ID|PRODNR|CONSUMER|PRICE|TIME
@@ -163,8 +164,9 @@ def get_consumed(user=None, startdate=None, enddate=None):
#2016-01-27 12:59:04 #2016-01-27 12:59:04
c.price = float(row[3]) c.price = float(row[3])
c.time = datetime.datetime.strptime(row[4], "%Y-%m-%d %H:%M:%S") c.time = datetime.datetime.strptime(row[4], "%Y-%m-%d %H:%M:%S")
consumed.append(c) if startdate is None or c.time > startdate:
if enddate is None or c.time < enddate:
consumed.append(c)
return consumed return consumed
def add_consume(username, productid): def add_consume(username, productid):

View File

@@ -49,6 +49,18 @@ div.item { float:left;
text-decoration:none; text-decoration:none;
} }
/* PRODUCT FRAME */
div.product { float:left;
min-width:144px;
min-height:144px;
background-color:#CC3333;
color:white;
padding:5px;
margin:5px;
border-radius:1px;
border:1px solid black;
}
/* MENU ITEM HOVER: greenish */ /* MENU ITEM HOVER: greenish */
div.item:hover { background-color:#00AA88; div.item:hover { background-color:#00AA88;
} }

View File

@@ -1,24 +1,32 @@
{% extends "base.html"%} {% extends "base.html"%}
{% set title = "Konsumieren" %} {% set title = "Konsumieren" %}
{% block content %} {% block content %}
<h3>TODO: </h3>
<ul>
<li>add photos for products, add photos in database</li>
</ul>
<h1> Konsumieren </h1> <h1> Konsumieren </h1>
{% if message %} {% if message %}
<p> {{ message }} </p> <div class="loggedin"> {{ message }} </div>
{% endif %} {% endif %}
<p> <div>
{% if user.isblack %} {% if user.isblack %}
Sorry, du bist geschwärzt! Sorry, du bist geschwärzt!
{% else %} {% else %}
Möchtest du etwas konsumieren? <h2>Möchtest du etwas konsumieren?</h2>
{% for product in products %} {% for product in products %}
{% if product.isshown %} {% if product.isshown %}
<div><p> {{ product.id }}, <a href="/consume?prodid={{product.id}}"> {{product.name}} </a>, {{"%0.2f" % product.price}} € </p> </div> <a href="/consume?prodid={{product.id}}">
<div class="product">
<!-- Produkt {{ product.id }} <br>-->
<div class="center">
<h2>{{product.name}}</h2>
{% set fils = "product_%s.png" % product.name %}
<img src="{{ url_for('static', filename=fils) }}" /><br>
</div>
<div class="right">
{{"%0.2f" % product.price}} €
</div>
</div>
</a>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</p> </div>
{% endblock %} {% endblock %}

View File

@@ -5,13 +5,6 @@
<ul> <ul>
<li>generate new plots if .png missing</li> <li>generate new plots if .png missing</li>
</ul> </ul>
<h1> Bierkonsum </h1>
<img src="{{ url_for('static', filename='total.png') }}">
{% if user %}
{% set fils = "total%03d.png" % user.id %}
<img src="{{ url_for('static', filename=fils) }}">
{% endif %}
<h1> Bierliste </h1> <h1> Bierliste </h1>
<img src="{{ url_for('static', filename='bierliste_small.png') }}"> <img src="{{ url_for('static', filename='bierliste_small.png') }}">
<!-- <table> <!-- <table>

View File

@@ -9,10 +9,11 @@
<p>{{ success }}</p> <p>{{ success }}</p>
{% endif %} {% endif %}
<p> TODO: many </p> <p> TODO: many </p>
<form name="user" method="post" action="/manage_beverages/add"> <form name="user" method="post" action="/manage_beverages/add" enctype="multipart/form-data">
Produktname:<br><input type="text" name="name" required><br> Produktname:<br><input type="text" name="name" required><br>
Preis:<br><input type="number" name="price" step="any" required value="0.0" /><br> Preis:<br><input type="number" name="price" step="any" required value="0.0" /><br>
Angezeigt: <input type="checkbox" name="isshown" checked /><br> Angezeigt: <input type="checkbox" name="isshown" checked /><br>
Bild: <input type="file" name="file"><br>
<input type="submit" value="Hinzufügen"> <input type="submit" value="Hinzufügen">
</form> </form>
{% endblock %} {% endblock %}

View File

@@ -8,11 +8,12 @@
{% if success %} {% if success %}
<p>{{ success }}</p> <p>{{ success }}</p>
{% endif %} {% endif %}
<form name="product" method="post" action="/manage_beverages/edit"> <form name="product" method="post" action="/manage_beverages/edit" enctype="multipart/form-data">
ProduktID:<br><input type="text" name="id" required value="{{product_to_edit.id}}" readonly="readonly" /> <br> ProduktID:<br><input type="text" name="id" required value="{{product_to_edit.id}}" readonly="readonly" /> <br>
ProduktName:<br><input type="text" name="name" required value="{{product_to_edit.name}}" /> <br> ProduktName:<br><input type="text" name="name" required value="{{product_to_edit.name}}" /> <br>
Preis:<br><input type="number" name="price" step="any" required value="{{product_to_edit.price}}" /><br> Preis:<br><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> Angezeigt: <input type="checkbox" name="isshown" {% if product_to_edit.isshown %} checked {% endif %} /><br>
Bild: <input type="file" name="file"><br>
<input type="submit" value="Übernehmen" /> <input type="submit" value="Übernehmen" />
</form> </form>
{% endif %} {% endif %}

View File

@@ -7,6 +7,7 @@ from user import User
from product import Product from product import Product
from consumption import Consumption from consumption import Consumption
import bcrypt import bcrypt
import os
@app.route('/static/<path:path>') @app.route('/static/<path:path>')
@@ -151,7 +152,7 @@ def manage_beverages():
def manage_beverages_edit(name=None): def manage_beverages_edit(name=None):
if request.method == 'GET': if request.method == 'GET':
error = None error = None
p = get_product_by_name(name); p = get_product_by_name(name)
if p is None: if p is None:
error = "Product existiert nicht" error = "Product existiert nicht"
@@ -170,6 +171,16 @@ def manage_beverages_edit(name=None):
else: else:
p.isshown = False p.isshown = False
pic = request.files['file']
print pic.filename
if pic:
extension = pic.filename.rsplit('.', 1)[1].lower()
print extension
if extension == "png" or extension == "jpg":
pic.seek(0) # Move cursor back to beginning so we can write to disk
fpath = os.path.join("./app/static/", "product_%s.png" % p.name)
pic.save(fpath)
update_product(p) update_product(p)
# update_user(u) # update_user(u)
@@ -195,6 +206,16 @@ def manage_beverages_add():
else: else:
p.isshown = False p.isshown = False
pic = request.files['file']
print pic.filename
if pic:
extension = pic.filename.rsplit('.', 1)[1].lower()
print extension
if extension == "png" or extension == "jpg":
pic.seek(0) # Move cursor back to beginning so we can write to disk
fpath = os.path.join("./app/static/", "product_%s.png" % p.name)
pic.save(fpath)
if error is None: if error is None:
add_product(p) 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', success="Konsumat hinzugefuegt.", user=get_user_by_name(session.get('name')))