From 79bcf2e8ca832f5a902f299592440e3249f9905f Mon Sep 17 00:00:00 2001 From: Ulrich Knechtelsdorfer Date: Sat, 13 Feb 2016 22:05:49 +0100 Subject: [PATCH] - add: add beverages --- app/database.py | 26 +++++++++- app/database.pyc | Bin 5711 -> 6710 bytes app/product.py | 3 +- app/product.pyc | Bin 526 -> 559 bytes app/templates/manage_beverages.html | 26 ++++++++-- app/templates/manage_beverages_add.html | 18 +++++++ app/templates/manage_beverages_edit.html | 19 ++++++++ app/templates/manage_products_add.html | 16 ------ app/views.py | 59 +++++++++++++++++++++++ app/views.pyc | Bin 5292 -> 6775 bytes doc/database.txt | 3 +- run.py | 6 +-- test/database.db | Bin 4096 -> 4096 bytes 13 files changed, 148 insertions(+), 28 deletions(-) create mode 100644 app/templates/manage_beverages_add.html create mode 100644 app/templates/manage_beverages_edit.html delete mode 100644 app/templates/manage_products_add.html 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/database.pyc b/app/database.pyc index cc0caff088218691277d42e3e00738984a92ad94..89eeda7b5f16f8d56ffd2ec3bf51391577863100 100644 GIT binary patch delta 1005 zcma)4OHUI~6h3F#4wOFW%T`(#2#`Sx%Qv9F>&R>bB01l+}O_fdgk1F&-b10_DAyTSlsr@(=l~&zF39U z$4*}jq(U{1ssnrGvl)#kWKtiGv`@TB?D#;LQN>FJ7 z!VfTjZufNz5kbs&Qz+E*|h5iZPU)8(Af;xUv` zuB;T&bGfNhQkmECnVd*_V*WPTc`?R?WU=o_h!Ow9T{g3^t*@E2OQ}axG3*3@186zR z!mgYhC1G9f*6DA-!bl$pv*cYDHc2P)b)&XxD)~aWNJ5I)g-p4ms4T4|EUDy6r6*UPVLvF2t-vKke|usQr>g+!9OD5$FuK& z28L&NyLHmKN$V0Hiee~=lj23_GoA`}xEs60a5!-*#RP1x_LRX!V7dsZTXmzcxoy7O zs%z|yHYs+)%RTow9cOsJVELToY?eR;G3tLTLXl2Pior;~%j0x8JDd)uBM|%x{5!0{ delta 409 zcmXw#%}T>S5XWZ{)7UnR{Yp&wAytb+5v5=cEm9Q=Er<$HREnM&5CvN`siz7;dl9^p z0et{Z-h_faga`2jd;|{)f(OA})ZLxm?*3<(|FREr&(kUKBNQ0EeB7$T-xy%~A`ABu zdZ{an_wH6R2+r?{LRW;E2~G^U0JQ|yH!Q86!#4#T%BcF_3bX;rd&^W(^E$$z1Z@#I z2zX+`cAJ+=bgj+^mXDs)F?v@|wJ5hn1$`JoKMOu1)RSY`O_uP0yLia^vObOgo&X&I z&zXWysnY#WE-0|RK32Tuj?-==LuNQ3STYsEld>f;-A>a>q)h#=rk}B^t15bR3>JnI28Lh_ z7NBCkOd!Ef0wU5u1PExb0*MkPAd#6;0#cNhn44Mx5-cdnOop)B5_5`EOV~kbii

Konsumatverwaltung

- {% for product in products %} -

{{ product.id }}, {{product.name}}, {{product.price}} €

- {% endfor %} - Getränk Hinzufügen -{% endblock %} + + + + + + + + + {% for product in products %} + + + + + + + + {% endfor %} +
IDNamePreisWird angezeigt
{{product.id}}{{product.name}}{{product.price}}{% if product.isshown %} ☑ {% else %} ☐ {% endif %} bearbeiten
+
+ Getränk Hinzufügen +{% endblock %} \ No newline at end of file diff --git a/app/templates/manage_beverages_add.html b/app/templates/manage_beverages_add.html new file mode 100644 index 0000000..591e844 --- /dev/null +++ b/app/templates/manage_beverages_add.html @@ -0,0 +1,18 @@ +{% extends "base.html"%} +{% set title = "Produkt hinzufügen" %} +{% block content %} +

Produkt hinzufügen

+ {% if error %} +

Fehler: {{ error }}

+ {% endif %} + {% if success %} +

{{ success }}

+ {% endif %} +

TODO: many

+
+ Produktname:
+ Preis:
+ Angezeigt:
+ +
+{% 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 %} +

{{product_to_edit.name}} bearbeiten

+ {% if error %} +

Fehler: {{ error }}

+ {% else %} + {% if success %} +

{{ success }}

+ {% endif %} +
+ Userid:
+ Username:
+ Preis:
+ Angezeigt:
+ +
+ {% 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 %} -

Produkt hinzufügen

- {% if error %} -

Fehler: {{ error }}

- {% endif %} - {% if success %} -

{{ success }}

- {% endif %} -

TODO: many

-
- Produktname:
- Preis:
-
-{% endblock %} \ No newline at end of file diff --git a/app/views.py b/app/views.py index 396890d..49d0da1 100644 --- a/app/views.py +++ b/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/', 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(): diff --git a/app/views.pyc b/app/views.pyc index fd299c32d48373149e36ec3895316cce8b60d139..c5d2ccc5b39ed3272da18457398153c4626eac41 100644 GIT binary patch delta 1441 zcmah|O-~b16us~DbK2>53lv&g)S4O+>Icz8G=iF_kdQh}ByrOWeM2eGLOQQT4Wx;n zD>phje}M}&h9BV0g^4>i8uu49w4|9oMzR#Ou=pJX39!mQFj(Wz)jVNnX+YcWwFz0tVnYdwZluR)6ynaWP4r4P~IFoYJHC6`dS4EJSMTNhM`@+$V?y{ z*?c*Lti}n(2&j=Hu4%}+Q?kDFxZcs*hQ=s^%4lAKBteiMM?gI_nncb~=jHVcU24-r zUL>Fyv?&DK5I}EJ=+baIXda}>1a<*!gwm+nrgc6(wV1)^*wep2!7L(xH^%%-@Z$) zk`&v>|4BMtX0>t%PrRVfLU7rAMEj0xi)4{JvS?ih+hy7WswP==exqad+PW;Rv^r0E zO=G!dH07j5_iA5VIZn}EQ`sINXAO)(9?`B5Ov5T!Je)+toiV$|2k!lScT-} zt7#06n{f|$lZ*%+ynl3qkHz^A`hpywvJflr(*CpfbLPK=IoeGtk*u=!)>86I^bBV78n2k delta 184 zcmexvvPM&e`7RHOOl6G4TM# z?#bd3xAE0EajyW&i*H diff --git a/doc/database.txt b/doc/database.txt index 2a70ec0..b53b9e3 100644 --- a/doc/database.txt +++ b/doc/database.txt @@ -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. diff --git a/run.py b/run.py index 9162559..03a4b08 100755 --- a/run.py +++ b/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) diff --git a/test/database.db b/test/database.db index c4318304e4290d080440d521c36146a996ddbb46..f673745e16d8333204acacefc8881e7774cdc304 100644 GIT binary patch delta 266 zcmZorXi%6SEojNWz`z2;Fu*lY#~3K6`;42H$(VteVH*R}VTNrJ3*5LGHJI4NWn~$g zlqcIVwaVxycm@Z1_=o!`IQjegxH|eNxVXAGhWdmk7-&vTWV{42bi%~Op3R4u99j8T znYS@8UuAyF{DAo+^R~@`97~u31zA}cMA z$q1C@TU}&amV5DnktYBnhWnf}uY`pm@uQn3^WEDPm delta 159 zcmZorXi%6SEvU)Bz`z2;Fu*xc#~3K6`;40xD8$T|$iQ@%$#`Oc+hhZl)sqt$FL5>U zGO>%x$}%?QPCU@csJZztlOrn^GxH4w=5NeTm~U)W