Add report for reviewing speakers/talks across all tracks

This commit is contained in:
Ben Sturmfels 2023-05-23 12:22:33 +10:00
parent c56b15f279
commit 1fccc11354
Signed by: bsturmfels
GPG key ID: 023C05E2C9C068F0
2 changed files with 34 additions and 2 deletions

View file

@ -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<pk>\d+)/)?$", speaker_edit, name="speaker_edit"),
url(r"^profile/(?P<pk>\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"),
]

View file

@ -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