Lash up presentations report for naming videos

This commit is contained in:
Ben Sturmfels 2023-07-17 12:30:47 +10:00
parent 97beb8b131
commit 503b9b164e
Signed by: bsturmfels
GPG key ID: 023C05E2C9C068F0
2 changed files with 42 additions and 0 deletions

View file

@ -1,6 +1,7 @@
from django.conf.urls import url
from .views import (
presentations_report,
speaker_create,
speaker_create_token,
speaker_edit,
@ -18,4 +19,5 @@ urlpatterns = [
url(r"^staff/create/(\d+)/$", speaker_create_staff, name="speaker_create_staff"),
url(r"^talks-report/$", speaker_talks_report, name="speaker_talks_report"),
url(r"^track-report/$", speaker_track_report, name="speaker_track_report"),
url(r"^presentations-report/$", presentations_report, name="presentations_report"),
]

View file

@ -191,3 +191,43 @@ def speaker_talks_report(request):
for row in cursor.fetchall():
writer.writerow(row)
return response
@login_required
@user_passes_test(lambda u: u.is_staff)
def presentations_report(request):
query = """
SELECT day.date,
room.name AS room,
start,
"end",
slot.name AS slot,
p.title,
s.name AS "primary speaker",
STRING_AGG(s2.name, ', ') AS "additional speakers"
FROM symposion_schedule_presentation p
INNER JOIN symposion_speakers_speaker s ON p.speaker_id = s.id
LEFT OUTER JOIN symposion_schedule_presentation_additional_speakers a ON p.id = a.presentation_id
LEFT OUTER JOIN symposion_speakers_speaker s2 ON a.speaker_id = s2.id
INNER JOIN symposion_schedule_slot slot ON p.slot_id = slot.id
INNER JOIN symposion_schedule_day day ON slot.day_id = day.id
INNER JOIN symposion_schedule_slotroom sr ON slot.id = sr.slot_id
INNER JOIN symposion_schedule_room room ON sr.room_id = room.id
GROUP BY p.id,
s.id,
slot.id,
day.id,
room.id
"""
response = HttpResponse(content_type='text/csv')
filename = 'presentations_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