feat(settings): limit applicable session types
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
5ade964ac0
commit
a8ba987102
|
@ -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,
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
]
|
|
@ -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,
|
||||
)
|
||||
|
|
|
@ -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 %}
|
Loading…
Reference in New Issue