From 1fccc11354e75b44cc45ad3e7efd0143e36eb807 Mon Sep 17 00:00:00 2001 From: Ben Sturmfels Date: Tue, 23 May 2023 12:22:33 +1000 Subject: [PATCH] Add report for reviewing speakers/talks across all tracks --- vendor/symposion/symposion/speakers/urls.py | 4 ++- vendor/symposion/symposion/speakers/views.py | 32 +++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/vendor/symposion/symposion/speakers/urls.py b/vendor/symposion/symposion/speakers/urls.py index a3cf7e2c..8425f78a 100644 --- a/vendor/symposion/symposion/speakers/urls.py +++ b/vendor/symposion/symposion/speakers/urls.py @@ -5,7 +5,8 @@ from .views import ( speaker_create_token, speaker_edit, speaker_profile, - speaker_create_staff + speaker_create_staff, + speaker_track_report, ) urlpatterns = [ @@ -14,4 +15,5 @@ urlpatterns = [ url(r"^edit/(?:(?P\d+)/)?$", speaker_edit, name="speaker_edit"), url(r"^profile/(?P\d+)/$", speaker_profile, name="speaker_profile"), url(r"^staff/create/(\d+)/$", speaker_create_staff, name="speaker_create_staff"), + url(r"^track-report/$", speaker_track_report, name="speaker_track_report"), ] diff --git a/vendor/symposion/symposion/speakers/views.py b/vendor/symposion/symposion/speakers/views.py index eea2df05..ada4b8a7 100644 --- a/vendor/symposion/symposion/speakers/views.py +++ b/vendor/symposion/symposion/speakers/views.py @@ -1,5 +1,10 @@ +import csv +import datetime + +from django.contrib.auth.decorators import user_passes_test from django.core.exceptions import ObjectDoesNotExist -from django.http import Http404 +from django.db import connection +from django.http import Http404, HttpResponse from django.shortcuts import render, redirect, get_object_or_404 from django.views.decorators.clickjacking import xframe_options_exempt @@ -135,3 +140,28 @@ def speaker_profile(request, pk): "speaker": speaker, "presentations": presentations, }) + + +@login_required +@user_passes_test(lambda u: u.is_staff) +def speaker_track_report(request): + query = """ + SELECT speaker.name speaker, email, telephone, kind.name track, title + FROM symposion_proposals_proposalbase + INNER JOIN symposion_speakers_speaker speaker ON speaker_id = speaker.id + INNER JOIN symposion_proposals_proposalkind kind ON kind_id = kind.id + INNER JOIN auth_user ON user_id = auth_user.id + ORDER BY speaker.name, title, track + """ + response = HttpResponse(content_type='text/csv') + filename = 'speaker_track_report-{}.csv'.format( + datetime.datetime.now().strftime('%Y-%m-%d'), + ) + response['Content-Disposition'] = f'attachment; filename={filename}' + writer = csv.writer(response) + with connection.cursor() as cursor: + cursor.execute(query) + writer.writerow([i[0] for i in cursor.description]) + for row in cursor.fetchall(): + writer.writerow(row) + return response