Update admin page
This commit is contained in:
parent
737cd8a068
commit
ba75b5c086
4 changed files with 44 additions and 5 deletions
|
@ -192,9 +192,7 @@ class ContestAdmin(CompareVersionAdmin):
|
|||
{
|
||||
"fields": (
|
||||
"access_code",
|
||||
"is_private",
|
||||
"private_contestants",
|
||||
"is_organization_private",
|
||||
"organizations",
|
||||
"view_contest_scoreboard",
|
||||
)
|
||||
|
|
|
@ -24,6 +24,7 @@ from judge.models import (
|
|||
ProblemTranslation,
|
||||
Profile,
|
||||
Solution,
|
||||
Notification,
|
||||
)
|
||||
from judge.widgets import (
|
||||
AdminHeavySelect2MultipleWidget,
|
||||
|
@ -214,12 +215,11 @@ class ProblemAdmin(CompareVersionAdmin):
|
|||
"code",
|
||||
"name",
|
||||
"is_public",
|
||||
"organizations",
|
||||
"date",
|
||||
"authors",
|
||||
"curators",
|
||||
"testers",
|
||||
"is_organization_private",
|
||||
"organizations",
|
||||
"description",
|
||||
"pdf_description",
|
||||
"license",
|
||||
|
@ -370,6 +370,7 @@ class ProblemAdmin(CompareVersionAdmin):
|
|||
return form
|
||||
|
||||
def save_model(self, request, obj, form, change):
|
||||
form.changed_data.remove("memory_unit")
|
||||
super().save_model(request, obj, form, change)
|
||||
if form.changed_data and any(
|
||||
f in form.changed_data for f in ("is_public", "points", "partial")
|
||||
|
@ -381,7 +382,24 @@ class ProblemAdmin(CompareVersionAdmin):
|
|||
# Only rescored if we did not already do so in `save_model`
|
||||
obj = form.instance
|
||||
obj.curators.add(request.profile)
|
||||
obj.is_organization_private = obj.organizations.count() > 0
|
||||
obj.save()
|
||||
# Create notification
|
||||
if "is_public" in form.changed_data:
|
||||
users = set(obj.authors.all())
|
||||
if obj.organizations.count() > 0:
|
||||
for org in obj.organizations.all():
|
||||
users = users.union(users, set(org.admins.all()))
|
||||
else:
|
||||
admins = Profile.objects.filter(user__is_superuser=True).all()
|
||||
users = users.union(users, admins)
|
||||
link = reverse_lazy("admin:judge_problem_change", args=(obj.id,))
|
||||
html = f"<a href=\"{link}\">{obj.name}</a>"
|
||||
for user in users:
|
||||
notification = Notification(
|
||||
owner=user, html_link=html, category="Problem public: " + str(obj.is_public), author=request.profile
|
||||
)
|
||||
notification.save()
|
||||
|
||||
def construct_change_message(self, request, form, *args, **kwargs):
|
||||
if form.cleaned_data.get("change_message"):
|
||||
|
|
23
judge/migrations/0131_auto_20220905_0027.py
Normal file
23
judge/migrations/0131_auto_20220905_0027.py
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Generated by Django 2.2.25 on 2022-09-04 17:27
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('judge', '0130_auto_20220831_1048'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='notification',
|
||||
name='category',
|
||||
field=models.CharField(max_length=50, verbose_name='category'),
|
||||
),
|
||||
migrations.AlterField(
|
||||
model_name='problemtranslation',
|
||||
name='language',
|
||||
field=models.CharField(choices=[('en', 'English'), ('vi', 'Vietnamese')], max_length=7, verbose_name='language'),
|
||||
),
|
||||
]
|
|
@ -244,7 +244,7 @@ class Notification(models.Model):
|
|||
Comment, null=True, verbose_name=_("comment"), on_delete=CASCADE
|
||||
)
|
||||
read = models.BooleanField(verbose_name=_("read"), default=False)
|
||||
category = models.CharField(verbose_name=_("category"), max_length=10)
|
||||
category = models.CharField(verbose_name=_("category"), max_length=50)
|
||||
html_link = models.TextField(
|
||||
default="",
|
||||
verbose_name=_("html link to comments, used for non-comments"),
|
||||
|
|
Loading…
Reference in a new issue