From a0422f0e84339eb5e3ba124dbffd33588eeacee2 Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Fri, 24 Nov 2017 15:01:38 -0800 Subject: [PATCH] Adds a couple of template tags --- pinaxcon/templatetags/nbpy_tags.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/pinaxcon/templatetags/nbpy_tags.py b/pinaxcon/templatetags/nbpy_tags.py index e5ccdaf..e3f51d8 100644 --- a/pinaxcon/templatetags/nbpy_tags.py +++ b/pinaxcon/templatetags/nbpy_tags.py @@ -1,6 +1,7 @@ from registrasion.models import commerce from registrasion.controllers.category import CategoryController from registrasion.controllers.item import ItemController +from registrasion.templatetags import registrasion_tags from decimal import Decimal from django import template @@ -42,3 +43,26 @@ def donation_income(context, invoice): donation = max(Decimal('0'), (invoice.value - sum(rbi))) return donation.quantize(Decimal('.01')) + + +# TODO: include van/de/van der/de la/etc etc etc + +@register.simple_tag +def name_split(name): + + tokens = name.split() + even_split = int((len(tokens) + 1) / 2) # Round up. + + return { + "first" : " ".join(tokens[:even_split]), + "last" : " ".join(tokens[even_split:]), + } + + +@register.simple_tag(takes_context=True) +def ticket_type(context): + + items = registrasion_tags.items_purchased(context) + for item in items: + if item.product.category.name == "Ticket": + return item.product.name