#!/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 = '
Id | Item Name | Bal. |
'
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 += '%d | %s | %d |
' % (style, a.id, a.name, balance)
response += '
'
if show_all:
response += '(hide out-of-stock items)
'
else:
response += '(show all items)
'
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')