2023-12-14 19:40:14 +01:00
|
|
|
from django import forms
|
|
|
|
from django_scopes.forms import SafeModelMultipleChoiceField
|
2023-12-13 23:58:00 +01:00
|
|
|
from i18nfield.forms import I18nModelForm
|
|
|
|
|
|
|
|
from .models import MusicrateSettings
|
|
|
|
|
|
|
|
|
|
|
|
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-13 23:58:00 +01:00
|
|
|
|
|
|
|
class Meta:
|
|
|
|
model = MusicrateSettings
|
2023-12-14 19:40:14 +01:00
|
|
|
fields = ("submission_types",)
|
|
|
|
widgets = {
|
|
|
|
"submission_types": forms.SelectMultiple(attrs={"class": "select2"}),
|
|
|
|
}
|
|
|
|
field_classes = {
|
|
|
|
"submission_types": SafeModelMultipleChoiceField,
|
|
|
|
}
|