Commits

Preston Holmes committed b34f3e0

added a CSV download of purchase data

  • Participants
  • Parent commits 5c91a55

Comments (0)

Files changed (3)

File tickets-project/dev.db

Binary file modified.

File tickets/urls.py

     url(r'^(?P<event_slug>\w*)/$','views.purchase'),
     url(r'^payment/verification/', include('paypal.standard.ipn.urls')),
     url(r'^sold_out$',direct_to_template,{'template':"tickets/sold_out.html"},name="sold_out"),
-
+    url(r'purchasedata$','views.purchase_data_csv'),
 # list/types
 # list/purchases
 # ticket/buy

File tickets/views.py

 from django.conf import settings
 from django.shortcuts import render_to_response, redirect, get_object_or_404
-from django.http import HttpResponseBadRequest, HttpResponse
+from django.http import HttpResponseBadRequest, HttpResponse, HttpResponseForbidden
 from django.views.generic.simple import direct_to_template
 from django import forms
 from django.template import RequestContext
 from django.forms.util import ErrorList
+from django.contrib.auth.decorators import login_required
 
 from paypal.standard.forms import PayPalPaymentsForm
 from tickets.models import *
 from tickets.forms import *
 
+import csv
+
+@login_required
+def purchase_data_csv (request):
+    if not request.user.is_staff:
+        return HttpResponseForbidden("you must have admin access")
+    response = HttpResponse(mimetype='text/csv')
+    response['Content-Disposition'] = 'attachment; filename=ticketpurchases.csv'
+    purchases = TicketPurchase.objects.all()
+    writer = csv.writer(response)
+    writer.writerow(['date', 'amount', 'name', 'status'])
+    for p in purchases:
+        writer.writerow([p.date, p.amount,p.name, p.status])
+    return response
+    
 def initiated(request):
     pass