Add speaker talks report

This commit is contained in:
Ben Sturmfels 2023-05-23 13:05:43 +10:00
parent 1fccc11354
commit 8f2fb70094
Signed by: bsturmfels
GPG key ID: 023C05E2C9C068F0
2 changed files with 27 additions and 0 deletions

View file

@ -16,4 +16,5 @@ urlpatterns = [
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"),
url(r"^talks-report/$", speaker_track_report, name="speaker_talks_report"),
]

View file

@ -165,3 +165,29 @@ def speaker_track_report(request):
for row in cursor.fetchall():
writer.writerow(row)
return response
@login_required
@user_passes_test(lambda u: u.is_staff)
def speaker_talks_report(request):
query = """
SELECT speaker.name speaker, email, telephone, COUNT(*) num_talks, STRING_agg(title, '; ') tracks
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
GROUP BY speaker.id, auth_user.id
ORDER BY num_talks desc
"""
response = HttpResponse(content_type='text/csv')
filename = 'speaker_talks_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