forked from brmlab/brmbar
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrmbar-web.py
executable file
·45 lines (36 loc) · 1.15 KB
/
brmbar-web.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/python
import sys
from brmbar import Database
import brmbar
from flask import *
app = Flask(__name__)
#app.debug = True
@app.route('/stock/')
def stock(show_all=False):
# TODO: Use a fancy template.
# FIXME: XSS protection.
response = '<table border="1"><tr><th>Id</th><th>Item Name</th><th>Bal.</th></tr>'
for a in shop.account_list("inventory"):
style = ''
balance = a.balance()
if balance == 0:
if not show_all:
continue
style = 'color: grey; font-style: italic'
elif balance < 0:
style = 'color: red'
response += '<tr style="%s"><td>%d</td><td>%s</td><td>%d</td></tr>' % (style, a.id, a.name, balance)
response += '</table>'
if show_all:
response += '<p><a href=".">(hide out-of-stock items)</a></p>'
else:
response += '<p><a href="all">(show all items)</a></p>'
return response
@app.route('/stock/all')
def stockall():
return stock(show_all=True)
db = Database.Database("dbname=brmbar")
shop = brmbar.Shop.new_with_defaults(db)
currency = shop.currency
if __name__ == '__main__':
app.run(host='0.0.0.0')