diff --git a/pretalx_musicrate/__init__.py b/pretalx_musicrate/__init__.py index 777f190..3e2f46a 100644 --- a/pretalx_musicrate/__init__.py +++ b/pretalx_musicrate/__init__.py @@ -1 +1 @@ -__version__ = "0.8.0" +__version__ = "0.9.0" diff --git a/pretalx_musicrate/locale/de_DE/LC_MESSAGES/django.po b/pretalx_musicrate/locale/de_DE/LC_MESSAGES/django.po index 73d9424..85c0cd2 100644 --- a/pretalx_musicrate/locale/de_DE/LC_MESSAGES/django.po +++ b/pretalx_musicrate/locale/de_DE/LC_MESSAGES/django.po @@ -5,10 +5,10 @@ # msgid "" msgstr "" -"Project-Id-Version: pretalx-musicrate 0.0.1\n" +"Project-Id-Version: pretalx-musicrate 0.9.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-16 03:23+0100\n" -"PO-Revision-Date: 2023-12-16 03:24+0100\n" +"POT-Creation-Date: 2023-12-18 01:34+0100\n" +"PO-Revision-Date: 2023-12-18 01:36+0100\n" "Last-Translator: Luca \n" "Language-Team: Luca \n" "Language: de_DE\n" @@ -93,6 +93,14 @@ msgstr "Zum Anhörtag" msgid "pretalx-musicrate settings" msgstr "pretalx-musicrate-Einstellungen" +#: pretalx_musicrate/templates/pretalx_musicrate/settings.html:22 +msgid "Save" +msgstr "Speichern" + +#: pretalx_musicrate/templates/pretalx_musicrate/settings.html:30 +msgid "Export ratings" +msgstr "Bewertungen exportieren" + #: pretalx_musicrate/templates/pretalx_musicrate/submission_base.html:29 msgid "(not specified)" msgstr "(nicht angegeben)" @@ -105,19 +113,19 @@ msgstr "Zurück" msgid "Next" msgstr "Weiter" -#: pretalx_musicrate/views.py:39 +#: pretalx_musicrate/views.py:41 msgid "Invalid token" msgstr "Ungültiges Token" -#: pretalx_musicrate/views.py:114 +#: pretalx_musicrate/views.py:116 msgid "The pretalx-musicrate settings were updated." msgstr "Die pretalx-musicrate-Einstellungen wurden gespeichert." -#: pretalx_musicrate/views.py:273 +#: pretalx_musicrate/views.py:275 msgid "Saved!" msgstr "Gespeichert!" -#: pretalx_musicrate/views.py:375 +#: pretalx_musicrate/views.py:377 #, python-format msgid "%(num_ratings)d of %(num_jurors)d has rated this submission" msgid_plural "%(num_ratings)d of %(num_jurors)d have rated this submission" diff --git a/pretalx_musicrate/templates/pretalx_musicrate/settings.html b/pretalx_musicrate/templates/pretalx_musicrate/settings.html index d29bc8d..a04ef8f 100644 --- a/pretalx_musicrate/templates/pretalx_musicrate/settings.html +++ b/pretalx_musicrate/templates/pretalx_musicrate/settings.html @@ -24,4 +24,9 @@ +
+ + + {% translate "Export ratings" %} + {% endblock %} diff --git a/pretalx_musicrate/urls.py b/pretalx_musicrate/urls.py index 75769ec..6938523 100644 --- a/pretalx_musicrate/urls.py +++ b/pretalx_musicrate/urls.py @@ -1,6 +1,7 @@ from django.urls import include, path from .views import ( + ExportView, JoinView, MayAdvanceView, MusicrateSettingsView, @@ -12,8 +13,12 @@ from .views import ( urlpatterns = [ path( "orga/event//settings/p/pretalx_musicrate/", - MusicrateSettingsView.as_view(), - name="settings.musicrate", + include( + [ + path("", MusicrateSettingsView.as_view(), name="settings.musicrate"), + path("export/", ExportView.as_view(), name="export"), + ] + ), ), path( "/p/pretalx_musicrate/", diff --git a/pretalx_musicrate/views.py b/pretalx_musicrate/views.py index cfe0512..40c9424 100644 --- a/pretalx_musicrate/views.py +++ b/pretalx_musicrate/views.py @@ -1,9 +1,11 @@ +import csv import re from hmac import compare_digest from urllib.parse import parse_qs, urlparse from django.contrib import messages -from django.http import JsonResponse +from django.db.models import Case, FilteredRelation, Q, Value, When +from django.http import HttpResponse, JsonResponse from django.shortcuts import get_object_or_404, redirect from django.urls import reverse from django.utils.functional import cached_property @@ -379,3 +381,53 @@ class MayAdvanceView(EventPermissionRequired, SubmissionMixin, View): % {"num_jurors": num_jurors, "num_ratings": num_ratings}, } ) + + +class ExportView(EventPermissionRequired, View): + permission_required = "orga.view_submissions" + + def get(self, request, *args, **kwargs): + response = HttpResponse( + content_type="text/csv", + headers={ + "Content-Disposition": f'attachment; filename="{request.event.slug}.csv"' + }, + ) + writer = csv.writer(response) + genre_question = request.event.pretalx_musicrate_settings.genre_question + origin_question = request.event.pretalx_musicrate_settings.origin_question + jurors = request.event.jurors.order_by("token") + for submission in request.event.submissions.prefetch_related("answers").filter( + submission_type__in=request.event.pretalx_musicrate_settings.submission_types.all() + ): + submission_info = [submission.title, submission.submission_type.name] + if genre_question is not None: + submission_info.append( + submission.answers.filter(question=genre_question) + .values_list("answer", flat=True) + .first() + or "" + ) + if origin_question is not None: + submission_info.append( + submission.answers.filter(question=origin_question) + .values_list("answer", flat=True) + .first() + or "" + ) + writer.writerow( + [ + *submission_info, + *jurors.annotate( + filtered_ratings=FilteredRelation( + "ratings", condition=Q(ratings__submission=submission) + ), + rating=Case( + When(filtered_ratings__rating=None, then=Value("")), + When(filtered_ratings__rating="", then=Value("E")), + default="filtered_ratings__rating", + ), + ).values_list("rating", flat=True), + ] + ) + return response