diff --git a/app/database.py b/app/database.py index 3925da2..03416ae 100644 --- a/app/database.py +++ b/app/database.py @@ -7,6 +7,7 @@ from consumption import Consumption from deposit import Deposit import random as rand import datetime +from settings import settings DATABASE = 'test/database.db' @@ -56,6 +57,7 @@ def get_user(u): u.isblack=row[6] u.isbaron=row[7] u.isshown=row[8] + u.autoblack=row[9] print u return u @@ -73,6 +75,7 @@ def get_user_by_name(name): u.isblack=row[6] u.isbaron=row[7] u.isshown=row[8] + u.autoblack=row[9] print u return u @@ -90,6 +93,7 @@ def get_users(): u.isblack=row[6] u.isbaron=row[7] u.isshown=row[8] + u.autoblack=row[9] users.append(u) return users @@ -101,7 +105,7 @@ def add_user(u): def update_user(u): #query_db("UPDATE users SET (NAME, LONGNAME, EMAIL, RFID_ID, ISBLACK, ISBARON, ISSHOWN) VALUES (?, ?, ?, ?, ?, ?, ?) WHERE ID=?", (u.name, u.longname, u.email, u.rfid_id, u.isblack, u.isbaron, u.isshown, u.id)) - query_db("UPDATE users SET NAME=?, LONGNAME=?, EMAIL=?, RFID_ID=?, ISBLACK=?, ISBARON=?, ISSHOWN=? WHERE ID=?", (u.name, u.longname, u.email, u.rfid_id, u.isblack, u.isbaron, u.isshown, u.id)) + query_db("UPDATE users SET NAME=?, LONGNAME=?, EMAIL=?, RFID_ID=?, ISBLACK=?, ISBARON=?, ISSHOWN=?, AUTOBLACK=? WHERE ID=?", (u.name, u.longname, u.email, u.rfid_id, u.isblack, u.isbaron, u.isshown, u.autoblack, u.id)) get_db().commit() @@ -181,6 +185,12 @@ def add_consume(username, productid): #INSERT INTO USERS (NAME, PASSWORD, LONGNAME, EMAIL, RFID_ID) VALUES (? ,? ,?, ?, ?)", (u.name, u.password, u.longname, u.email, u.rfid_id)) query_db("INSERT INTO CONSUMED (PRODNR, CONSUMER, PRICE, TIME) VALUES (?, ?, ?, ?)", (str(product.id), str(consumerid), product.price, datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))) get_db().commit() + + if settings.autoBlack: + if get_debt(name=username) > settings.blockLimit: + u = get_user_by_name(username) + u.isblack = True + update_user(u) print "consumed" return @@ -223,6 +233,11 @@ def add_deposit(username, amount): consumerid = int(consumerid[0]) query_db("INSERT INTO DEPOSITS (USERID, AMOUNT, TIME) VALUES (?, ?, ?)", (str(consumerid), amount, datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"))) get_db().commit() + if settings.autoUnblack: + if get_debt(name=username) < settings.blockLimit: + u = get_user_by_name(username) + u.isblack = False + update_user(u) print "deposit" return @@ -261,4 +276,4 @@ def add_test_consume(consumerid, productid, daysago): product = get_product_by_id(productid) query_db("INSERT INTO CONSUMED (PRODNR, CONSUMER, PRICE, TIME) VALUES (?, ?, ?, ?)", (str(product.id), str(consumerid), product.price, (datetime.datetime.now()-datetime.timedelta(days=daysago)).strftime("%Y-%m-%d %H:%M:%S"))) get_db().commit() - return \ No newline at end of file + return diff --git a/app/settings.py b/app/settings.py index 0f1b92a..2254cb2 100644 --- a/app/settings.py +++ b/app/settings.py @@ -32,8 +32,8 @@ class Settings: ##Payment Incentives #Money Limit - self.autoBlock = False #Automatically block user if money owed > limit - self.autoUnblock = False #Automatically unblock user if money owed < limit + self.autoBlack = True #Automatically block user if money owed > limit + self.autoUnblack = True #Automatically unblock user if money owed < limit self.blockLimit = 150 #Money limit for automatic blocking (default 150) #Mail Spam self.autoAnnoy = False #Automatically send payment eMails diff --git a/app/templates/billing.html b/app/templates/billing.html index aee2cb3..b23ad0d 100644 --- a/app/templates/billing.html +++ b/app/templates/billing.html @@ -15,6 +15,7 @@ Name Geschwärzt + Auto-Schwärzen Schulden Bezahlt @@ -23,6 +24,7 @@ {{user.longname}} {% if user.isblack %} ☑ {% else %} ☐ {% endif %} + {% if user.autoblack %} ☑ {% else %} ☐ {% endif %} {{debt[user.id-1]}} € € Einzelne Rechnung versenden diff --git a/app/templates/manage_users.html b/app/templates/manage_users.html index ee16545..68ce2d5 100644 --- a/app/templates/manage_users.html +++ b/app/templates/manage_users.html @@ -13,6 +13,7 @@ Geschwärzt Baron Angezeigt + Auto-Schwärzen {% for user in users %} @@ -25,6 +26,7 @@ {% if user.isblack %} ☑ {% else %} ☐ {% endif %} {% if user.isbaron %} ☑ {% else %} ☐ {% endif %} {% if user.isshown %} ☑ {% else %} ☐ {% endif %} + {% if user.autoblack %} ☑ {% else %} ☐ {% endif %} bearbeiten {% endfor %} diff --git a/app/templates/manage_users_edit.html b/app/templates/manage_users_edit.html index 8200be1..0868f60 100644 --- a/app/templates/manage_users_edit.html +++ b/app/templates/manage_users_edit.html @@ -17,6 +17,7 @@ Geschwärzt:
Baron:
Angezeigt:
+ Auto-Schwärzen:
{% endif %} diff --git a/app/user.py b/app/user.py index f6ba854..b3080a3 100644 --- a/app/user.py +++ b/app/user.py @@ -10,6 +10,7 @@ class User: self.isblack=False self.isbaron=False self.isshown=False + self.autoblack=False def __str__(self): @@ -68,4 +69,12 @@ class User: else: s = "%s, True" % s + if self.autoblack is None: + s = "%s, None" % s + else: + if self.isshown is 0 or self. isshown is False: + s = "%s, False" % s + else: + s = "%s, True" % s + return s diff --git a/app/views.py b/app/views.py index b862ac0..c69e379 100644 --- a/app/views.py +++ b/app/views.py @@ -135,6 +135,12 @@ def manage_users_edit(name=None): else: u.isshown = False + if 'autoblack' in request.form: + u.autoblack = True + else: + u.autoblack = False + + update_user(u) return redirect('/manage_users') @@ -273,6 +279,7 @@ def billing(): add_deposit(user.name, payment) print "%s payed %d" % (user.name, payment) debt = [0 for user in users] + users = get_users() # refresh users for correct viewing of autounblacking for user in users: debt[user.id-1] = get_debt(user.name) diff --git a/doc/database.sql b/doc/database.sql index b4f09d2..0111873 100644 --- a/doc/database.sql +++ b/doc/database.sql @@ -39,7 +39,8 @@ CREATE TABLE Users( rfid_id TEXT, isblack BOOLEAN DEFAULT 0, isbaron BOOLEAN DEFAULT 0, - isshown BOOLEAN DEFAULT 1 + isshown BOOLEAN DEFAULT 1, + autoblack BOOLEAN DEFAULT 1 ); -- The table PRODUCTS contains information about the beverages available diff --git a/test/database.db b/test/database.db index cfbeef2..b0b2db7 100644 Binary files a/test/database.db and b/test/database.db differ