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

@ -11,7 +11,6 @@ from django.contrib.auth.models import User
from django.contrib.auth.forms import AuthenticationForm
from django.core.exceptions import ValidationError, ObjectDoesNotExist
from django.core.validators import RegexValidator
from django.db import transaction
from django.db.models import Q
from django.forms import (
CharField,
@ -52,7 +51,6 @@ from judge.widgets import (
DateTimePickerWidget,
ImageWidget,
)
from judge.tasks import rescore_contest
def fix_unicode(string, unsafe=tuple("\u202a\u202b\u202d\u202e")):
@ -282,16 +280,9 @@ class EditOrganizationContestForm(ModelForm):
"view_contest_scoreboard",
]:
self.fields[field].widget.data_url = (
self.fields[field].widget.get_url() + "?org_id=1"
self.fields[field].widget.get_url() + f"?org_id={self.org_id}"
)
def save(self, commit=True):
res = super(EditOrganizationContestForm, self).save(commit=False)
if commit:
res.save()
transaction.on_commit(rescore_contest.s(res.key).delay)
return res
class Meta:
model = Contest
fields = (

View file

@ -99,11 +99,13 @@ class Contest(models.Model, PageVotable, Bookmarkable):
)
authors = models.ManyToManyField(
Profile,
verbose_name=_("authors"),
help_text=_("These users will be able to edit the contest."),
related_name="authors+",
)
curators = models.ManyToManyField(
Profile,
verbose_name=_("curators"),
help_text=_(
"These users will be able to edit the contest, "
"but will not be listed as authors."
@ -113,6 +115,7 @@ class Contest(models.Model, PageVotable, Bookmarkable):
)
testers = models.ManyToManyField(
Profile,
verbose_name=_("testers"),
help_text=_(
"These users will be able to view the contest, " "but not edit it."
),

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

File diff suppressed because it is too large Load diff

View file

@ -29,12 +29,6 @@
height: 2em;
padding-top: 4px;
}
@media(min-width: 800px) {
#content {
width: 99%;
margin-left: 0;
}
}
@media(max-width: 799px) {
#content {
width: 100%;