diff --git a/vendor/symposion/symposion/speakers/urls.py b/vendor/symposion/symposion/speakers/urls.py index 8425f78a..ecd70709 100644 --- a/vendor/symposion/symposion/speakers/urls.py +++ b/vendor/symposion/symposion/speakers/urls.py @@ -16,4 +16,5 @@ urlpatterns = [ 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"), + url(r"^talks-report/$", speaker_track_report, name="speaker_talks_report"), ] diff --git a/vendor/symposion/symposion/speakers/views.py b/vendor/symposion/symposion/speakers/views.py index ada4b8a7..19dd0e08 100644 --- a/vendor/symposion/symposion/speakers/views.py +++ b/vendor/symposion/symposion/speakers/views.py @@ -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