Compare commits

...

2 Commits

Author SHA1 Message Date
Luca dcce8e5407 fix: find new last submission if current one is not 'submitted'
continuous-integration/drone/push Build is passing Details
2024-12-07 20:36:15 +01:00
Luca 660650c8da feat: include only 'submitted' submissions in rating 2024-12-07 19:34:29 +01:00
2 changed files with 50 additions and 36 deletions

View File

@ -1 +1 @@
__version__ = "2025.1.0" __version__ = "2025.2.0.dev0"

View File

@ -16,7 +16,7 @@ from django.views.generic.detail import SingleObjectMixin
from django_context_decorator import context from django_context_decorator import context
from pretalx.common.views.mixins import EventPermissionRequired from pretalx.common.views.mixins import EventPermissionRequired
from pretalx.orga.views.submission import BaseSubmissionList, SubmissionList from pretalx.orga.views.submission import BaseSubmissionList, SubmissionList
from pretalx.submission.models import Submission from pretalx.submission.models import Submission, SubmissionStates
from .forms import ( from .forms import (
AssigneeForm, AssigneeForm,
@ -31,6 +31,25 @@ youtube_re = re.compile(
) )
def get_last_submission(settings, submissions, submission=None):
if submission is not None and submission.state != SubmissionStates.SUBMITTED:
submission = None
submission = submission or settings.last_submission
if submission is not None and submission.state != SubmissionStates.SUBMITTED:
submission = None
return (
submission
or submissions.filter(
submission_type__in=settings.submission_types.all(),
state=SubmissionStates.SUBMITTED,
)
.order_by("created")
.first()
)
class JoinView(TemplateView): class JoinView(TemplateView):
template_name = "pretalx_musicrate/join.html" template_name = "pretalx_musicrate/join.html"
@ -57,14 +76,10 @@ class JoinView(TemplateView):
def get(self, request, *args, token, **kwargs): def get(self, request, *args, token, **kwargs):
token_valid = self.validate_token(token) token_valid = self.validate_token(token)
if self.juror is not None: if self.juror is not None:
submission = ( submission = get_last_submission(
self.juror.last_submission self.request.event.pretalx_musicrate_settings,
or self.request.event.pretalx_musicrate_settings.last_submission self.request.event.submissions,
or self.request.event.submissions.filter( self.juror.last_submission,
submission_type__in=self.request.event.pretalx_musicrate_settings.submission_types.all()
)
.order_by("created")
.first()
) )
if submission is not None: if submission is not None:
return redirect( return redirect(
@ -83,14 +98,10 @@ class JoinView(TemplateView):
event=self.request.event, event=self.request.event,
last_submission=self.request.event.pretalx_musicrate_settings.last_submission, last_submission=self.request.event.pretalx_musicrate_settings.last_submission,
) )
submission = ( submission = get_last_submission(
self.juror.last_submission self.request.event.pretalx_musicrate_settings,
or self.request.event.pretalx_musicrate_settings.last_submission self.request.event.submissions,
or self.request.event.submissions.filter( self.juror.last_submission,
submission_type__in=self.request.event.pretalx_musicrate_settings.submission_types.all()
)
.order_by("created")
.first()
) )
if submission is not None: if submission is not None:
return redirect( return redirect(
@ -140,13 +151,9 @@ class QRCodeView(EventPermissionRequired, TemplateView):
}, },
) )
) )
context["last_submission"] = ( context["last_submission"] = get_last_submission(
self.request.event.pretalx_musicrate_settings.last_submission self.request.event.pretalx_musicrate_settings,
or self.request.event.submissions.filter( self.request.event.submissions,
submission_type__in=self.request.event.pretalx_musicrate_settings.submission_types.all()
)
.order_by("created")
.first()
) )
return context return context
@ -157,7 +164,8 @@ class SubmissionMixin(SingleObjectMixin):
def get_queryset(self): def get_queryset(self):
return self.request.event.submissions.prefetch_related("answers").filter( return self.request.event.submissions.prefetch_related("answers").filter(
submission_type__in=self.request.event.pretalx_musicrate_settings.submission_types.all() submission_type__in=self.request.event.pretalx_musicrate_settings.submission_types.all(),
state=SubmissionStates.SUBMITTED,
) )
@context @context
@ -284,17 +292,22 @@ class RatingView(FormView, SubmissionMixin):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
self.object = self.get_object() self.object = self.get_object()
last_submission = get_last_submission(
self.request.event.pretalx_musicrate_settings,
self.request.event.submissions,
)
if ( if (
(settings := self.request.event.pretalx_musicrate_settings).last_submission last_submission is not None
is not None and self.object.created > last_submission.created
and self.object.created > settings.last_submission.created
): ):
return redirect( return redirect(
self.request.resolver_match.view_name, self.request.resolver_match.view_name,
event=self.request.event.slug, event=self.request.event.slug,
token=self.juror.token, token=self.juror.token,
code=settings.last_submission.code, code=last_submission.code,
) )
return super().get(request, *args, **kwargs) return super().get(request, *args, **kwargs)
@ -353,16 +366,16 @@ class PresenterView(EventPermissionRequired, SubmissionMixin, TemplateView):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
self.object = self.get_object() self.object = self.get_object()
if (
(settings := self.request.event.pretalx_musicrate_settings).last_submission settings = self.request.event.pretalx_musicrate_settings
is None last_submission = get_last_submission(settings, self.request.event.submissions)
or self.object.created > settings.last_submission.created if last_submission is None or self.object.created > last_submission.created:
):
try: try:
settings.last_submission = self.object settings.last_submission = self.object
settings.save() settings.save()
except Exception: except Exception:
pass pass
response = super().get(request, *args, **kwargs) response = super().get(request, *args, **kwargs)
response._csp_update = {"frame-src": "https://www.youtube-nocookie.com"} response._csp_update = {"frame-src": "https://www.youtube-nocookie.com"}
return response return response
@ -410,7 +423,8 @@ class ExportView(EventPermissionRequired, View):
request.event.submissions.prefetch_related("answers") request.event.submissions.prefetch_related("answers")
.select_related("submission_type") .select_related("submission_type")
.filter( .filter(
submission_type__in=request.event.pretalx_musicrate_settings.submission_types.all() submission_type__in=request.event.pretalx_musicrate_settings.submission_types.all(),
state=SubmissionStates.SUBMITTED,
) )
.only("title", "submission_type__name") .only("title", "submission_type__name")
.order_by("created") .order_by("created")