From 8952683505f3f6fdd4381f576309e2ba0a2f651a Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Sat, 25 Mar 2023 22:51:43 -0500 Subject: [PATCH] Support output-only SCAT --- judge/forms.py | 28 +++++++++++++++------------- templates/problem/submit.html | 12 +++++++++--- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/judge/forms.py b/judge/forms.py index 5168240..077728a 100644 --- a/judge/forms.py +++ b/judge/forms.py @@ -149,19 +149,21 @@ class ProblemSubmitForm(ModelForm): def clean(self): if "source_file" in self.files: - if self.cleaned_data["language"].key == "OUTPUT" and self.files[ - "source_file" - ].name.endswith(".zip"): - self.source_file_name = secrets.token_hex(16) + ".zip" - filepath = os.path.join( - settings.DMOJ_SUBMISSION_ROOT, self.source_file_name - ) - with open(filepath, "wb+") as destination: - for chunk in self.files["source_file"].chunks(): - destination.write(chunk) - self.cleaned_data["source"] = self.request.build_absolute_uri( - reverse("submission_source_file", args=(self.source_file_name,)) - ) + if self.cleaned_data["language"].key in ["OUTPUT", "SCAT"]: + filename = self.files["source_file"].name + if filename.endswith(".zip") or filename.endswith(".sb3"): + self.source_file_name = ( + secrets.token_hex(16) + "." + filename.split(".")[-1] + ) + filepath = os.path.join( + settings.DMOJ_SUBMISSION_ROOT, self.source_file_name + ) + with open(filepath, "wb+") as destination: + for chunk in self.files["source_file"].chunks(): + destination.write(chunk) + self.cleaned_data["source"] = self.request.build_absolute_uri( + reverse("submission_source_file", args=(self.source_file_name,)) + ) del self.files["source_file"] return self.cleaned_data diff --git a/templates/problem/submit.html b/templates/problem/submit.html index 7f36406..178f2ac 100644 --- a/templates/problem/submit.html +++ b/templates/problem/submit.html @@ -153,9 +153,15 @@ if (file.name.endsWith('zip')) { update_submit_area(file.name); } - else if (file.name.endsWith('sb3')) { - get_source_scratch(file); - } + {% if output_only %} + else if (file.name.endsWith('sb3')) { + update_submit_area(file.name); + } + {% else %} + else if (file.name.endsWith('sb3')) { + get_source_scratch(file); + } + {% endif %} else { get_source_default(file); }