Merge branch 'master' of https://github.com/ulrichknecht/baroness
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
|
||||||
|
|
||||||
@@ -108,6 +111,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
|
||||||
|
|
||||||
@@ -119,7 +123,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()
|
||||||
|
|
||||||
|
|
||||||
@@ -199,6 +203,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
|
||||||
@@ -213,6 +223,8 @@ def get_debt(name=None):
|
|||||||
deposits = get_deposits(get_user_by_name(name).id)
|
deposits = get_deposits(get_user_by_name(name).id)
|
||||||
for deposit in deposits:
|
for deposit in deposits:
|
||||||
debt -= deposit.amount
|
debt -= deposit.amount
|
||||||
|
|
||||||
|
debt = round(debt, 2)
|
||||||
return debt
|
return debt
|
||||||
|
|
||||||
|
|
||||||
@@ -234,6 +246,21 @@ def get_deposits(userid = None):
|
|||||||
deposits.append(d)
|
deposits.append(d)
|
||||||
return deposits
|
return deposits
|
||||||
|
|
||||||
|
def add_deposit(username, amount):
|
||||||
|
consumerid = query_db("SELECT ID FROM USERS WHERE NAME = ?", [username], one=True)
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
##for testing only
|
##for testing only
|
||||||
def generate_test_users():
|
def generate_test_users():
|
||||||
|
|
||||||
@@ -267,4 +294,4 @@ def add_test_consume(consumerid, productid, daysago):
|
|||||||
product = get_product_by_id(productid)
|
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")))
|
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()
|
get_db().commit()
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -274,7 +274,7 @@ class PanelUsers (wx.Panel):
|
|||||||
|
|
||||||
self.but.SetBackgroundColour((255-(i*20 % 40), (160+(i*50 % 100)), 0))
|
self.but.SetBackgroundColour((255-(i*20 % 40), (160+(i*50 % 100)), 0))
|
||||||
#self.but.SetForegroundColour("#006699")
|
#self.but.SetForegroundColour("#006699")
|
||||||
self.but.SetPressColor(wx.Color(255,255,255,0))
|
self.but.SetPressColor(wx.Colour(255,255,255,0))
|
||||||
self.but.SetFont(wx.Font(25, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Humor Sans"))
|
self.but.SetFont(wx.Font(25, wx.DEFAULT, wx.NORMAL, wx.NORMAL, 0, "Humor Sans"))
|
||||||
self.but.Bind(wx.EVT_LEFT_DOWN, parent.onUser, id=self.but.Id)
|
self.but.Bind(wx.EVT_LEFT_DOWN, parent.onUser, id=self.but.Id)
|
||||||
self.but_names.append(self.but)
|
self.but_names.append(self.but)
|
||||||
|
|||||||
59
app/send_email.py
Normal file
59
app/send_email.py
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
import smtplib
|
||||||
|
import database
|
||||||
|
# import email
|
||||||
|
# from email.mime.text import MIMEText
|
||||||
|
# from email.MIMEText import MIMEText
|
||||||
|
import user
|
||||||
|
|
||||||
|
def send_email(recipient, subject, body):
|
||||||
|
gmail_user = 'bier1baroness'
|
||||||
|
gmail_pwd = 'test11test11'
|
||||||
|
FROM = 'bier1baroness@gmail.com'
|
||||||
|
SUBJECT = subject
|
||||||
|
TEXT = body
|
||||||
|
|
||||||
|
# Prepare actual message
|
||||||
|
message = u"Content-Type: text/plain; charset=utf-8\nFrom: Baroness <%s>\nTo: %s\nSubject: %s\n\n%s" % (FROM, recipient, SUBJECT, TEXT)
|
||||||
|
message = message.encode('utf-8')
|
||||||
|
|
||||||
|
# message = msg.as_string()
|
||||||
|
print message
|
||||||
|
try:
|
||||||
|
server = smtplib.SMTP("smtp.gmail.com:587")
|
||||||
|
#server.set_debuglevel(1)
|
||||||
|
server.starttls()
|
||||||
|
server.login(gmail_user, gmail_pwd)
|
||||||
|
server.sendmail(FROM, recipient, message)
|
||||||
|
server.quit()
|
||||||
|
print 'Mail was sent to %s' % recipient
|
||||||
|
|
||||||
|
except:
|
||||||
|
print "Failed to send mail to %s" %recipient
|
||||||
|
|
||||||
|
def send_emails(body, subject, users):
|
||||||
|
FROM = 'bier1baroness@gmail.com'
|
||||||
|
|
||||||
|
for user in users:
|
||||||
|
debt = get_debt(user.name)
|
||||||
|
subject_parsed = parse_email(subject, user, debt)
|
||||||
|
body_parsed = parse_email(body, user, debt)
|
||||||
|
send_email(user.email, subject_parsed, body_parsed)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def parse_email(text, u, dept):
|
||||||
|
|
||||||
|
text = text.replace('%%longname%%', u.longname)
|
||||||
|
text = text.replace('%%dept%%', str(dept))
|
||||||
|
|
||||||
|
if text.find('%%if_is_black%%', 0, text.__len__()):
|
||||||
|
start = text.find('%%if_is_black%%', 0, text.__len__())
|
||||||
|
end = text.find('%%end_if_is_black%%')
|
||||||
|
|
||||||
|
if not u.isblack:
|
||||||
|
text = text.replace(text[start:end], '')
|
||||||
|
text = text.replace('%%if_is_black%%', '')
|
||||||
|
text = text.replace('%%end_if_is_black%%', '')
|
||||||
|
|
||||||
|
return text
|
||||||
@@ -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
|
||||||
|
|||||||
@@ -5,11 +5,13 @@
|
|||||||
<p>{{ success }}</p>
|
<p>{{ success }}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<h1>Abrechnung</h1>
|
<h1>Abrechnung</h1>
|
||||||
|
<p>An alle User Rechnungen <a href="/billing/send_all_bills"> versenden</a>.</p>
|
||||||
<form name="billing" method="post" action="/billing">
|
<form name="billing" method="post" action="/billing">
|
||||||
<table>
|
<table>
|
||||||
<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>
|
||||||
@@ -18,6 +20,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>
|
||||||
@@ -26,5 +29,4 @@
|
|||||||
</table>
|
</table>
|
||||||
<input type="submit" value="Änderungen übernehmen">
|
<input type="submit" value="Änderungen übernehmen">
|
||||||
</form>
|
</form>
|
||||||
<p>An alle User Rechnungen <a href="/billing/send_all_bills"> versenden</a>.</p>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -1,23 +1,34 @@
|
|||||||
{% extends "base.html"%}
|
{% extends "base.html"%}
|
||||||
{% set title = "An alle User Rechnung versenden" %}
|
{% set title = "An alle User Rechnungen versenden" %}
|
||||||
{% block content %}
|
{% block content %}
|
||||||
<h3>TODO: </h3>
|
<h3>TODO: </h3>
|
||||||
<ul>
|
<ul>
|
||||||
<li>actual send emails</li>
|
<li>actual send emails</li>
|
||||||
<li>save default text somewhere and make it configureable</li>
|
<li>save default text somewhere and make it configureable</li>
|
||||||
<li>parse wildcards</li>
|
<li>insert the right ammount of dept</li>
|
||||||
</ul>
|
</ul>
|
||||||
{% if success %}
|
{% if success %}
|
||||||
<p>{{ success }}</p>
|
<p>{{ success }}</p>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<h1>Rechnung an alle verschicken</h1>
|
<h1>Rechnung an alle verschicken</h1>
|
||||||
<form name="billing" method="post" action="/billing/send_all_bills">
|
<form name="billing" method="post" action="/billing/send_all_bills">
|
||||||
<textarea cols="80" rows="20">
|
Betreff:<input type="text" name="subject" value="Bierrechnung von der Baroness"/> <br />
|
||||||
|
<textarea cols="80" rows="20" name="message">
|
||||||
Hallo %%longname%%
|
Hallo %%longname%%
|
||||||
du hast zurzeit viele Schulden.
|
du hast %%dept%%€ Schulden.
|
||||||
%%if_is_black%%Weil du zu hohe Schulden hast, bist du geschwärzt%%endif%%
|
Bitte überweise diesen Betrag an das Konto:
|
||||||
</textarea>
|
|
||||||
|
|
||||||
|
%%if_is_black%%Weil du zu hohe Schulden hast, bist du geschwärzt%%end_if_is_black%%
|
||||||
|
</textarea><br />
|
||||||
|
<p> Warnung: Das versenden vieler emails dauert ein weilchen.</p>
|
||||||
<input type="submit" value="Email versenden">
|
<input type="submit" value="Email versenden">
|
||||||
</form>
|
</form>
|
||||||
|
|
||||||
|
<h1>Kommandos</h1>
|
||||||
|
<p>Der text den du eingibst wird von der Baroness noch personalisiert. Folgende Komandos kennt die Baroness.</p>
|
||||||
|
<ul>
|
||||||
|
<li> <b>%%longname%%</b> fügt den vollen namen des Benutzers ein.</li>
|
||||||
|
<li> <b>%%dept%%</b> fügt die Höhe der Schulden des Benutzers ein. </li>
|
||||||
|
<li> <b>%%if_is_black%% TEXT %%end_if_is_black%%</b> fügt den TEXT ein, falls der user geschwärzt ist.</li>
|
||||||
|
</ul>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -11,13 +11,20 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
<h1>Rechnung an {{user_to_bill.longname}} verschicken</h1>
|
<h1>Rechnung an {{user_to_bill.longname}} verschicken</h1>
|
||||||
<form name="billing" method="post" action="/billing/send_personal_bill/{{user_to_bill.name}}">
|
<form name="billing" method="post" action="/billing/send_personal_bill/{{user_to_bill.name}}">
|
||||||
<textarea cols="80" rows="20">
|
Betreff:<input type="text" name="subject" value="Bierrechnung von der Baroness"/> <br />
|
||||||
|
<textarea cols="80" rows="20" name="message">
|
||||||
Hallo {{user_to_bill.longname}}
|
Hallo {{user_to_bill.longname}}
|
||||||
du hast zurzeit viele Schulden.
|
du hast zurzeit {{dept}} € Schulden.
|
||||||
{% if user_to_bill.isblack %}Weil du zu hohe Schulden hast, bist du geschwärzt{% endif %}
|
{% if user_to_bill.isblack %}Weil du zu hohe Schulden hast, bist du geschwärzt.{% endif %}
|
||||||
</textarea>
|
Bitte überweise den Betrag an das Konto:
|
||||||
|
Peter Schleter;
|
||||||
|
IBAN; BIC;
|
||||||
|
|
||||||
|
dein Baron,
|
||||||
|
{{user.longname}}
|
||||||
|
</textarea><br />
|
||||||
<input type="submit" value="Email versenden">
|
<input type="submit" value="Email versenden">
|
||||||
</form>
|
</form>
|
||||||
<p>An alle User Rechnungen <a href="/billing/send_all_bills"> versenden</a>.</p>
|
<p>An alle User Rechnungen <a href="/billing/send_all_bills"> versenden</a>.</p>
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -12,6 +12,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 %}
|
||||||
@@ -24,6 +25,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
|
||||||
|
|||||||
54
app/views.py
54
app/views.py
@@ -5,6 +5,7 @@ from database import *
|
|||||||
from plot import *
|
from plot import *
|
||||||
from user import User
|
from user import User
|
||||||
from product import Product
|
from product import Product
|
||||||
|
from send_email import send_email, send_emails
|
||||||
from consumption import Consumption
|
from consumption import Consumption
|
||||||
import bcrypt
|
import bcrypt
|
||||||
import os
|
import os
|
||||||
@@ -134,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')
|
||||||
@@ -261,8 +268,22 @@ def personal():
|
|||||||
@requires_baron
|
@requires_baron
|
||||||
def billing():
|
def billing():
|
||||||
users = get_users()
|
users = get_users()
|
||||||
|
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
return render_template('billing.html', users=users, success="Not Implemented", dept=0, user=get_user_by_name(session.get('name')))
|
for user in users:
|
||||||
|
formname = "%s_payed" % user.name
|
||||||
|
if formname in request.form:
|
||||||
|
# add payment here
|
||||||
|
payment = float(request.form[formname])
|
||||||
|
if payment != 0:
|
||||||
|
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)
|
||||||
|
|
||||||
|
return render_template('billing.html', users=users, success="Writing to database is not implemented", debt=debt, user=get_user_by_name(session.get('name')))
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
debt = [0 for user in users]
|
debt = [0 for user in users]
|
||||||
for user in users:
|
for user in users:
|
||||||
@@ -270,22 +291,41 @@ def billing():
|
|||||||
return render_template('billing.html', users=users, debt=debt, user=get_user_by_name(session.get('name')))
|
return render_template('billing.html', users=users, debt=debt, user=get_user_by_name(session.get('name')))
|
||||||
|
|
||||||
|
|
||||||
@app.route('/billing/send_personal_bill/<name>', methods=['GET','POST'])
|
@app.route('/billing/send_personal_bill/<name>', methods=['GET', 'POST'])
|
||||||
@requires_baron
|
@requires_baron
|
||||||
def send_personal_bill(name=None):
|
def send_personal_bill(name=None):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
return "To be implemented"
|
users = get_users()
|
||||||
#return redirect('/billing')
|
u = get_user_by_name(name)
|
||||||
|
message = request.form['message']
|
||||||
|
subject = request.form['subject']
|
||||||
|
send_email(u.email, subject, message)
|
||||||
|
|
||||||
|
success = "Die Rechnung wurde an %s versendet." %u.longname
|
||||||
|
return render_template('billing.html', users=users, success=success, dept=0, user=get_user_by_name(session.get('name')))
|
||||||
|
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
return render_template('billing_personal.html', user_to_bill=get_user_by_name(name) ,user=get_user_by_name(session.get('name')))
|
return render_template('billing_personal.html', user_to_bill=get_user_by_name(name), dept=get_debt(name), user=get_user_by_name(session.get('name')))
|
||||||
|
|
||||||
|
|
||||||
@app.route('/billing/send_all_bills', methods=['GET','POST'])
|
@app.route('/billing/send_all_bills', methods=['GET', 'POST'])
|
||||||
@requires_baron
|
@requires_baron
|
||||||
def send_mass_mail(name=None):
|
def send_mass_mail(name=None):
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
return "To be implemented"
|
users = get_users()
|
||||||
|
u = get_user_by_name(name)
|
||||||
|
message = request.form['message']
|
||||||
|
subject = request.form['subject']
|
||||||
|
|
||||||
|
send_emails(message, subject, users)
|
||||||
|
#for user in users:
|
||||||
|
# message_parsed = parse_email(message, user, 3) # change ammount of depts here
|
||||||
|
# subject_parsed = parse_email(subject, user, 3) # change ammount of depts here!
|
||||||
|
# send_email(user.email, subject_parsed, message_parsed)
|
||||||
|
|
||||||
|
success = "An alle user werden Rechnungen versendet."
|
||||||
|
return render_template('billing.html', users=users, success=success, dept=0, user=get_user_by_name(session.get('name')))
|
||||||
|
|
||||||
if request.method == 'GET':
|
if request.method == 'GET':
|
||||||
return render_template('billing_mass_mail.html', user=get_user_by_name(session.get('name')))
|
return render_template('billing_mass_mail.html', user=get_user_by_name(session.get('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