- add autoblack
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Geschwärzt</th>
|
||||
<th>Auto-Schwärzen</th>
|
||||
<th>Schulden</th>
|
||||
<th>Bezahlt</th>
|
||||
<th></th>
|
||||
@@ -23,6 +24,7 @@
|
||||
<tr>
|
||||
<td>{{user.longname}}</td>
|
||||
<td>{% if user.isblack %} ☑ {% else %} ☐ {% endif %}</td>
|
||||
<td>{% if user.autoblack %} ☑ {% else %} ☐ {% endif %}</td>
|
||||
<td>{{debt[user.id-1]}} € </td>
|
||||
<td> <input type="number" name="{{user.name}}_payed" step="any" required value="0" /> € </td>
|
||||
<td>Einzelne Rechnung <a href="/billing/send_personal_bill/{{user.name}}">versenden</a></td>
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
<th>Geschwärzt</th>
|
||||
<th>Baron</th>
|
||||
<th>Angezeigt</th>
|
||||
<th>Auto-Schwärzen</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
{% for user in users %}
|
||||
@@ -25,6 +26,7 @@
|
||||
<td>{% if user.isblack %} ☑ {% else %} ☐ {% endif %} </td>
|
||||
<td>{% if user.isbaron %} ☑ {% else %} ☐ {% endif %} </td>
|
||||
<td>{% if user.isshown %} ☑ {% else %} ☐ {% endif %} </td>
|
||||
<td>{% if user.autoblack %} ☑ {% else %} ☐ {% endif %} </td>
|
||||
<td> <a href="/manage_users/edit/{{user.name}}">bearbeiten</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
Geschwärzt: <input type="checkbox" name="isblack" {% if user_to_edit.isblack %} checked {% endif %} /> <br>
|
||||
Baron: <input type="checkbox" name="isbaron" {% if user_to_edit.isbaron %} checked {% endif %} /> <br>
|
||||
Angezeigt: <input type="checkbox" name="isshown" {% if user_to_edit.isshown %} checked {% endif %} /><br>
|
||||
Auto-Schwärzen: <input type="checkbox" name="autoblack" {% if user_to_edit.autoblack %} checked {% endif %} /><br>
|
||||
<input type="submit" value="Übernehmen" />
|
||||
</form>
|
||||
{% endif %}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
BIN
test/database.db
BIN
test/database.db
Binary file not shown.
Reference in New Issue
Block a user