diff --git a/judge/admin/contest.py b/judge/admin/contest.py index 33767de..e63bf78 100644 --- a/judge/admin/contest.py +++ b/judge/admin/contest.py @@ -192,9 +192,7 @@ class ContestAdmin(CompareVersionAdmin): { "fields": ( "access_code", - "is_private", "private_contestants", - "is_organization_private", "organizations", "view_contest_scoreboard", ) diff --git a/judge/admin/problem.py b/judge/admin/problem.py index f770d6b..537c632 100644 --- a/judge/admin/problem.py +++ b/judge/admin/problem.py @@ -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"{obj.name}" + 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"): diff --git a/judge/migrations/0131_auto_20220905_0027.py b/judge/migrations/0131_auto_20220905_0027.py new file mode 100644 index 0000000..f96fb09 --- /dev/null +++ b/judge/migrations/0131_auto_20220905_0027.py @@ -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'), + ), + ] diff --git a/judge/models/comment.py b/judge/models/comment.py index c03df7e..9361434 100644 --- a/judge/models/comment.py +++ b/judge/models/comment.py @@ -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"),