From 9da41c06de54dc2dfd7ef41b44005b41432f774e Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Mon, 9 Jan 2017 18:57:49 +1100 Subject: [PATCH] Adds first badge support --- registrasion/templatetags/registrasion_tags.py | 11 +++++++++++ registrasion/urls.py | 2 ++ registrasion/views.py | 18 ++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/registrasion/templatetags/registrasion_tags.py b/registrasion/templatetags/registrasion_tags.py index 02cda54e..62315919 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): diff --git a/registrasion/urls.py b/registrasion/urls.py index 8f2e1663..322ee62c 100644 --- a/registrasion/urls.py +++ b/registrasion/urls.py @@ -5,6 +5,7 @@ from django.conf.urls import url from .views import ( amend_registration, + badge, checkout, credit_note, edit_profile, @@ -22,6 +23,7 @@ from .views import ( public = [ url(r"^amend/([0-9]+)$", amend_registration, name="amend_registration"), + url(r"^badge/([0-9]+)$", badge, name="badge"), url(r"^category/([0-9]+)$", product_category, name="product_category"), url(r"^checkout$", checkout, name="checkout"), url(r"^checkout/([0-9]+)$", checkout, name="checkout"), diff --git a/registrasion/views.py b/registrasion/views.py index 24e5ebf1..83e5ed97 100644 --- a/registrasion/views.py +++ b/registrasion/views.py @@ -968,3 +968,21 @@ def invoice_mailout(request): } return render(request, "registrasion/invoice_mailout.html", data) + + +@user_passes_test(_staff_only) +def badge(request, user_id): + ''' Renders a single user's badge (SVG). ''' + + user_id = int(user_id) + + data = { + "user": User.objects.get(pk=user_id), + } + + print User.objects.get(pk=user_id) + + response = render(request, "registrasion/badge.svg", data) + response["Content-Type"] = "image/svg+xml" + response["Content-Disposition"] = 'inline; filename="badge.svg"' + return response