Add debug logging for product availability checks

This commit is contained in:
James Polley 2019-01-21 10:43:47 +13:00
parent 8d46544a5c
commit e723ec937b

View file

@ -1,4 +1,5 @@
import itertools import itertools
import logging
from django.db.models import Case from django.db.models import Case
from django.db.models import F, Q from django.db.models import F, Q
@ -23,6 +24,9 @@ class ProductController(object):
def available_products(cls, user, category=None, products=None): def available_products(cls, user, category=None, products=None):
''' Returns a list of all of the products that are available per ''' Returns a list of all of the products that are available per
flag conditions from the given categories. ''' flag conditions from the given categories. '''
logging.debug("Checking available products for user %(user)s: "
"category %(category)s or products %(product)s",
{'user': user, 'category': category, 'products': products})
if category is None and products is None: if category is None and products is None:
raise ValueError("You must provide products or a category") raise ValueError("You must provide products or a category")
@ -45,14 +49,20 @@ class ProductController(object):
if product_remainders[product.id] > 0 if product_remainders[product.id] > 0
) )
logging.debug("Passed limits: %s", passed_limits)
failed_and_messages = FlagController.test_flags( failed_and_messages = FlagController.test_flags(
user, products=passed_limits user, products=passed_limits
) )
failed_conditions = set(i[0] for i in failed_and_messages) failed_conditions = set(i[0] for i in failed_and_messages)
logging.debug("Failed conditions: %s", failed_conditions)
out = list(passed_limits - failed_conditions) out = list(passed_limits - failed_conditions)
out.sort(key=lambda product: product.order) out.sort(key=lambda product: product.order)
logging.debug("Returning: %s", out)
return out return out
@classmethod @classmethod