Files
@ 2b59151429fe
Branch filter:
Location: symposion_app/registrasion/templatetags/registrasion_tags.py - annotation
2b59151429fe
1.9 KiB
text/x-python
Merge branch 'random_fixes'
c192fef491c4 f7289c21019b c192fef491c4 36ecf7fd5489 c192fef491c4 36ecf7fd5489 c192fef491c4 c192fef491c4 c192fef491c4 36ecf7fd5489 8d66ed57150d db332da9584d c192fef491c4 c192fef491c4 c192fef491c4 f7289c21019b 36ecf7fd5489 db332da9584d 36ecf7fd5489 36ecf7fd5489 36ecf7fd5489 36ecf7fd5489 36ecf7fd5489 db332da9584d 36ecf7fd5489 36ecf7fd5489 36ecf7fd5489 36ecf7fd5489 36ecf7fd5489 36ecf7fd5489 36ecf7fd5489 36ecf7fd5489 53413388e016 36ecf7fd5489 36ecf7fd5489 db332da9584d 36ecf7fd5489 4021aa3c8ebc 4021aa3c8ebc 4021aa3c8ebc 36ecf7fd5489 36ecf7fd5489 36ecf7fd5489 36ecf7fd5489 53413388e016 53413388e016 36ecf7fd5489 4021aa3c8ebc 4021aa3c8ebc 4021aa3c8ebc 53413388e016 53413388e016 36ecf7fd5489 53413388e016 53413388e016 53413388e016 36ecf7fd5489 aa6377f4ce88 12e4d0a3cb24 aa6377f4ce88 aa6377f4ce88 aa6377f4ce88 aa6377f4ce88 | from registrasion import models as rego
from registrasion.controllers.category import CategoryController
from collections import namedtuple
from django import template
from django.db.models import Sum
register = template.Library()
ProductAndQuantity = namedtuple("ProductAndQuantity", ["product", "quantity"])
@register.assignment_tag(takes_context=True)
def available_categories(context):
''' Returns all of the available product categories '''
return CategoryController.available_categories(context.request.user)
@register.assignment_tag(takes_context=True)
def invoices(context):
''' Returns all of the invoices that this user has. '''
return rego.Invoice.objects.filter(cart__user=context.request.user)
@register.assignment_tag(takes_context=True)
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,
).select_related("product", "product__category")
return all_items
@register.assignment_tag(takes_context=True)
def items_purchased(context, category=None):
''' Returns all of the items that this user has purchased, optionally
from the given category. '''
all_items = rego.ProductItem.objects.filter(
cart__user=context.request.user,
cart__active=False,
cart__released=False,
).select_related("product", "product__category")
if category:
all_items = all_items.filter(product__category=category)
pq = all_items.values("product").annotate(quantity=Sum("quantity")).all()
products = rego.Product.objects.all()
out = []
for item in pq:
prod = products.get(pk=item["product"])
out.append(ProductAndQuantity(prod, item["quantity"]))
return out
@register.filter
def multiply(value, arg):
''' Multiplies value by arg '''
return value * arg
|