mirror of
https://github.com/brmlab/brmbar.git
synced 2025-06-07 12:54:05 +02:00
brmbar-web: By default hide out-of-stock items
This commit is contained in:
parent
bf3fd3e842
commit
65741c31f0
1 changed files with 12 additions and 2 deletions
|
@ -10,8 +10,8 @@ from flask import *
|
|||
app = Flask(__name__)
|
||||
#app.debug = True
|
||||
|
||||
@app.route('/stock')
|
||||
def stock():
|
||||
@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>'
|
||||
|
@ -19,13 +19,23 @@ def stock():
|
|||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue