Try fixing problem admin glitch
This commit is contained in:
parent
bfe939564b
commit
eb07dd8fa7
2 changed files with 12 additions and 3 deletions
|
@ -370,8 +370,6 @@ class ProblemAdmin(CompareVersionAdmin):
|
||||||
super().save_related(request, form, formsets, change)
|
super().save_related(request, form, formsets, change)
|
||||||
obj = form.instance
|
obj = form.instance
|
||||||
obj.curators.add(request.profile)
|
obj.curators.add(request.profile)
|
||||||
obj.is_organization_private = obj.organizations.count() > 0
|
|
||||||
obj.save()
|
|
||||||
|
|
||||||
if "curators" in form.changed_data or "authors" in form.changed_data:
|
if "curators" in form.changed_data or "authors" in form.changed_data:
|
||||||
del obj.editor_ids
|
del obj.editor_ids
|
||||||
|
|
|
@ -11,6 +11,8 @@ from django.db.models.functions import Coalesce
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.utils.translation import gettext_lazy as _
|
from django.utils.translation import gettext_lazy as _
|
||||||
|
from django.db.models.signals import m2m_changed
|
||||||
|
from django.dispatch import receiver
|
||||||
|
|
||||||
from judge.fulltext import SearchQuerySet
|
from judge.fulltext import SearchQuerySet
|
||||||
from judge.models.pagevote import PageVotable
|
from judge.models.pagevote import PageVotable
|
||||||
|
@ -555,8 +557,9 @@ class Problem(models.Model, PageVotable, Bookmarkable):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
code_changed = self.__original_code and self.code != self.__original_code
|
||||||
super(Problem, self).save(*args, **kwargs)
|
super(Problem, self).save(*args, **kwargs)
|
||||||
if self.__original_code and self.code != self.__original_code:
|
if code_changed:
|
||||||
if hasattr(self, "data_files") or self.pdf_description:
|
if hasattr(self, "data_files") or self.pdf_description:
|
||||||
try:
|
try:
|
||||||
problem_data_storage.rename(self.__original_code, self.code)
|
problem_data_storage.rename(self.__original_code, self.code)
|
||||||
|
@ -567,6 +570,7 @@ class Problem(models.Model, PageVotable, Bookmarkable):
|
||||||
self.pdf_description.name = problem_directory_file_helper(
|
self.pdf_description.name = problem_directory_file_helper(
|
||||||
self.code, self.pdf_description.name
|
self.code, self.pdf_description.name
|
||||||
)
|
)
|
||||||
|
super().save(update_fields=["pdf_description"])
|
||||||
if hasattr(self, "data_files"):
|
if hasattr(self, "data_files"):
|
||||||
self.data_files._update_code(self.__original_code, self.code)
|
self.data_files._update_code(self.__original_code, self.code)
|
||||||
|
|
||||||
|
@ -719,3 +723,10 @@ class ProblemPointsVote(models.Model):
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return f"{self.voter}: {self.points} for {self.problem.code}"
|
return f"{self.voter}: {self.points} for {self.problem.code}"
|
||||||
|
|
||||||
|
|
||||||
|
@receiver(m2m_changed, sender=Problem.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"])
|
||||||
|
|
Loading…
Reference in a new issue