Fix inconsistency of contest is_organization_private
This commit is contained in:
parent
9270a017d3
commit
4ee2e1b940
2 changed files with 17 additions and 4 deletions
|
@ -316,10 +316,6 @@ class ContestAdmin(CompareVersionAdmin):
|
||||||
# Only rescored if we did not already do so in `save_model`
|
# Only rescored if we did not already do so in `save_model`
|
||||||
if not self._rescored and any(formset.has_changed() for formset in formsets):
|
if not self._rescored and any(formset.has_changed() for formset in formsets):
|
||||||
self._rescore(form.cleaned_data["key"])
|
self._rescore(form.cleaned_data["key"])
|
||||||
obj = form.instance
|
|
||||||
obj.is_organization_private = obj.organizations.count() > 0
|
|
||||||
obj.is_private = obj.private_contestants.count() > 0
|
|
||||||
obj.save()
|
|
||||||
|
|
||||||
def has_change_permission(self, request, obj=None):
|
def has_change_permission(self, request, obj=None):
|
||||||
if not request.user.has_perm("judge.edit_own_contest"):
|
if not request.user.has_perm("judge.edit_own_contest"):
|
||||||
|
|
|
@ -2,11 +2,14 @@ from django.core.exceptions import ValidationError
|
||||||
from django.core.validators import MaxValueValidator, MinValueValidator, RegexValidator
|
from django.core.validators import MaxValueValidator, MinValueValidator, RegexValidator
|
||||||
from django.db import models, transaction
|
from django.db import models, transaction
|
||||||
from django.db.models import CASCADE, Q
|
from django.db.models import CASCADE, Q
|
||||||
|
from django.db.models.signals import m2m_changed
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.utils.translation import gettext, gettext_lazy as _
|
from django.utils.translation import gettext, gettext_lazy as _
|
||||||
from django.contrib.contenttypes.fields import GenericRelation
|
from django.contrib.contenttypes.fields import GenericRelation
|
||||||
|
from django.dispatch import receiver
|
||||||
|
|
||||||
from jsonfield import JSONField
|
from jsonfield import JSONField
|
||||||
from lupa import LuaRuntime
|
from lupa import LuaRuntime
|
||||||
from moss import (
|
from moss import (
|
||||||
|
@ -658,6 +661,20 @@ class Contest(models.Model, PageVotable, Bookmarkable):
|
||||||
verbose_name_plural = _("contests")
|
verbose_name_plural = _("contests")
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(m2m_changed, sender=Contest.organizations.through)
|
||||||
|
def update_organization_private(sender, instance, **kwargs):
|
||||||
|
if kwargs["action"] in ["post_add", "post_remove", "post_clear"]:
|
||||||
|
instance.is_organization_private = instance.organizations.exists()
|
||||||
|
instance.save(update_fields=["is_organization_private"])
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(m2m_changed, sender=Contest.private_contestants.through)
|
||||||
|
def update_private(sender, instance, **kwargs):
|
||||||
|
if kwargs["action"] in ["post_add", "post_remove", "post_clear"]:
|
||||||
|
instance.is_private = instance.private_contestants.exists()
|
||||||
|
instance.save(update_fields=["is_private"])
|
||||||
|
|
||||||
|
|
||||||
class ContestParticipation(models.Model):
|
class ContestParticipation(models.Model):
|
||||||
LIVE = 0
|
LIVE = 0
|
||||||
SPECTATE = -1
|
SPECTATE = -1
|
||||||
|
|
Loading…
Reference in a new issue