diff --git a/pretalx_musicrate/forms.py b/pretalx_musicrate/forms.py index b263baa..da304d4 100644 --- a/pretalx_musicrate/forms.py +++ b/pretalx_musicrate/forms.py @@ -1,3 +1,5 @@ +from django import forms +from django_scopes.forms import SafeModelMultipleChoiceField from i18nfield.forms import I18nModelForm from .models import MusicrateSettings @@ -7,8 +9,17 @@ class MusicrateSettingsForm(I18nModelForm): def __init__(self, *args, event=None, **kwargs): self.instance, _ = MusicrateSettings.objects.get_or_create(event=event) super().__init__(*args, **kwargs, instance=self.instance, locales=event.locales) + if not event.submission_types.count(): + self.fields.pop("submission_types") + else: + self.fields["submission_types"].queryset = event.submission_types.all() class Meta: model = MusicrateSettings - fields = ("some_setting",) - widgets = {} + fields = ("submission_types",) + widgets = { + "submission_types": forms.SelectMultiple(attrs={"class": "select2"}), + } + field_classes = { + "submission_types": SafeModelMultipleChoiceField, + } diff --git a/pretalx_musicrate/migrations/0001_initial.py b/pretalx_musicrate/migrations/0001_initial.py new file mode 100644 index 0000000..2314e2d --- /dev/null +++ b/pretalx_musicrate/migrations/0001_initial.py @@ -0,0 +1,42 @@ +# Generated by Django 4.2.8 on 2023-12-14 18:32 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + initial = True + + dependencies = [ + ("submission", "0074_created_updated_everywhere"), + ("event", "0035_created_updated_everywhere"), + ] + + operations = [ + migrations.CreateModel( + name="MusicrateSettings", + fields=[ + ( + "id", + models.AutoField( + auto_created=True, primary_key=True, serialize=False + ), + ), + ( + "event", + models.OneToOneField( + on_delete=django.db.models.deletion.CASCADE, + related_name="pretalx_musicrate_settings", + to="event.event", + ), + ), + ( + "submission_types", + models.ManyToManyField( + related_name="pretalx_musicrate_settings", + to="submission.submissiontype", + ), + ), + ], + ), + ] diff --git a/pretalx_musicrate/migrations/__init__.py b/pretalx_musicrate/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pretalx_musicrate/models.py b/pretalx_musicrate/models.py index 387223e..93cce02 100644 --- a/pretalx_musicrate/models.py +++ b/pretalx_musicrate/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.utils.translation import gettext_lazy as _ class MusicrateSettings(models.Model): @@ -7,4 +8,12 @@ class MusicrateSettings(models.Model): on_delete=models.CASCADE, related_name="pretalx_musicrate_settings", ) - some_setting = models.CharField(max_length=10, default="A") + submission_types = models.ManyToManyField( + to="submission.SubmissionType", + related_name="pretalx_musicrate_settings", + help_text=_( + "You can limit pretalx-musicrate to some session types. Leave this field empty to rate all session types." + ), + verbose_name=_("Session Types"), + blank=True, + ) diff --git a/pretalx_musicrate/templates/pretalx_musicrate/settings.html b/pretalx_musicrate/templates/pretalx_musicrate/settings.html new file mode 100644 index 0000000..3033fb2 --- /dev/null +++ b/pretalx_musicrate/templates/pretalx_musicrate/settings.html @@ -0,0 +1,15 @@ +{% extends "orga/base.html" %} +{% load bootstrap4 %} +{% load compress %} +{% load i18n %} +{% load static %} + +{% block content %} +