diff --git a/registrasion/templatetags/registrasion_tags.py b/registrasion/templatetags/registrasion_tags.py index 02cda54efed7e32fcbdd2d2c515963ab61cc70ac..623159198cd0726905e37a12ab7dda84b72f733f 100644 --- a/registrasion/templatetags/registrasion_tags.py +++ b/registrasion/templatetags/registrasion_tags.py @@ -95,6 +95,17 @@ def items_purchased(context, category=None): ) +@register.assignment_tag(takes_context=True) +def total_items_purchased(context, category=None): + ''' Returns the number of items purchased for this user (sum of quantities). + + The user will be either `context.user`, and `context.request.user` if + the former is not defined. + ''' + + return sum(i.quantity for i in items_purchased(context, category)) + + @register.assignment_tag(takes_context=True) def report_as_csv(context, section):