From 8f046c59c172ede5c4d2a9f2540a7e5989ad0f8a Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Fri, 25 Aug 2023 18:12:53 -0500 Subject: [PATCH] Drop output_prefix_override and use show_testcases --- judge/admin/contest.py | 3 +- judge/forms.py | 2 +- judge/migrations/0164_show_testcase.py | 30 +++++++++++++++++++ .../0165_drop_output_prefix_override.py | 17 +++++++++++ judge/models/contest.py | 7 ++--- judge/models/profile.py | 7 +++++ judge/views/submission.py | 6 ++-- templates/submission/status-testcases.html | 5 ---- 8 files changed, 61 insertions(+), 16 deletions(-) create mode 100644 judge/migrations/0164_show_testcase.py create mode 100644 judge/migrations/0165_drop_output_prefix_override.py diff --git a/judge/admin/contest.py b/judge/admin/contest.py index f183880..9c8b6fd 100644 --- a/judge/admin/contest.py +++ b/judge/admin/contest.py @@ -71,7 +71,6 @@ class ContestProblemInlineForm(ModelForm): "hidden_subtasks": TextInput(attrs={"size": "3"}), "points": TextInput(attrs={"size": "1"}), "order": TextInput(attrs={"size": "1"}), - "output_prefix_override": TextInput(attrs={"size": "1"}), } @@ -86,7 +85,7 @@ class ContestProblemInline(admin.TabularInline): "is_pretested", "max_submissions", "hidden_subtasks", - "output_prefix_override", + "show_testcases", "order", "rejudge_column", ) diff --git a/judge/forms.py b/judge/forms.py index 32fc75e..d71ffbc 100644 --- a/judge/forms.py +++ b/judge/forms.py @@ -528,7 +528,7 @@ class ContestProblemForm(ModelForm): "problem", "points", "partial", - "output_prefix_override", + "show_testcases", "max_submissions", ) widgets = { diff --git a/judge/migrations/0164_show_testcase.py b/judge/migrations/0164_show_testcase.py new file mode 100644 index 0000000..33cbdf8 --- /dev/null +++ b/judge/migrations/0164_show_testcase.py @@ -0,0 +1,30 @@ +# Generated by Django 3.2.18 on 2023-08-25 23:03 + +from django.db import migrations, models + + +def migrate_show_testcases(apps, schema_editor): + ContestProblem = apps.get_model("judge", "ContestProblem") + + for c in ContestProblem.objects.all(): + if c.output_prefix_override == 1: + c.show_testcases = True + c.save() + + +class Migration(migrations.Migration): + + dependencies = [ + ("judge", "0163_email_change"), + ] + + operations = [ + migrations.AddField( + model_name="contestproblem", + name="show_testcases", + field=models.BooleanField(default=False, verbose_name="visible testcases"), + ), + migrations.RunPython( + migrate_show_testcases, migrations.RunPython.noop, atomic=True + ), + ] diff --git a/judge/migrations/0165_drop_output_prefix_override.py b/judge/migrations/0165_drop_output_prefix_override.py new file mode 100644 index 0000000..ea9b17a --- /dev/null +++ b/judge/migrations/0165_drop_output_prefix_override.py @@ -0,0 +1,17 @@ +# Generated by Django 3.2.18 on 2023-08-25 23:11 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("judge", "0164_show_testcase"), + ] + + operations = [ + migrations.RemoveField( + model_name="contestproblem", + name="output_prefix_override", + ), + ] diff --git a/judge/models/contest.py b/judge/models/contest.py index 1129076..8bb3d5b 100644 --- a/judge/models/contest.py +++ b/judge/models/contest.py @@ -772,12 +772,9 @@ class ContestProblem(models.Model): partial = models.BooleanField(default=True, verbose_name=_("partial")) is_pretested = models.BooleanField(default=False, verbose_name=_("is pretested")) order = models.PositiveIntegerField(db_index=True, verbose_name=_("order")) - output_prefix_override = models.IntegerField( - help_text=_("0 to not show testcases, 1 to show"), + show_testcases = models.BooleanField( verbose_name=_("visible testcases"), - null=True, - blank=True, - default=0, + default=False, ) max_submissions = models.IntegerField( help_text=_( diff --git a/judge/models/profile.py b/judge/models/profile.py index eb3572a..ccb0e87 100644 --- a/judge/models/profile.py +++ b/judge/models/profile.py @@ -109,6 +109,13 @@ class Organization(models.Model): "Organization membership test must be Profile or primany key" ) + def delete(self, *args, **kwargs): + contests = self.contest_set + for contest in contests.all(): + if contest.organizations.count() == 1: + contest.delete() + super().delete(*args, **kwargs) + def __str__(self): return self.name diff --git a/judge/views/submission.py b/judge/views/submission.py index 147a2cc..1556dd9 100644 --- a/judge/views/submission.py +++ b/judge/views/submission.py @@ -259,13 +259,13 @@ class SubmissionStatus(SubmissionDetailBase): ) contest = submission.contest_or_none - prefix_length = 0 + show_testcases = False can_see_testcases = self.access_testcases_in_contest() if contest is not None: - prefix_length = contest.problem.output_prefix_override or 0 + show_testcases = contest.problem.show_testcases or False - if contest is None or prefix_length > 0 or can_see_testcases: + if contest is None or show_testcases or can_see_testcases: context["cases_data"] = get_cases_data(submission) context["can_see_testcases"] = True try: diff --git a/templates/submission/status-testcases.html b/templates/submission/status-testcases.html index 4d4b435..2d2547d 100644 --- a/templates/submission/status-testcases.html +++ b/templates/submission/status-testcases.html @@ -1,8 +1,3 @@ -{% if submission.contest_or_none %} - {% set prefix_length = submission.contest_or_none.problem.output_prefix_override %} -{% else %} - {% set prefix_length = None %} -{% endif %} {% set is_pretest = submission.is_pretested %} {% if submission.status != 'IE' %}