Add speaker talks report
This commit is contained in:
parent
1fccc11354
commit
8f2fb70094
2 changed files with 27 additions and 0 deletions
1
vendor/symposion/symposion/speakers/urls.py
vendored
1
vendor/symposion/symposion/speakers/urls.py
vendored
|
@ -16,4 +16,5 @@ urlpatterns = [
|
||||||
url(r"^profile/(?P<pk>\d+)/$", speaker_profile, name="speaker_profile"),
|
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"^staff/create/(\d+)/$", speaker_create_staff, name="speaker_create_staff"),
|
||||||
url(r"^track-report/$", speaker_track_report, name="speaker_track_report"),
|
url(r"^track-report/$", speaker_track_report, name="speaker_track_report"),
|
||||||
|
url(r"^talks-report/$", speaker_track_report, name="speaker_talks_report"),
|
||||||
]
|
]
|
||||||
|
|
26
vendor/symposion/symposion/speakers/views.py
vendored
26
vendor/symposion/symposion/speakers/views.py
vendored
|
@ -165,3 +165,29 @@ def speaker_track_report(request):
|
||||||
for row in cursor.fetchall():
|
for row in cursor.fetchall():
|
||||||
writer.writerow(row)
|
writer.writerow(row)
|
||||||
return response
|
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
|
||||||
|
|
Loading…
Reference in a new issue