From b48d66fd9de61f17e922fd2e8475ffe0fdfa13ef Mon Sep 17 00:00:00 2001 From: James Tauber Date: Tue, 9 Oct 2012 15:07:55 -0400 Subject: [PATCH] csv schedule export --- symposion/schedule/urls.py | 2 ++ symposion/schedule/views.py | 23 ++++++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/symposion/schedule/urls.py b/symposion/schedule/urls.py index 2568577f..e00d61e0 100644 --- a/symposion/schedule/urls.py +++ b/symposion/schedule/urls.py @@ -5,9 +5,11 @@ urlpatterns = patterns("symposion.schedule.views", url(r"^$", "schedule_detail", name="schedule_detail"), url(r"^edit/$", "schedule_edit", name="schedule_edit"), url(r"^list/$", "schedule_list", name="schedule_list"), + url(r"^presentations.csv$", "schedule_list_csv", name="schedule_list_csv"), url(r"^presentation/(\d+)/$", "schedule_presentation_detail", name="schedule_presentation_detail"), url(r"^(\w+)/$", "schedule_detail", name="schedule_detail"), url(r"^(\w+)/edit/$", "schedule_edit", name="schedule_edit"), url(r"^(\w+)/list/$", "schedule_list", name="schedule_list"), + url(r"^(\w+)/presentations.csv$", "schedule_list_csv", name="schedule_list_csv"), url(r"^(\w+)/edit/slot/(\d+)/", "schedule_slot_edit", name="schedule_slot_edit"), ) diff --git a/symposion/schedule/views.py b/symposion/schedule/views.py index a19f700d..99cad340 100644 --- a/symposion/schedule/views.py +++ b/symposion/schedule/views.py @@ -1,6 +1,7 @@ from django.core.exceptions import ObjectDoesNotExist -from django.http import Http404 +from django.http import Http404, HttpResponse from django.shortcuts import render, get_object_or_404, redirect +from django.template import loader, Context from django.contrib.auth.decorators import login_required @@ -50,6 +51,26 @@ def schedule_list(request, slug=None): return render(request, "schedule/schedule_list.html", ctx) +def schedule_list_csv(request, slug=None): + schedule = fetch_schedule(slug) + + presentations = Presentation.objects.filter(section=schedule.section) + presentations = presentations.exclude(cancelled=True).order_by("id") + + response = HttpResponse(mimetype="text/csv") + if slug: + file_slug = slug + else: + file_slug = "presentations" + response["Content-Disposition"] = 'attachment; filename="%s.csv"' % file_slug + + response.write(loader.get_template("schedule/schedule_list.csv").render(Context({ + "presentations": presentations, + + }))) + return response + + @login_required def schedule_edit(request, slug=None):