From a78f1db5e634e8402ef68e9fb3dcf1592c626c64 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Sat, 28 May 2022 03:54:12 -0500 Subject: [PATCH] Make admin a little smarter --- judge/admin/contest.py | 4 ++++ judge/admin/organization.py | 5 +++++ judge/models/profile.py | 4 ---- templates/top-users.html | 2 +- 4 files changed, 10 insertions(+), 5 deletions(-) diff --git a/judge/admin/contest.py b/judge/admin/contest.py index c9581fb..33767de 100644 --- a/judge/admin/contest.py +++ b/judge/admin/contest.py @@ -288,6 +288,10 @@ class ContestAdmin(CompareVersionAdmin): # 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): 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): if not request.user.has_perm("judge.edit_own_contest"): diff --git a/judge/admin/organization.py b/judge/admin/organization.py index 64a4da0..0c5f148 100644 --- a/judge/admin/organization.py +++ b/judge/admin/organization.py @@ -81,6 +81,11 @@ class OrganizationAdmin(VersionAdmin): return True return obj.admins.filter(id=request.profile.id).exists() + def save_related(self, request, form, formsets, change): + super().save_related(request, form, formsets, change) + obj = form.instance + obj.members.add(*obj.admins.all()) + class OrganizationRequestAdmin(admin.ModelAdmin): list_display = ("username", "organization", "state", "time") diff --git a/judge/models/profile.py b/judge/models/profile.py index 251101d..fe8ce17 100644 --- a/judge/models/profile.py +++ b/judge/models/profile.py @@ -112,10 +112,6 @@ class Organization(models.Model): def get_contests_url(self): return reverse("organization_contests", args=(self.id, self.slug)) - def save(self, *args, **kwargs): - self.members.add(*self.admins.all()) - super(Organization, self).save(*args, **kwargs) - class Meta: ordering = ["name"] permissions = ( diff --git a/templates/top-users.html b/templates/top-users.html index 23e2f10..e7abb32 100644 --- a/templates/top-users.html +++ b/templates/top-users.html @@ -8,7 +8,7 @@ {{loop.index}} {{link_user(user)}} - {{user.rating}} + {{user.rating or '_'}} {% endfor %}