From 67ac01e599d4e7c45410f083eb3001ae7e0fe1ab Mon Sep 17 00:00:00 2001 From: Christopher Neugebauer Date: Fri, 14 Oct 2016 11:36:31 -0700 Subject: [PATCH] Adds a tag to take the CSV version of a report --- registrasion/templatetags/registrasion_tags.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/registrasion/templatetags/registrasion_tags.py b/registrasion/templatetags/registrasion_tags.py index fda5b2c0..7d2bb56e 100644 --- a/registrasion/templatetags/registrasion_tags.py +++ b/registrasion/templatetags/registrasion_tags.py @@ -4,6 +4,7 @@ from registrasion.controllers.item import ItemController from django import template from django.db.models import Sum +from urllib import urlencode register = template.Library() @@ -74,3 +75,14 @@ def items_purchased(context, category=None): return ItemController(context.request.user).items_purchased( category=category ) + + +@register.assignment_tag(takes_context=True) +def report_as_csv(context, section): + + query = dict(context.request.GET) + query["section"] = section + query["content_type"] = "text/csv" + querystring = urlencode(query) + + return context.request.path + "?" + querystring