From 361144815ed64e4221580ea848867b8ad2035bd3 Mon Sep 17 00:00:00 2001 From: s3lph Date: Wed, 7 Apr 2021 01:25:45 +0200 Subject: [PATCH] Improve support for stock providers --- matemat/webserver/pagelets/buy.py | 12 ++++++------ package/debian/matemat/DEBIAN/control | 2 +- templates/productlist.html | 5 +++-- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/matemat/webserver/pagelets/buy.py b/matemat/webserver/pagelets/buy.py index bd64b2e..350b20e 100644 --- a/matemat/webserver/pagelets/buy.py +++ b/matemat/webserver/pagelets/buy.py @@ -25,11 +25,11 @@ def buy(): if 'pid' in request.params: pid = int(str(request.params.pid)) product = db.get_product(pid) - # Create a consumption entry for the (user, product) combination - db.increment_consumption(user, product) - stock_provider = c.get_stock_provider() - if stock_provider.needs_update(): - stock_provider.update_stock(product, -1) - c.get_dispenser().dispense(product, 1) + if c.get_dispenser().dispense(product, 1): + # Create a consumption entry for the (user, product) combination + db.increment_consumption(user, product) + stock_provider = c.get_stock_provider() + if stock_provider.needs_update(): + stock_provider.update_stock(product, -1) # Redirect to the main page (where this request should have come from) redirect('/') diff --git a/package/debian/matemat/DEBIAN/control b/package/debian/matemat/DEBIAN/control index 43e9faa..37e9315 100644 --- a/package/debian/matemat/DEBIAN/control +++ b/package/debian/matemat/DEBIAN/control @@ -1,5 +1,5 @@ Package: matemat -Version: 0.2.4 +Version: 0.2.6 Maintainer: s3lph Section: web Priority: optional diff --git a/templates/productlist.html b/templates/productlist.html index 51ae56f..fbbc038 100644 --- a/templates/productlist.html +++ b/templates/productlist.html @@ -34,8 +34,9 @@
Picture of {{ product.name }} - {% if product.stockable %} - {{ stock.get_stock(product) }} + {% set pstock = stock.get_stock(product) %} + {% if pstock is not none %} + {{ pstock }} {% endif %}