mirror of
https://github.com/brmlab/brmbar.git
synced 2025-06-07 21:04:00 +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 = Flask(__name__)
|
||||||
#app.debug = True
|
#app.debug = True
|
||||||
|
|
||||||
@app.route('/stock')
|
@app.route('/stock/')
|
||||||
def stock():
|
def stock(show_all=False):
|
||||||
# TODO: Use a fancy template.
|
# TODO: Use a fancy template.
|
||||||
# FIXME: XSS protection.
|
# FIXME: XSS protection.
|
||||||
response = '<table border="1"><tr><th>Id</th><th>Item Name</th><th>Bal.</th></tr>'
|
response = '<table border="1"><tr><th>Id</th><th>Item Name</th><th>Bal.</th></tr>'
|
||||||
|
@ -19,13 +19,23 @@ def stock():
|
||||||
style = ''
|
style = ''
|
||||||
balance = a.balance()
|
balance = a.balance()
|
||||||
if balance == 0:
|
if balance == 0:
|
||||||
|
if not show_all:
|
||||||
|
continue
|
||||||
style = 'color: grey; font-style: italic'
|
style = 'color: grey; font-style: italic'
|
||||||
elif balance < 0:
|
elif balance < 0:
|
||||||
style = 'color: red'
|
style = 'color: red'
|
||||||
response += '<tr style="%s"><td>%d</td><td>%s</td><td>%d</td></tr>' % (style, a.id, a.name, balance)
|
response += '<tr style="%s"><td>%d</td><td>%s</td><td>%d</td></tr>' % (style, a.id, a.name, balance)
|
||||||
response += '</table>'
|
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
|
return response
|
||||||
|
|
||||||
|
@app.route('/stock/all')
|
||||||
|
def stockall():
|
||||||
|
return stock(show_all=True)
|
||||||
|
|
||||||
|
|
||||||
db = Database.Database("dbname=brmbar")
|
db = Database.Database("dbname=brmbar")
|
||||||
shop = brmbar.Shop.new_with_defaults(db)
|
shop = brmbar.Shop.new_with_defaults(db)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue