inital commit
This commit is contained in:
4
app/__init__.py
Normal file
4
app/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
from flask import Flask
|
||||
|
||||
app = Flask(__name__)
|
||||
from app import views
|
||||
BIN
app/__init__.pyc
Normal file
BIN
app/__init__.pyc
Normal file
Binary file not shown.
40
app/check_rights.py
Normal file
40
app/check_rights.py
Normal file
@@ -0,0 +1,40 @@
|
||||
# https://github.com/JesseAldridge/flask_simple_login/blob/master/simple_login.py
|
||||
from flask import session, render_template
|
||||
from user import User
|
||||
from database import *
|
||||
from functools import wraps
|
||||
|
||||
|
||||
def requires_baron(fn):
|
||||
@wraps(fn)
|
||||
def decorated_function(*a,**kw):
|
||||
u = User()
|
||||
u.name = session.get('name', None)
|
||||
u = get_user(u)
|
||||
if not u or not u.isbaron:
|
||||
return render_template("not_baron.html", user=get_user_by_name(session.get('name'))), 401
|
||||
return fn(*a, **kw)
|
||||
return decorated_function
|
||||
|
||||
|
||||
def requires_login(fn):
|
||||
@wraps(fn)
|
||||
def decorated_function(*a, **kw):
|
||||
if not session.get('name', None):
|
||||
return render_template("not_logged_in.html", user=get_user_by_name(session.get('name'))), 401
|
||||
return fn(*a, **kw)
|
||||
return decorated_function
|
||||
|
||||
|
||||
#def require_login(redirect=False):
|
||||
# def decorator(fn):
|
||||
# @functools.wraps(fn)
|
||||
# def decorated_function(*a, **kw):
|
||||
# username = session.get('username', None)
|
||||
# if not username or username not in g.user_db['user_info']:
|
||||
# if redirect:
|
||||
# return flask.redirect('/login')
|
||||
# return 'not logged in', 401
|
||||
# return fn(*a, **kw)
|
||||
# return decorated_function
|
||||
# return decorator
|
||||
BIN
app/check_rights.pyc
Normal file
BIN
app/check_rights.pyc
Normal file
Binary file not shown.
12
app/consumption.py
Normal file
12
app/consumption.py
Normal file
@@ -0,0 +1,12 @@
|
||||
import datetime as dt
|
||||
|
||||
class Consumption:
|
||||
|
||||
def __init__(self):
|
||||
#ID|PRODNR|CONSUMER|PRICE|TIME
|
||||
self.id = 0
|
||||
self.prodnr = 0
|
||||
self.consumer = 0
|
||||
self.price = 0
|
||||
self.time = dt.datetime
|
||||
|
||||
BIN
app/consumption.pyc
Normal file
BIN
app/consumption.pyc
Normal file
Binary file not shown.
157
app/database.py
Normal file
157
app/database.py
Normal file
@@ -0,0 +1,157 @@
|
||||
import sqlite3
|
||||
from flask import g
|
||||
from app import app
|
||||
from user import User
|
||||
from product import Product
|
||||
from consumption import Consumption
|
||||
import datetime
|
||||
|
||||
DATABASE = 'test/database.db'
|
||||
|
||||
def get_db():
|
||||
db = getattr(g, '_database',None)
|
||||
if db is None:
|
||||
db = g._database = sqlite3.connect(DATABASE)
|
||||
return db
|
||||
|
||||
@app.teardown_appcontext
|
||||
def close_connection(exception):
|
||||
db = getattr(g,'_database', None)
|
||||
if db is not None:
|
||||
db.close()
|
||||
|
||||
def query_db(query, args=(), one=False):
|
||||
closeflag = False
|
||||
try:
|
||||
db = get_db()
|
||||
except RuntimeError:
|
||||
print "GUI DB acces"
|
||||
db = sqlite3.connect(DATABASE)
|
||||
closeflag = True
|
||||
|
||||
print query
|
||||
print args
|
||||
#print "Sqlite: " + query % args
|
||||
cur = db.execute(query, args)
|
||||
rows = cur.fetchall()
|
||||
cur.close()
|
||||
if closeflag is True:
|
||||
db.close()
|
||||
|
||||
return (rows[0] if rows else None) if one else rows
|
||||
|
||||
def get_user(u):
|
||||
row = query_db("SELECT * FROM USERS WHERE NAME = ?", [u.name], one=True)
|
||||
u = User()
|
||||
if row is None:
|
||||
return None
|
||||
u.id=row[0]
|
||||
u.name=row[1]
|
||||
u.password=row[2]
|
||||
u.longname=row[3]
|
||||
u.email=row[4]
|
||||
u.rfid_id=row[5]
|
||||
u.isblack=row[6]
|
||||
u.isbaron=row[7]
|
||||
u.isshown=row[8]
|
||||
print u
|
||||
return u
|
||||
|
||||
def get_user_by_name(name):
|
||||
row = query_db("SELECT * FROM USERS WHERE NAME = ?", [name], one=True)
|
||||
u = User()
|
||||
if row is None:
|
||||
return None
|
||||
u.id=row[0]
|
||||
u.name=row[1]
|
||||
u.password=row[2]
|
||||
u.longname=row[3]
|
||||
u.email=row[4]
|
||||
u.rfid_id=row[5]
|
||||
u.isblack=row[6]
|
||||
u.isbaron=row[7]
|
||||
u.isshown=row[8]
|
||||
print u
|
||||
return u
|
||||
|
||||
def get_users():
|
||||
rows = query_db("SELECT * FROM USERS")
|
||||
users = []
|
||||
for row in rows:
|
||||
u = User()
|
||||
u.id=row[0]
|
||||
u.name=row[1]
|
||||
u.password=row[2]
|
||||
u.longname=row[3]
|
||||
u.email=row[4]
|
||||
u.rfid_id=row[5]
|
||||
u.isblack=row[6]
|
||||
u.isbaron=row[7]
|
||||
u.isshown=row[8]
|
||||
users.append(u)
|
||||
return users
|
||||
|
||||
|
||||
def add_user(u):
|
||||
query_db("INSERT INTO USERS (NAME, PASSWORD, LONGNAME, EMAIL, RFID_ID) VALUES (? ,? ,?, ?, ?)", (u.name, u.password, u.longname, u.email, u.rfid_id))
|
||||
get_db().commit()
|
||||
|
||||
|
||||
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))
|
||||
get_db().commit()
|
||||
|
||||
|
||||
def get_products():
|
||||
rows = query_db("SELECT * FROM PRODUCTS")
|
||||
products = []
|
||||
for row in rows:
|
||||
p = Product()
|
||||
p.id = row[0]
|
||||
p.name = row[1]
|
||||
p.price = row[2]
|
||||
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
|
||||
p = Product()
|
||||
p.id = row[0]
|
||||
p.name = row[1]
|
||||
p.price = row[2]
|
||||
return p
|
||||
|
||||
|
||||
def get_consumed(user=None, startdate=None, enddate=None):
|
||||
|
||||
if user is None and startdate is None and enddate is None:
|
||||
rows = query_db('SELECT * FROM CONSUMED')
|
||||
|
||||
consumed = []
|
||||
for row in rows:
|
||||
#ID|PRODNR|CONSUMER|PRICE|TIME
|
||||
c = Consumption()
|
||||
c.id = int(row[0])
|
||||
c.prodnr = int(row[1])
|
||||
c.consumer = int(row[2])
|
||||
#2016-01-27 12:59:04
|
||||
c.price = float(row[3])
|
||||
c.time = datetime.datetime.strptime(row[4], "%Y-%m-%d %H:%M:%S")
|
||||
consumed.append(c)
|
||||
|
||||
return consumed
|
||||
|
||||
def add_consume(username, productid):
|
||||
|
||||
consumerid = query_db("SELECT ID FROM USERS WHERE NAME = ?", [username], one=True)
|
||||
print "consumerid = "
|
||||
print consumerid
|
||||
consumerid = int(consumerid[0])
|
||||
product = get_product_by_id(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()
|
||||
print "consumed"
|
||||
BIN
app/database.pyc
Normal file
BIN
app/database.pyc
Normal file
Binary file not shown.
33
app/gui.py
Normal file
33
app/gui.py
Normal file
@@ -0,0 +1,33 @@
|
||||
import wx
|
||||
from database import *
|
||||
|
||||
class MainWindow(wx.Frame):
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super(MainWindow, self).__init__(*args, **kwargs)
|
||||
|
||||
self.init_ui()
|
||||
|
||||
def init_ui(self):
|
||||
self.SetSize((480, 320))
|
||||
self.SetTitle('Baroness Control')
|
||||
panel = wx.Panel(self, -1)
|
||||
|
||||
products = get_products()
|
||||
buttonids = []
|
||||
i = 0
|
||||
for product in products:
|
||||
but = wx.Button(panel, label=product.name, pos=(50+i*150, 50), size=(100, 100))
|
||||
print "Button %s created" % product.name
|
||||
self.Bind(wx.EVT_BUTTON, self.on_button_press, id=but.Id)
|
||||
i = i+1
|
||||
|
||||
self.Bind(wx.EVT_CLOSE, self.on_quit)
|
||||
self.Show(True)
|
||||
|
||||
def on_button_press(self,e, id=-1):
|
||||
print e
|
||||
|
||||
def on_quit(self, e):
|
||||
print "close"
|
||||
self.Destroy()
|
||||
BIN
app/gui.pyc
Normal file
BIN
app/gui.pyc
Normal file
Binary file not shown.
6
app/product.py
Normal file
6
app/product.py
Normal file
@@ -0,0 +1,6 @@
|
||||
class Product:
|
||||
|
||||
def __init__(self):
|
||||
self.id = 0
|
||||
self.name = ""
|
||||
self.price = 0.0
|
||||
BIN
app/product.pyc
Normal file
BIN
app/product.pyc
Normal file
Binary file not shown.
1
app/static/style.css
Normal file
1
app/static/style.css
Normal file
@@ -0,0 +1 @@
|
||||
static css style sheet
|
||||
39
app/templates/base.html
Normal file
39
app/templates/base.html
Normal file
@@ -0,0 +1,39 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
{% if title %}
|
||||
<title> {{ title }} - Baroness </title>
|
||||
{% else %}
|
||||
<title> Des Bierbarons Helferin - Baroness </title>
|
||||
{% endif %}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<!-- Menu -->
|
||||
<ul>
|
||||
<li><a href="/index">Home</a></li>
|
||||
{% if user %}
|
||||
<li><a href="/logout">Logout</a></li>
|
||||
<li><a href="/consume"> Konsumieren</a></li>
|
||||
<li><a href="/personal">Personal</a></li>
|
||||
{% if user.isbaron %}
|
||||
<li><a href="/billing">Billing</a></li>
|
||||
<li><a href="/manage_beverages">Konsumatverwaltung</a></li>
|
||||
<li><a href="/manage_users">Konsumentenverwaltung</a></li>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<li><a href="/login">Login</a></li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
{% if user %}
|
||||
Du bist eingeloggt als {{user.longname}}.
|
||||
{% endif %}
|
||||
|
||||
{% block content %}{% endblock %}
|
||||
|
||||
</body>
|
||||
|
||||
</html>
|
||||
10
app/templates/billing.html
Normal file
10
app/templates/billing.html
Normal file
@@ -0,0 +1,10 @@
|
||||
{% extends "base.html"%}
|
||||
{% set title = "Konsumatverwaltung" %}
|
||||
{% block content %}
|
||||
<h3>TODO: </h3>
|
||||
<ul>
|
||||
<li>everything</li>
|
||||
</ul>
|
||||
<h1>Abrechnung</h1>
|
||||
|
||||
{% endblock %}
|
||||
18
app/templates/consume.html
Normal file
18
app/templates/consume.html
Normal file
@@ -0,0 +1,18 @@
|
||||
{% extends "base.html"%}
|
||||
{% set title = "Konsumieren" %}
|
||||
{% block content %}
|
||||
<h3>TODO: </h3>
|
||||
<ul>
|
||||
<li>add photos for products, add photos in database</li>
|
||||
</ul>
|
||||
<h1> Konsumieren </h1>
|
||||
{% if message %}
|
||||
<p> {{ message }} </p>
|
||||
{% endif %}
|
||||
<p>
|
||||
Möchtest du etwas konsumieren?
|
||||
{% for product in products %}
|
||||
<div><p> {{ product.id }}, <a href="/consume?prodid={{product.id}}"> {{product.name}} </a>, {{product.price}} € </p> </div>
|
||||
{% endfor %}
|
||||
</p>
|
||||
{% endblock %}
|
||||
27
app/templates/index.html
Normal file
27
app/templates/index.html
Normal file
@@ -0,0 +1,27 @@
|
||||
{% extends "base.html"%}
|
||||
{% set title = "Bierliste" %}
|
||||
{% block content %}
|
||||
<h3>TODO: </h3>
|
||||
<ul>
|
||||
<li> graphical beer list</li>
|
||||
</ul>
|
||||
<h1> Bierliste </h1>
|
||||
<table>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Produkt Nummer</th>
|
||||
<th>Konsument</th>
|
||||
<th>Preis</th>
|
||||
<th>Zeit</th>
|
||||
</tr>
|
||||
{% for consumption in consumed %}
|
||||
<tr>
|
||||
<td>{{consumption.id}}</td>
|
||||
<td>{{consumption.prodnr}}</td>
|
||||
<td>{{consumption.consumer}}</td>
|
||||
<td>{{consumption.price}}</td>
|
||||
<td>{{consumption.time}}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
{% endblock %}
|
||||
17
app/templates/login.html
Normal file
17
app/templates/login.html
Normal file
@@ -0,0 +1,17 @@
|
||||
{% extends "base.html"%}
|
||||
{% set title = "Login" %}
|
||||
{% block content %}
|
||||
<h3>TODO: </h3>
|
||||
<ul>
|
||||
<li>encrypt and salt passwords</li>
|
||||
</ul>
|
||||
<h1> Login </h1>
|
||||
{% if error %}
|
||||
<p>{{ error }}</p>
|
||||
{% endif %}
|
||||
<form name="login" method="post" action="/login">
|
||||
Username:<input type="text" name=username required placeholder="Username"><br>
|
||||
Passwort:<input type="password" name=password required placeholder="Password"><br>
|
||||
<input type="submit" value="Login">
|
||||
</form>
|
||||
{% endblock %}
|
||||
14
app/templates/manage_beverages.html
Normal file
14
app/templates/manage_beverages.html
Normal file
@@ -0,0 +1,14 @@
|
||||
{% extends "base.html"%}
|
||||
{% set title = "Konsumatverwaltung" %}
|
||||
{% block content %}
|
||||
<h3>TODO: </h3>
|
||||
<ul>
|
||||
<li>add "change products pages"</li>
|
||||
</ul>
|
||||
<h1> Konsumatverwaltung </h1>
|
||||
|
||||
{% for product in products %}
|
||||
<div><p> {{ product.id }}, {{product.name}}, {{product.price}} €</p></div>
|
||||
{% endfor %}
|
||||
<a href=/manage_beverages/add>Getränk Hinzufügen</a></li>
|
||||
{% endblock %}
|
||||
16
app/templates/manage_products_add.html
Normal file
16
app/templates/manage_products_add.html
Normal file
@@ -0,0 +1,16 @@
|
||||
{% extends "base.html"%}
|
||||
{% set title = "Produkt hinzufügen" %}
|
||||
{% block content %}
|
||||
<h1> Produkt hinzufügen</h1>
|
||||
{% if error %}
|
||||
<p>Fehler: {{ error }}</p>
|
||||
{% endif %}
|
||||
{% if success %}
|
||||
<p>{{ success }}</p>
|
||||
{% endif %}
|
||||
<p> TODO: many </p>
|
||||
<form name="user" method="post" action="/manage_users/add">
|
||||
Produktname:<input type="text" name=username required placeholder="Username"><br>
|
||||
Preis:<input type="password" name=password1 required placeholder="Password"><br>
|
||||
</form>
|
||||
{% endblock %}
|
||||
34
app/templates/manage_users.html
Normal file
34
app/templates/manage_users.html
Normal file
@@ -0,0 +1,34 @@
|
||||
{% extends "base.html"%}
|
||||
{% set title = "Konsumentenverwaltung" %}
|
||||
{% block content %}
|
||||
<h1> Konsumentenverwaltung </h1>
|
||||
<p> TODO: many</p>
|
||||
<table>
|
||||
<tr>
|
||||
<th>ID</th>
|
||||
<th>Username</th>
|
||||
<th>Name</th>
|
||||
<th>E-mail</th>
|
||||
<th>RFID-ID</th>
|
||||
<th>Geschwärzt</th>
|
||||
<th>Baron</th>
|
||||
<th>Angezeigt</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
{% for user in users %}
|
||||
<tr>
|
||||
<td>{{user.id}}</td>
|
||||
<td>{{user.name}}</td>
|
||||
<td>{{user.longname}}</td>
|
||||
<td>{{user.email}}</td>
|
||||
<td>{{user.rfid_id}}</td>
|
||||
<td>{% if user.isblack %} ☑ {% else %} ☐ {% endif %} </td>
|
||||
<td>{% if user.isbaron %} ☑ {% else %} ☐ {% endif %} </td>
|
||||
<td>{% if user.isshown %} ☑ {% else %} ☐ {% endif %} </td>
|
||||
<td> <a href="/manage_users/edit/{{user.name}}">bearbeiten</a></td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
<br />
|
||||
<a href=/manage_users/add>User Hinzufügen</a>
|
||||
{% endblock %}
|
||||
21
app/templates/manage_users_add.html
Normal file
21
app/templates/manage_users_add.html
Normal file
@@ -0,0 +1,21 @@
|
||||
{% extends "base.html"%}
|
||||
{% set title = "Konsumentin hinzufügen" %}
|
||||
{% block content %}
|
||||
<h1> Konsumentin hinzufügen</h1>
|
||||
{% if error %}
|
||||
<p>Fehler: {{ error }}</p>
|
||||
{% endif %}
|
||||
{% if success %}
|
||||
<p>{{ success }}</p>
|
||||
{% endif %}
|
||||
<p> TODO: many </p>
|
||||
<form name="user" method="post" action="/manage_users/add">
|
||||
Username:<input type="text" name=username required placeholder="Username"><br>
|
||||
Passwort:<input type="password" name=password1 required placeholder="Password"><br>
|
||||
Passwort wiederholen:<input type="password" name=password2 required placeholder="Password"><br>
|
||||
Name:<input type="text" name=longname required placeholder="Vorname Nachname"><br>
|
||||
Email:<input type="email" name=email required placeholder="petra@fet.at"><br>
|
||||
Euml ID:<input type="text" name=rfid_id required placeholder="0xDEADBEEF"><br>
|
||||
<input type="submit" value="Hinzufügen">
|
||||
</form>
|
||||
{% endblock %}
|
||||
23
app/templates/manage_users_edit.html
Normal file
23
app/templates/manage_users_edit.html
Normal file
@@ -0,0 +1,23 @@
|
||||
{% extends "base.html"%}
|
||||
{% set title = "Konsumentin bearbeiten" %}
|
||||
{% block content %}
|
||||
<h1> {{user.name}} bearbeiten</h1>
|
||||
{% if error %}
|
||||
<p>Fehler: {{ error }}</p>
|
||||
{% else %}
|
||||
{% if success %}
|
||||
<p>{{ success }}</p>
|
||||
{% endif %}
|
||||
<form name="user" method="post" action="/manage_users/edit">
|
||||
Userid: <input type="text" name="id" required value="{{user_to_edit.id}}" readonly="readonly" /> <br>
|
||||
Username:<input type="text" name="username" required value="{{user_to_edit.name}}" /> <br>
|
||||
Name:<input type="text" name="longname" required value="{{user_to_edit.longname}}" /><br>
|
||||
Email:<input type="email" name="email" required value="{{user_to_edit.email}}" /><br>
|
||||
Euml ID:<input type="text" name="rfid_id" required value="{{user_to_edit.rfid_id}}" /><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>
|
||||
Angezeigt: <input type="checkbox" name="isshown" {% if user_to_edit.isshown %} checked {% endif %} /><br>
|
||||
<input type="submit" value="Übernehmen" />
|
||||
</form>
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
6
app/templates/not_baron.html
Normal file
6
app/templates/not_baron.html
Normal file
@@ -0,0 +1,6 @@
|
||||
{% extends "base.html"%}
|
||||
{% set title = "Fehler 401" %}
|
||||
{% block content %}
|
||||
<h1> Fehler 401 </h1>
|
||||
<p>Du musst Baron sein um auf diese Seite zugreifen zu könnnen.</p>
|
||||
{% endblock %}
|
||||
6
app/templates/not_logged_in.html
Normal file
6
app/templates/not_logged_in.html
Normal file
@@ -0,0 +1,6 @@
|
||||
{% extends "base.html"%}
|
||||
{% set title = "Fehler 401" %}
|
||||
{% block content %}
|
||||
<h1> Fehler 401 </h1>
|
||||
<p>Du musst eingeloggt sein um auf diese Seite zugerreifen zu können.</p>
|
||||
{% endblock %}
|
||||
71
app/user.py
Normal file
71
app/user.py
Normal file
@@ -0,0 +1,71 @@
|
||||
class User:
|
||||
|
||||
def __init__(self):
|
||||
self.id=0;
|
||||
self.name=""
|
||||
self.password=""
|
||||
self.longname=""
|
||||
self.email=""
|
||||
self.rfid_id=""
|
||||
self.isblack=False
|
||||
self.isbaron=False
|
||||
self.isshown=False
|
||||
|
||||
|
||||
def __str__(self):
|
||||
s = "User:"
|
||||
if self.id:
|
||||
s = "%s %d" % (s, self.id)
|
||||
else:
|
||||
s = "%s, None" % s
|
||||
|
||||
if self.name:
|
||||
s = "%s, %s" % (s, self.name)
|
||||
else:
|
||||
s = "%s, None" % s
|
||||
|
||||
if self.password:
|
||||
s = "%s, %s" % (s, self.password)
|
||||
else:
|
||||
s = "%s, None" % s
|
||||
|
||||
if self.longname:
|
||||
s = "%s, %s" % (s, self.longname)
|
||||
else:
|
||||
s = "%s, None" % s
|
||||
|
||||
if self.email:
|
||||
s = "%s, %s" % (s, self.email)
|
||||
else:
|
||||
s = "%s, None" % s
|
||||
|
||||
if self.rfid_id:
|
||||
s = "%s, %s" % (s, self.rfid_id)
|
||||
else:
|
||||
s = "%s, None" % s
|
||||
|
||||
if self.isblack is None:
|
||||
s = "%s, None" % s
|
||||
else:
|
||||
if self.isblack is 0 or self.isblack is False:
|
||||
s = "%s, False" % s
|
||||
else:
|
||||
s = "%s, True" % s
|
||||
|
||||
if self.isbaron is None:
|
||||
s = "%s, None" % s
|
||||
else:
|
||||
if self.isbaron is 0 or self.isbaron is False:
|
||||
s = "%s, False" % s
|
||||
else:
|
||||
s = "%s, True" % s
|
||||
|
||||
if self.isshown 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
|
||||
BIN
app/user.pyc
Normal file
BIN
app/user.pyc
Normal file
Binary file not shown.
BIN
app/users.pyc
Normal file
BIN
app/users.pyc
Normal file
Binary file not shown.
157
app/views.py
Normal file
157
app/views.py
Normal file
@@ -0,0 +1,157 @@
|
||||
from check_rights import *
|
||||
from flask import render_template, request, redirect, session, send_from_directory
|
||||
from app import app
|
||||
from database import *
|
||||
from user import User
|
||||
from product import Product
|
||||
from consumption import Consumption
|
||||
|
||||
|
||||
|
||||
@app.route('/static/<path:path>')
|
||||
def static_proxy(path):
|
||||
return send_from_directory('./static/', path)
|
||||
|
||||
|
||||
@app.route('/')
|
||||
@app.route('/index')
|
||||
def index():
|
||||
consumed = get_consumed()
|
||||
return render_template("index.html", consumed=consumed, user=get_user_by_name(session.get('name')))
|
||||
|
||||
|
||||
@app.route('/login', methods=['POST', 'GET'])
|
||||
def login():
|
||||
error = None
|
||||
|
||||
if 'name' in session: #check if usr is already logged in
|
||||
return redirect('/')
|
||||
|
||||
if request.method == 'POST':
|
||||
u = User()
|
||||
u.name = request.form['username'].lower()
|
||||
|
||||
u = get_user(u)
|
||||
|
||||
if u is None:
|
||||
error = 'User does not exist!'
|
||||
return render_template('login.html', error=error, user=get_user_by_name(session.get('name')))
|
||||
if u.password != request.form['password']:
|
||||
error = 'Wrong password!'
|
||||
return render_template('login.html', error=error, user=get_user_by_name(session.get('name')))
|
||||
|
||||
session['name'] = u.name
|
||||
return redirect('/')
|
||||
|
||||
return render_template('login.html', error=error, user=get_user_by_name(session.get('name')))
|
||||
|
||||
|
||||
@app.route('/logout')
|
||||
@requires_login
|
||||
def logout():
|
||||
session.pop('name', None)
|
||||
return redirect('/')
|
||||
|
||||
|
||||
@app.route('/manage_users')
|
||||
@requires_baron
|
||||
def manage_users():
|
||||
users = get_users()
|
||||
return render_template('manage_users.html', users=users, user=get_user_by_name(session.get('name')))
|
||||
|
||||
|
||||
@app.route('/manage_users/add', methods=['POST', 'GET'])
|
||||
@requires_baron
|
||||
def manage_users_add():
|
||||
if request.method == 'POST':
|
||||
u = User()
|
||||
error = None
|
||||
u.name = request.form['username'].lower()
|
||||
if u.name is None:
|
||||
error = "Username not unique!"
|
||||
|
||||
if request.form['password1'] == request.form['password2']:
|
||||
u.password = request.form['password1']
|
||||
else:
|
||||
error="Passwords do not match!"
|
||||
u.longname=request.form['longname']
|
||||
u.email = request.form['email']
|
||||
u.rfid_id = request.form['rfid_id']
|
||||
|
||||
if error is None:
|
||||
add_user(u)
|
||||
return render_template('manage_users_add.html', success="User created!", user=get_user_by_name(session.get('name')));
|
||||
|
||||
return render_template('manage_users_add.html', error=error, user=get_user_by_name(session.get('name')))
|
||||
return render_template('manage_users_add.html', user=get_user_by_name(session.get('name')))
|
||||
|
||||
|
||||
@app.route('/manage_users/edit', methods=['POST'])
|
||||
@app.route('/manage_users/edit/<name>', methods=['GET'])
|
||||
@requires_baron
|
||||
def manage_users_edit(name=None):
|
||||
if request.method == 'GET':
|
||||
error = None
|
||||
u = User()
|
||||
u.name = name
|
||||
u = get_user(u)
|
||||
|
||||
if u is None:
|
||||
error = "User existiert nicht"
|
||||
|
||||
return render_template('manage_users_edit.html', user_to_edit=u, error=error, user=get_user_by_name(session.get('name')))
|
||||
|
||||
if request.method == 'POST':
|
||||
u = User()
|
||||
#print request.form
|
||||
u.id = request.form['id']
|
||||
u.name = request.form['username'].lower()
|
||||
u.longname=request.form['longname']
|
||||
u.email = request.form['email']
|
||||
u.rfid_id = request.form['rfid_id']
|
||||
|
||||
if 'isblack' in request.form:
|
||||
u.isblack = True
|
||||
else:
|
||||
u.isblack = False
|
||||
|
||||
if 'isbaron' in request.form:
|
||||
u.isbaron = True
|
||||
else:
|
||||
u.isbaron = False
|
||||
|
||||
if 'isshown' in request.form:
|
||||
u.isshown = True
|
||||
else:
|
||||
u.isshown = False
|
||||
|
||||
update_user(u)
|
||||
|
||||
return redirect('/manage_users')
|
||||
|
||||
|
||||
@app.route('/manage_beverages')
|
||||
@requires_baron
|
||||
def manage_beverages():
|
||||
products = get_products()
|
||||
return render_template('manage_beverages.html', products=products, user=get_user_by_name(session.get('name')))
|
||||
|
||||
@app.route('/consume')
|
||||
@requires_login
|
||||
def consume():
|
||||
products = get_products()
|
||||
message = []
|
||||
prodid = request.args.get('prodid')
|
||||
if prodid is not None:
|
||||
prod = get_product_by_id(prodid)
|
||||
username = session.get('name')
|
||||
add_consume(username, prod.id)
|
||||
message = "Du hast gerade ein %s konsumiert." % prod.name
|
||||
return render_template('consume.html', products=products, message=message, user=get_user_by_name(session.get('name')))
|
||||
|
||||
|
||||
@app.route('/billing')
|
||||
@requires_baron
|
||||
def billing():
|
||||
|
||||
return render_template('billing.html', user=get_user_by_name(session.get('name')))
|
||||
BIN
app/views.pyc
Normal file
BIN
app/views.pyc
Normal file
Binary file not shown.
Reference in New Issue
Block a user