fix: find new last submission if current one is not 'submitted'
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
660650c8da
commit
dcce8e5407
|
@ -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,15 +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(),
|
|
||||||
state=SubmissionStates.SUBMITTED,
|
|
||||||
)
|
|
||||||
.order_by("created")
|
|
||||||
.first()
|
|
||||||
)
|
)
|
||||||
if submission is not None:
|
if submission is not None:
|
||||||
return redirect(
|
return redirect(
|
||||||
|
@ -84,15 +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(),
|
|
||||||
state=SubmissionStates.SUBMITTED,
|
|
||||||
)
|
|
||||||
.order_by("created")
|
|
||||||
.first()
|
|
||||||
)
|
)
|
||||||
if submission is not None:
|
if submission is not None:
|
||||||
return redirect(
|
return redirect(
|
||||||
|
@ -142,14 +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(),
|
|
||||||
state=SubmissionStates.SUBMITTED,
|
|
||||||
)
|
|
||||||
.order_by("created")
|
|
||||||
.first()
|
|
||||||
)
|
)
|
||||||
return context
|
return context
|
||||||
|
|
||||||
|
@ -288,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)
|
||||||
|
|
||||||
|
|
||||||
|
@ -357,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
|
||||||
|
|
Loading…
Reference in New Issue