diff --git a/pretalx_musicrate/forms.py b/pretalx_musicrate/forms.py index b3f75d4..c6687fb 100644 --- a/pretalx_musicrate/forms.py +++ b/pretalx_musicrate/forms.py @@ -1,8 +1,9 @@ from django import forms from django_scopes.forms import SafeModelChoiceField, SafeModelMultipleChoiceField from i18nfield.forms import I18nModelForm +from pretalx.person.models import User -from .models import MusicrateSettings, Rating +from .models import Assignee, MusicrateSettings, Rating class MusicrateSettingsForm(I18nModelForm): @@ -56,3 +57,23 @@ class RatingForm(forms.ModelForm): class Meta: model = Rating fields = ("rating",) + + +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"})} diff --git a/pretalx_musicrate/templates/pretalx_musicrate/assignee.html b/pretalx_musicrate/templates/pretalx_musicrate/assignee.html new file mode 100644 index 0000000..aa1bcec --- /dev/null +++ b/pretalx_musicrate/templates/pretalx_musicrate/assignee.html @@ -0,0 +1,22 @@ +{% extends "orga/base.html" %} +{% load bootstrap4 %} +{% load i18n %} + +{% block content %} +
/", AssigneeView.as_view(), name="assignee"),
+ path("export/", ExportView.as_view(), name="export"),
+ ]
+ ),
+ ),
]
),
),
diff --git a/pretalx_musicrate/views.py b/pretalx_musicrate/views.py
index c6eff9d..e94a88e 100644
--- a/pretalx_musicrate/views.py
+++ b/pretalx_musicrate/views.py
@@ -15,8 +15,9 @@ from django.views.generic import FormView, TemplateView, View
from django.views.generic.detail import SingleObjectMixin
from django_context_decorator import context
from pretalx.common.mixins.views import EventPermissionRequired
+from pretalx.submission.models import Submission
-from .forms import MusicrateSettingsForm, RatingForm
+from .forms import AssigneeForm, MusicrateSettingsForm, RatingForm
from .models import Juror, Rating
youtube_re = re.compile(
@@ -439,3 +440,33 @@ class ExportView(EventPermissionRequired, View):
]
)
return response
+
+
+class AssigneeView(EventPermissionRequired, FormView, SingleObjectMixin):
+ form_class = AssigneeForm
+ model = Submission
+ permission_required = "orga.change_submissions"
+ slug_field = "code"
+ slug_url_kwarg = "code"
+ template_name = "pretalx_musicrate/assignee.html"
+
+ def get_form_kwargs(self):
+ kwargs = super().get_form_kwargs()
+ kwargs["submission"] = self.object
+ return kwargs
+
+ def get_success_url(self):
+ return self.request.path
+
+ def form_valid(self, form):
+ form.save()
+ messages.success(self.request, _("Saved!"))
+ return super().form_valid(form)
+
+ def get(self, *args, **kwargs):
+ self.object = self.get_object()
+ return super().get(*args, **kwargs)
+
+ def post(self, *args, **kwargs):
+ self.object = self.get_object()
+ return super().post(*args, **kwargs)