2023-12-14 19:40:14 +01:00
|
|
|
from django import forms
|
2024-02-14 00:54:28 +01:00
|
|
|
from django.utils.translation import gettext_lazy as _
|
2023-12-15 00:06:53 +01:00
|
|
|
from django_scopes.forms import SafeModelChoiceField, SafeModelMultipleChoiceField
|
2023-12-13 23:58:00 +01:00
|
|
|
from i18nfield.forms import I18nModelForm
|
2024-02-13 18:39:25 +01:00
|
|
|
from pretalx.person.models import User
|
2024-02-14 00:54:28 +01:00
|
|
|
from pretalx.submission.forms import SubmissionFilterForm
|
2023-12-13 23:58:00 +01:00
|
|
|
|
2024-02-13 18:39:25 +01:00
|
|
|
from .models import Assignee, MusicrateSettings, Rating
|
2023-12-13 23:58:00 +01:00
|
|
|
|
|
|
|
|
|
|
|
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)
|
2023-12-14 19:40:14 +01:00
|
|
|
if not event.submission_types.count():
|
|
|
|
self.fields.pop("submission_types")
|
|
|
|
else:
|
|
|
|
self.fields["submission_types"].queryset = event.submission_types.all()
|
2023-12-15 00:06:53 +01:00
|
|
|
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()
|
|
|
|
)
|
2023-12-16 03:29:52 +01:00
|
|
|
self.fields["link_questions"].queryset = event.questions.all()
|
2023-12-13 23:58:00 +01:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = MusicrateSettings
|
2023-12-15 18:14:33 +01:00
|
|
|
fields = (
|
|
|
|
"submission_types",
|
|
|
|
"genre_question",
|
|
|
|
"origin_question",
|
2023-12-16 03:29:52 +01:00
|
|
|
"link_questions",
|
2023-12-15 18:14:33 +01:00
|
|
|
"advance_threshold",
|
|
|
|
)
|
2023-12-14 19:40:14 +01:00
|
|
|
widgets = {
|
|
|
|
"submission_types": forms.SelectMultiple(attrs={"class": "select2"}),
|
2023-12-15 00:06:53 +01:00
|
|
|
"genre_question": forms.Select(attrs={"class": "select2"}),
|
|
|
|
"origin_question": forms.Select(attrs={"class": "select2"}),
|
2023-12-16 03:29:52 +01:00
|
|
|
"link_questions": forms.SelectMultiple(attrs={"class": "select2"}),
|
2023-12-14 19:40:14 +01:00
|
|
|
}
|
|
|
|
field_classes = {
|
|
|
|
"submission_types": SafeModelMultipleChoiceField,
|
2023-12-15 00:06:53 +01:00
|
|
|
"genre_question": SafeModelChoiceField,
|
|
|
|
"origin_question": SafeModelChoiceField,
|
2023-12-16 03:29:52 +01:00
|
|
|
"link_questions": SafeModelMultipleChoiceField,
|
2023-12-14 19:40:14 +01:00
|
|
|
}
|
2023-12-16 01:05:05 +01:00
|
|
|
|
|
|
|
|
|
|
|
class RatingForm(forms.ModelForm):
|
|
|
|
rating = forms.ChoiceField(
|
|
|
|
choices=Rating.RATING_CHOICES, required=False, widget=forms.RadioSelect
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Rating
|
|
|
|
fields = ("rating",)
|
2024-02-13 18:39:25 +01:00
|
|
|
|
|
|
|
|
|
|
|
class AssigneeForm(forms.ModelForm):
|
|
|
|
def __init__(self, *args, submission=None, **kwargs):
|
|
|
|
try:
|
|
|
|
self.instance = Assignee.objects.get(submission=submission)
|
|
|
|
except Assignee.DoesNotExist:
|
|
|
|
self.instance = Assignee(submission=submission)
|
|
|
|
super().__init__(*args, instance=self.instance, **kwargs)
|
|
|
|
self.fields["user"].queryset = User.objects.none().union(
|
|
|
|
*(
|
|
|
|
t.members.all()
|
|
|
|
for t in submission.event.teams.filter(can_change_submissions=True)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = Assignee
|
|
|
|
fields = ("user",)
|
|
|
|
widgets = {"user": forms.Select(attrs={"class": "select2"})}
|
2024-02-14 00:54:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
class EnhancedSubmissionFilterForm(SubmissionFilterForm):
|
|
|
|
require_all_tags = forms.BooleanField(required=False, label=_("require all"))
|
2024-02-16 19:11:14 +01:00
|
|
|
|
|
|
|
def filter_queryset(self, qs):
|
|
|
|
qs = super().filter_queryset(qs)
|
|
|
|
if self.cleaned_data.get("require_all_tags"):
|
|
|
|
for tag in self.cleaned_data.get("tags"):
|
|
|
|
qs = qs.filter(tags__in=[tag])
|
|
|
|
return qs
|