From f04e114062148f7e7e7f679e0d5e1988d29dcfda Mon Sep 17 00:00:00 2001 From: Luca Date: Fri, 15 Dec 2023 00:06:53 +0100 Subject: [PATCH] feat(settings): add genre and origin questions --- pretalx_musicrate/forms.py | 18 ++++++++-- ...sicratesettings_genre_question_and_more.py | 34 +++++++++++++++++++ pretalx_musicrate/models.py | 16 +++++++++ .../templates/pretalx_musicrate/settings.html | 2 ++ 4 files changed, 68 insertions(+), 2 deletions(-) create mode 100644 pretalx_musicrate/migrations/0002_musicratesettings_genre_question_and_more.py diff --git a/pretalx_musicrate/forms.py b/pretalx_musicrate/forms.py index da304d4..a550d84 100644 --- a/pretalx_musicrate/forms.py +++ b/pretalx_musicrate/forms.py @@ -1,5 +1,5 @@ from django import forms -from django_scopes.forms import SafeModelMultipleChoiceField +from django_scopes.forms import SafeModelChoiceField, SafeModelMultipleChoiceField from i18nfield.forms import I18nModelForm from .models import MusicrateSettings @@ -13,13 +13,27 @@ class MusicrateSettingsForm(I18nModelForm): self.fields.pop("submission_types") else: self.fields["submission_types"].queryset = event.submission_types.all() + self.fields["genre_question"].queryset = ( + event.questions.exclude(pk=self.instance.origin_question.pk) + if self.instance.origin_question + else event.questions.all() + ) + self.fields["origin_question"].queryset = ( + event.questions.exclude(pk=self.instance.genre_question.pk) + if self.instance.genre_question + else event.questions.all() + ) class Meta: model = MusicrateSettings - fields = ("submission_types",) + fields = ("submission_types", "genre_question", "origin_question") widgets = { "submission_types": forms.SelectMultiple(attrs={"class": "select2"}), + "genre_question": forms.Select(attrs={"class": "select2"}), + "origin_question": forms.Select(attrs={"class": "select2"}), } field_classes = { "submission_types": SafeModelMultipleChoiceField, + "genre_question": SafeModelChoiceField, + "origin_question": SafeModelChoiceField, } diff --git a/pretalx_musicrate/migrations/0002_musicratesettings_genre_question_and_more.py b/pretalx_musicrate/migrations/0002_musicratesettings_genre_question_and_more.py new file mode 100644 index 0000000..c93be40 --- /dev/null +++ b/pretalx_musicrate/migrations/0002_musicratesettings_genre_question_and_more.py @@ -0,0 +1,34 @@ +# Generated by Django 4.2.8 on 2023-12-14 22:47 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("submission", "0074_created_updated_everywhere"), + ("pretalx_musicrate", "0001_initial"), + ] + + operations = [ + migrations.AddField( + model_name="musicratesettings", + name="genre_question", + field=models.OneToOneField( + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="pretalx_musicrate_settings_genre", + to="submission.question", + ), + ), + migrations.AddField( + model_name="musicratesettings", + name="origin_question", + field=models.OneToOneField( + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="pretalx_musicrate_settings_origin", + to="submission.question", + ), + ), + ] diff --git a/pretalx_musicrate/models.py b/pretalx_musicrate/models.py index 93cce02..fc0e771 100644 --- a/pretalx_musicrate/models.py +++ b/pretalx_musicrate/models.py @@ -17,3 +17,19 @@ class MusicrateSettings(models.Model): verbose_name=_("Session Types"), blank=True, ) + genre_question = models.OneToOneField( + to="submission.Question", + on_delete=models.SET_NULL, + related_name="pretalx_musicrate_settings_genre", + verbose_name=_("Genre Question"), + blank=True, + null=True, + ) + origin_question = models.OneToOneField( + to="submission.Question", + on_delete=models.SET_NULL, + related_name="pretalx_musicrate_settings_origin", + verbose_name=_("Origin Question"), + blank=True, + null=True, + ) diff --git a/pretalx_musicrate/templates/pretalx_musicrate/settings.html b/pretalx_musicrate/templates/pretalx_musicrate/settings.html index 3033fb2..196debd 100644 --- a/pretalx_musicrate/templates/pretalx_musicrate/settings.html +++ b/pretalx_musicrate/templates/pretalx_musicrate/settings.html @@ -10,6 +10,8 @@ {% csrf_token %} {% bootstrap_form_errors form %} {% bootstrap_field form.submission_types layout='event' %} + {% bootstrap_field form.genre_question layout='event' %} + {% bootstrap_field form.origin_question layout='event' %} {% include "orga/includes/submit_row.html" %} {% endblock %}