- 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

@@ -7,6 +7,7 @@ from user import User
from product import Product
from consumption import Consumption
import bcrypt
import os
@app.route('/static/<path:path>')
@@ -151,7 +152,7 @@ def manage_beverages():
def manage_beverages_edit(name=None):
if request.method == 'GET':
error = None
p = get_product_by_name(name);
p = get_product_by_name(name)
if p is None:
error = "Product existiert nicht"
@@ -170,6 +171,16 @@ def manage_beverages_edit(name=None):
else:
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_user(u)
@@ -195,6 +206,16 @@ def manage_beverages_add():
else:
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:
add_product(p)
return render_template('manage_beverages_add.html', success="Konsumat hinzugefuegt.", user=get_user_by_name(session.get('name')))