From c69349f3e323c21729594410b848d7abefdd2a75 Mon Sep 17 00:00:00 2001 From: Pat Pannuto Date: Fri, 1 Aug 2014 16:57:09 -0400 Subject: [PATCH] Show discontinued items with request link on items page Closes #83 --- chezbetty/__init__.py | 1 + chezbetty/templates/items.jinja2 | 21 +++++++++++++++++++++ chezbetty/views.py | 11 ++++++++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/chezbetty/__init__.py b/chezbetty/__init__.py index 5fdb796..34ed291 100644 --- a/chezbetty/__init__.py +++ b/chezbetty/__init__.py @@ -67,6 +67,7 @@ def debug(request): config.add_route('item', '/item/{barcode}/json') config.add_route('item_request', '/item/request') config.add_route('item_request_new', '/item/request/new') + config.add_route('item_request_by_id', '/item/request/by_id/{id}') config.add_route('shame', '/shame') config.add_route('user', '/user/{umid}') diff --git a/chezbetty/templates/items.jinja2 b/chezbetty/templates/items.jinja2 index fdfeda0..6db16e3 100644 --- a/chezbetty/templates/items.jinja2 +++ b/chezbetty/templates/items.jinja2 @@ -56,6 +56,27 @@ Betty stops selling something you would like back, feel free to + +

Discontinued Items:

+ + + + + + + + + + + {% for item in disabled_items %} + + + + + {% endfor %} + + +
Item
{{ item.name }}Request Return
diff --git a/chezbetty/views.py b/chezbetty/views.py index ed5a5f9..45d85fb 100644 --- a/chezbetty/views.py +++ b/chezbetty/views.py @@ -61,7 +61,10 @@ def items(request): items = DBSession.query(Item)\ .filter(Item.enabled==True)\ .order_by(Item.name).all() - return {'items': items} + disabled_items = DBSession.query(Item)\ + .filter(Item.enabled==False)\ + .order_by(Item.name).all() + return {'items': items, 'disabled_items': disabled_items} @view_config(route_name='item_request', renderer='templates/item_request.jinja2') @@ -293,6 +296,12 @@ def item_request_new(request): request.session.flash('Error adding request.', 'error') return HTTPFound(location=request.route_url('index')) +@view_config(route_name='item_request_by_id') +def item_request_by_id(request): + item = Item.from_id(request.matchdict['id']) + datalayer.new_request(None, item.name) + request.session.flash('Request for {} added successfully'.format(item.name), 'success') + return HTTPFound(location=request.route_url('index')) @view_config(route_name='purchase_new', request_method='POST', renderer='json', permission='service') def purchase_new(request):