Add debug logging for product availability checks
This commit is contained in:
parent
8d46544a5c
commit
e723ec937b
1 changed files with 10 additions and 0 deletions
|
@ -1,4 +1,5 @@
|
|||
import itertools
|
||||
import logging
|
||||
|
||||
from django.db.models import Case
|
||||
from django.db.models import F, Q
|
||||
|
@ -23,6 +24,9 @@ class ProductController(object):
|
|||
def available_products(cls, user, category=None, products=None):
|
||||
''' Returns a list of all of the products that are available per
|
||||
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:
|
||||
raise ValueError("You must provide products or a category")
|
||||
|
||||
|
@ -45,14 +49,20 @@ class ProductController(object):
|
|||
if product_remainders[product.id] > 0
|
||||
)
|
||||
|
||||
logging.debug("Passed limits: %s", passed_limits)
|
||||
|
||||
failed_and_messages = FlagController.test_flags(
|
||||
user, products=passed_limits
|
||||
)
|
||||
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.sort(key=lambda product: product.order)
|
||||
|
||||
logging.debug("Returning: %s", out)
|
||||
|
||||
return out
|
||||
|
||||
@classmethod
|
||||
|
|
Loading…
Reference in a new issue