From 194f98bcc4d02cf80a0bab389421ba10ca450bed Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Sat, 2 Apr 2016 18:03:42 +1100 Subject: [PATCH] Refactors available_products to use test_enabling_conditions --- registrasion/controllers/product.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/registrasion/controllers/product.py b/registrasion/controllers/product.py index ec9a73e5..dd1536fc 100644 --- a/registrasion/controllers/product.py +++ b/registrasion/controllers/product.py @@ -30,14 +30,20 @@ class ProductController(object): if products is not None: all_products = itertools.chain(all_products, products) - out = [ + passed_limits = set( product for product in all_products if CategoryController(product.category).user_quantity_remaining(user) > 0 if cls(product).user_quantity_remaining(user) > 0 - if cls(product).can_add_with_enabling_conditions(user, 0) - ] + ) + + failed_conditions = set(ConditionController.test_enabling_conditions( + user, products=passed_limits + )) + + out = list(passed_limits - failed_conditions) out.sort(key=lambda product: product.order) + return out def user_quantity_remaining(self, user):