From 66d315e8d65202c1353f06470d973ad8da07a335 Mon Sep 17 00:00:00 2001 From: Luca Date: Sat, 16 Dec 2023 03:29:52 +0100 Subject: [PATCH] feat: look for links in configured questions --- pretalx_musicrate/forms.py | 4 ++++ .../locale/de_DE/LC_MESSAGES/django.po | 16 ++++++++----- .../0006_musicratesettings_link_questions.py | 24 +++++++++++++++++++ pretalx_musicrate/models.py | 6 +++++ .../templates/pretalx_musicrate/settings.html | 1 + pretalx_musicrate/views.py | 4 ++++ 6 files changed, 49 insertions(+), 6 deletions(-) create mode 100644 pretalx_musicrate/migrations/0006_musicratesettings_link_questions.py diff --git a/pretalx_musicrate/forms.py b/pretalx_musicrate/forms.py index 96ec3fb..b3f75d4 100644 --- a/pretalx_musicrate/forms.py +++ b/pretalx_musicrate/forms.py @@ -23,6 +23,7 @@ class MusicrateSettingsForm(I18nModelForm): if self.instance.genre_question else event.questions.all() ) + self.fields["link_questions"].queryset = event.questions.all() class Meta: model = MusicrateSettings @@ -30,17 +31,20 @@ class MusicrateSettingsForm(I18nModelForm): "submission_types", "genre_question", "origin_question", + "link_questions", "advance_threshold", ) widgets = { "submission_types": forms.SelectMultiple(attrs={"class": "select2"}), "genre_question": forms.Select(attrs={"class": "select2"}), "origin_question": forms.Select(attrs={"class": "select2"}), + "link_questions": forms.SelectMultiple(attrs={"class": "select2"}), } field_classes = { "submission_types": SafeModelMultipleChoiceField, "genre_question": SafeModelChoiceField, "origin_question": SafeModelChoiceField, + "link_questions": SafeModelMultipleChoiceField, } diff --git a/pretalx_musicrate/locale/de_DE/LC_MESSAGES/django.po b/pretalx_musicrate/locale/de_DE/LC_MESSAGES/django.po index b70eb58..73d9424 100644 --- a/pretalx_musicrate/locale/de_DE/LC_MESSAGES/django.po +++ b/pretalx_musicrate/locale/de_DE/LC_MESSAGES/django.po @@ -7,8 +7,8 @@ msgid "" msgstr "" "Project-Id-Version: pretalx-musicrate 0.0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-12-16 03:01+0100\n" -"PO-Revision-Date: 2023-12-16 03:02+0100\n" +"POT-Creation-Date: 2023-12-16 03:23+0100\n" +"PO-Revision-Date: 2023-12-16 03:24+0100\n" "Last-Translator: Luca \n" "Language-Team: Luca \n" "Language: de_DE\n" @@ -58,6 +58,10 @@ msgstr "" msgid "Advance Threshold" msgstr "Weiter-Schwellenwert" +#: pretalx_musicrate/models.py:63 +msgid "Link Questions" +msgstr "Fragen zu Links" + #: pretalx_musicrate/signals.py:16 msgid "Collective Rating" msgstr "Anhörtag" @@ -101,19 +105,19 @@ msgstr "Zurück" msgid "Next" msgstr "Weiter" -#: pretalx_musicrate/views.py:40 +#: pretalx_musicrate/views.py:39 msgid "Invalid token" msgstr "Ungültiges Token" -#: pretalx_musicrate/views.py:115 +#: pretalx_musicrate/views.py:114 msgid "The pretalx-musicrate settings were updated." msgstr "Die pretalx-musicrate-Einstellungen wurden gespeichert." -#: pretalx_musicrate/views.py:274 +#: pretalx_musicrate/views.py:273 msgid "Saved!" msgstr "Gespeichert!" -#: pretalx_musicrate/views.py:372 +#: pretalx_musicrate/views.py:375 #, 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/migrations/0006_musicratesettings_link_questions.py b/pretalx_musicrate/migrations/0006_musicratesettings_link_questions.py new file mode 100644 index 0000000..e81bd95 --- /dev/null +++ b/pretalx_musicrate/migrations/0006_musicratesettings_link_questions.py @@ -0,0 +1,24 @@ +# Generated by Django 4.2.8 on 2023-12-16 02:17 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("submission", "0074_created_updated_everywhere"), + ( + "pretalx_musicrate", + "0005_juror_musicratesettings_last_submission_rating_and_more", + ), + ] + + operations = [ + migrations.AddField( + model_name="musicratesettings", + name="link_questions", + field=models.ManyToManyField( + related_name="pretalx_musicrate_settings_links", + to="submission.question", + ), + ), + ] diff --git a/pretalx_musicrate/models.py b/pretalx_musicrate/models.py index 0e537b1..ae52238 100644 --- a/pretalx_musicrate/models.py +++ b/pretalx_musicrate/models.py @@ -57,6 +57,12 @@ class MusicrateSettings(models.Model): related_name="pretalx_musicrate_settings", null=True, ) + link_questions = models.ManyToManyField( + to="submission.Question", + related_name="pretalx_musicrate_settings_links", + verbose_name=_("Link Questions"), + blank=True, + ) class Juror(PretalxModel): diff --git a/pretalx_musicrate/templates/pretalx_musicrate/settings.html b/pretalx_musicrate/templates/pretalx_musicrate/settings.html index db894a6..1c173a9 100644 --- a/pretalx_musicrate/templates/pretalx_musicrate/settings.html +++ b/pretalx_musicrate/templates/pretalx_musicrate/settings.html @@ -12,6 +12,7 @@ {% bootstrap_field form.submission_types layout='event' %} {% bootstrap_field form.genre_question layout='event' %} {% bootstrap_field form.origin_question layout='event' %} + {% bootstrap_field form.link_questions layout='event' %} {% bootstrap_field form.advance_threshold layout='event' %} {% include "orga/includes/submit_row.html" %} diff --git a/pretalx_musicrate/views.py b/pretalx_musicrate/views.py index 208f987..cfe0512 100644 --- a/pretalx_musicrate/views.py +++ b/pretalx_musicrate/views.py @@ -311,6 +311,10 @@ class PresenterView(EventPermissionRequired, SubmissionMixin, TemplateView): urlizer(self.submission.description) urlizer(self.submission.notes) urlizer(self.submission.internal_notes) + for answer in self.submission.answers.filter( + question__in=self.request.event.pretalx_musicrate_settings.link_questions.all() + ).values_list("answer", flat=True): + urlizer(answer) links = [] for url in extractor.urls: if (m := youtube_re.search(url)) is not None: