- add autoblack
This commit is contained in:
@@ -7,6 +7,7 @@ from consumption import Consumption
|
|||||||
from deposit import Deposit
|
from deposit import Deposit
|
||||||
import random as rand
|
import random as rand
|
||||||
import datetime
|
import datetime
|
||||||
|
from settings import settings
|
||||||
|
|
||||||
DATABASE = 'test/database.db'
|
DATABASE = 'test/database.db'
|
||||||
|
|
||||||
@@ -56,6 +57,7 @@ def get_user(u):
|
|||||||
u.isblack=row[6]
|
u.isblack=row[6]
|
||||||
u.isbaron=row[7]
|
u.isbaron=row[7]
|
||||||
u.isshown=row[8]
|
u.isshown=row[8]
|
||||||
|
u.autoblack=row[9]
|
||||||
print u
|
print u
|
||||||
return u
|
return u
|
||||||
|
|
||||||
@@ -73,6 +75,7 @@ def get_user_by_name(name):
|
|||||||
u.isblack=row[6]
|
u.isblack=row[6]
|
||||||
u.isbaron=row[7]
|
u.isbaron=row[7]
|
||||||
u.isshown=row[8]
|
u.isshown=row[8]
|
||||||
|
u.autoblack=row[9]
|
||||||
print u
|
print u
|
||||||
return u
|
return u
|
||||||
|
|
||||||
@@ -90,6 +93,7 @@ def get_users():
|
|||||||
u.isblack=row[6]
|
u.isblack=row[6]
|
||||||
u.isbaron=row[7]
|
u.isbaron=row[7]
|
||||||
u.isshown=row[8]
|
u.isshown=row[8]
|
||||||
|
u.autoblack=row[9]
|
||||||
users.append(u)
|
users.append(u)
|
||||||
return users
|
return users
|
||||||
|
|
||||||
@@ -101,7 +105,7 @@ def add_user(u):
|
|||||||
|
|
||||||
def update_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) 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()
|
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))
|
#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")))
|
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()
|
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"
|
print "consumed"
|
||||||
|
|
||||||
return
|
return
|
||||||
@@ -223,6 +233,11 @@ def add_deposit(username, amount):
|
|||||||
consumerid = int(consumerid[0])
|
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")))
|
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()
|
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"
|
print "deposit"
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -32,8 +32,8 @@ class Settings:
|
|||||||
|
|
||||||
##Payment Incentives
|
##Payment Incentives
|
||||||
#Money Limit
|
#Money Limit
|
||||||
self.autoBlock = False #Automatically block user if money owed > limit
|
self.autoBlack = True #Automatically block user if money owed > limit
|
||||||
self.autoUnblock = False #Automatically unblock 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)
|
self.blockLimit = 150 #Money limit for automatic blocking (default 150)
|
||||||
#Mail Spam
|
#Mail Spam
|
||||||
self.autoAnnoy = False #Automatically send payment eMails
|
self.autoAnnoy = False #Automatically send payment eMails
|
||||||
|
|||||||
@@ -15,6 +15,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Geschwärzt</th>
|
<th>Geschwärzt</th>
|
||||||
|
<th>Auto-Schwärzen</th>
|
||||||
<th>Schulden</th>
|
<th>Schulden</th>
|
||||||
<th>Bezahlt</th>
|
<th>Bezahlt</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
@@ -23,6 +24,7 @@
|
|||||||
<tr>
|
<tr>
|
||||||
<td>{{user.longname}}</td>
|
<td>{{user.longname}}</td>
|
||||||
<td>{% if user.isblack %} ☑ {% else %} ☐ {% endif %}</td>
|
<td>{% if user.isblack %} ☑ {% else %} ☐ {% endif %}</td>
|
||||||
|
<td>{% if user.autoblack %} ☑ {% else %} ☐ {% endif %}</td>
|
||||||
<td>{{debt[user.id-1]}} € </td>
|
<td>{{debt[user.id-1]}} € </td>
|
||||||
<td> <input type="number" name="{{user.name}}_payed" step="any" required value="0" /> € </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>
|
<td>Einzelne Rechnung <a href="/billing/send_personal_bill/{{user.name}}">versenden</a></td>
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
<th>Geschwärzt</th>
|
<th>Geschwärzt</th>
|
||||||
<th>Baron</th>
|
<th>Baron</th>
|
||||||
<th>Angezeigt</th>
|
<th>Angezeigt</th>
|
||||||
|
<th>Auto-Schwärzen</th>
|
||||||
<th></th>
|
<th></th>
|
||||||
</tr>
|
</tr>
|
||||||
{% for user in users %}
|
{% for user in users %}
|
||||||
@@ -25,6 +26,7 @@
|
|||||||
<td>{% if user.isblack %} ☑ {% else %} ☐ {% endif %} </td>
|
<td>{% if user.isblack %} ☑ {% else %} ☐ {% endif %} </td>
|
||||||
<td>{% if user.isbaron %} ☑ {% else %} ☐ {% endif %} </td>
|
<td>{% if user.isbaron %} ☑ {% else %} ☐ {% endif %} </td>
|
||||||
<td>{% if user.isshown %} ☑ {% 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>
|
<td> <a href="/manage_users/edit/{{user.name}}">bearbeiten</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
Geschwärzt: <input type="checkbox" name="isblack" {% if user_to_edit.isblack %} checked {% endif %} /> <br>
|
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>
|
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>
|
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" />
|
<input type="submit" value="Übernehmen" />
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ class User:
|
|||||||
self.isblack=False
|
self.isblack=False
|
||||||
self.isbaron=False
|
self.isbaron=False
|
||||||
self.isshown=False
|
self.isshown=False
|
||||||
|
self.autoblack=False
|
||||||
|
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@@ -68,4 +69,12 @@ class User:
|
|||||||
else:
|
else:
|
||||||
s = "%s, True" % s
|
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
|
return s
|
||||||
|
|||||||
@@ -135,6 +135,12 @@ def manage_users_edit(name=None):
|
|||||||
else:
|
else:
|
||||||
u.isshown = False
|
u.isshown = False
|
||||||
|
|
||||||
|
if 'autoblack' in request.form:
|
||||||
|
u.autoblack = True
|
||||||
|
else:
|
||||||
|
u.autoblack = False
|
||||||
|
|
||||||
|
|
||||||
update_user(u)
|
update_user(u)
|
||||||
|
|
||||||
return redirect('/manage_users')
|
return redirect('/manage_users')
|
||||||
@@ -273,6 +279,7 @@ def billing():
|
|||||||
add_deposit(user.name, payment)
|
add_deposit(user.name, payment)
|
||||||
print "%s payed %d" % (user.name, payment)
|
print "%s payed %d" % (user.name, payment)
|
||||||
debt = [0 for user in users]
|
debt = [0 for user in users]
|
||||||
|
users = get_users() # refresh users for correct viewing of autounblacking
|
||||||
for user in users:
|
for user in users:
|
||||||
debt[user.id-1] = get_debt(user.name)
|
debt[user.id-1] = get_debt(user.name)
|
||||||
|
|
||||||
|
|||||||
@@ -39,7 +39,8 @@ CREATE TABLE Users(
|
|||||||
rfid_id TEXT,
|
rfid_id TEXT,
|
||||||
isblack BOOLEAN DEFAULT 0,
|
isblack BOOLEAN DEFAULT 0,
|
||||||
isbaron 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
|
-- 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