feat(settings): limit applicable session types
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Luca 2023-12-14 19:40:14 +01:00
parent 5ade964ac0
commit a8ba987102
5 changed files with 80 additions and 3 deletions

View File

@ -1,3 +1,5 @@
from django import forms
from django_scopes.forms import SafeModelMultipleChoiceField
from i18nfield.forms import I18nModelForm from i18nfield.forms import I18nModelForm
from .models import MusicrateSettings from .models import MusicrateSettings
@ -7,8 +9,17 @@ class MusicrateSettingsForm(I18nModelForm):
def __init__(self, *args, event=None, **kwargs): def __init__(self, *args, event=None, **kwargs):
self.instance, _ = MusicrateSettings.objects.get_or_create(event=event) self.instance, _ = MusicrateSettings.objects.get_or_create(event=event)
super().__init__(*args, **kwargs, instance=self.instance, locales=event.locales) 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: class Meta:
model = MusicrateSettings model = MusicrateSettings
fields = ("some_setting",) fields = ("submission_types",)
widgets = {} widgets = {
"submission_types": forms.SelectMultiple(attrs={"class": "select2"}),
}
field_classes = {
"submission_types": SafeModelMultipleChoiceField,
}

View File

@ -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",
),
),
],
),
]

View File

View File

@ -1,4 +1,5 @@
from django.db import models from django.db import models
from django.utils.translation import gettext_lazy as _
class MusicrateSettings(models.Model): class MusicrateSettings(models.Model):
@ -7,4 +8,12 @@ class MusicrateSettings(models.Model):
on_delete=models.CASCADE, on_delete=models.CASCADE,
related_name="pretalx_musicrate_settings", 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,
)

View File

@ -0,0 +1,15 @@
{% extends "orga/base.html" %}
{% load bootstrap4 %}
{% load compress %}
{% load i18n %}
{% load static %}
{% block content %}
<h2>{% translate "pretalx-musicrate settings" %}</h2>
<form method="post">
{% csrf_token %}
{% bootstrap_form_errors form %}
{% bootstrap_field form.submission_types layout='event' %}
{% include "orga/includes/submit_row.html" %}
</form>
{% endblock %}