Compare commits

...

2 Commits

Author SHA1 Message Date
Luca f0caef1cca chore: bump version
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/tag Build is passing Details
2024-02-13 18:40:03 +01:00
Luca f3b5473cd3 feat: add assignee form 2024-02-13 18:39:25 +01:00
5 changed files with 93 additions and 6 deletions

View File

@ -1 +1 @@
__version__ = "0.11.1"
__version__ = "0.12.0"

View File

@ -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"})}

View File

@ -0,0 +1,22 @@
{% extends "orga/base.html" %}
{% load bootstrap4 %}
{% load i18n %}
{% block content %}
<h2>{% blocktranslate with title=submission.title %}Assignee for {{ quotation_open }}{{ title }}{{ quotation_close }}{% endblocktranslate %}</h2>
<form method="post">
{% csrf_token %}
{% bootstrap_form_errors form %}
{% bootstrap_field form.user layout='event' %}
<div class="submit-group panel">
<span></span>
<span>
<button type="submit" class="btn btn-success btn-lg">
<i class="fa fa-check"></i>
{% translate "Save" %}
</button>
</span>
</div>
</form>
{% endblock %}

View File

@ -1,6 +1,7 @@
from django.urls import include, path
from .views import (
AssigneeView,
ExportView,
JoinView,
MayAdvanceView,
@ -12,14 +13,26 @@ from .views import (
urlpatterns = [
path(
"orga/event/<slug:event>/settings/p/pretalx_musicrate/",
"orga/event/<slug:event>/",
include(
[
path("", MusicrateSettingsView.as_view(), name="settings.musicrate"),
path(
"settings/p/pretalx_musicrate/",
MusicrateSettingsView.as_view(),
name="settings.musicrate",
),
path(
"p/pretalx_musicrate/",
include(
[
path("<code>/", AssigneeView.as_view(), name="assignee"),
path("export/", ExportView.as_view(), name="export"),
]
),
),
]
),
),
path(
"<slug:event>/p/pretalx_musicrate/",
include(

View File

@ -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)