Fix group contest m2m fields (authors, curators, etc)

This commit is contained in:
cuom1999 2023-10-27 16:49:28 -05:00
parent 93d032fc72
commit 27586b25b8
6 changed files with 271 additions and 260 deletions

View file

@ -419,7 +419,14 @@ class ContestDetail(
return []
res = []
for organization in self.object.organizations.all():
can_edit = False
if self.request.profile.can_edit_organization(organization):
can_edit = True
if self.request.profile in organization and self.object.is_editable_by(
self.request.user
):
can_edit = True
if can_edit:
res.append(organization)
return res

View file

@ -73,6 +73,7 @@ from judge.views.problem import ProblemList
from judge.views.contests import ContestList
from judge.views.submission import AllSubmissions, SubmissionsListBase
from judge.views.feed import FeedView
from judge.tasks import rescore_contest
__all__ = [
"OrganizationList",
@ -394,7 +395,7 @@ class OrganizationContestMixin(
model = Contest
def is_contest_editable(self, request, contest):
return request.profile in contest.authors.all() or self.can_edit_organization(
return contest.is_editable_by(request.user) or self.can_edit_organization(
self.organization
)
@ -947,7 +948,7 @@ class EditOrganizationContest(
def get_content_title(self):
href = reverse("contest_view", args=[self.contest.key])
return mark_safe(f'Edit <a href="{href}">{self.contest.key}</a>')
return mark_safe(_("Edit") + f' <a href="{href}">{self.contest.key}</a>')
def get_object(self):
return self.contest
@ -960,6 +961,19 @@ class EditOrganizationContest(
self.object.organizations.add(self.organization)
self.object.is_organization_private = True
self.object.save()
if any(
f in form.changed_data
for f in (
"start_time",
"end_time",
"time_limit",
"format_config",
"format_name",
"freeze_after",
)
):
transaction.on_commit(rescore_contest.s(self.object.key).delay)
return res
def get_problem_formset(self, post=False):