@@ -26,32 +26,36 @@ def invoices(context):
def items_pending(context):
''' Returns all of the items that this user has in their current cart,
and is awaiting payment. '''
all_items = rego.ProductItem.objects.filter(
cart__user=context.request.user,
cart__active=True,
)
return all_items
@register.assignment_tag(takes_context=True)
def items_purchased(context):
''' Returns all of the items that this user has purchased '''
def items_purchased(context, category=None):
''' Returns all of the items that this user has purchased, optionally
from the given category. '''
cart__active=False,
if category:
all_items = all_items.filter(product__category=category)
products = set(item.product for item in all_items)
out = []
for product in products:
pp = all_items.filter(product=product)
quantity = pp.aggregate(Sum("quantity"))["quantity__sum"]
out.append(ProductAndQuantity(product, quantity))
return out
@register.filter
def multiply(value, arg):
''' Multiplies value by arg '''