Support output-only SCAT

This commit is contained in:
cuom1999 2023-03-25 22:51:43 -05:00
parent a07b147ea6
commit 8952683505
2 changed files with 24 additions and 16 deletions

View file

@ -149,19 +149,21 @@ class ProblemSubmitForm(ModelForm):
def clean(self): def clean(self):
if "source_file" in self.files: if "source_file" in self.files:
if self.cleaned_data["language"].key == "OUTPUT" and self.files[ if self.cleaned_data["language"].key in ["OUTPUT", "SCAT"]:
"source_file" filename = self.files["source_file"].name
].name.endswith(".zip"): if filename.endswith(".zip") or filename.endswith(".sb3"):
self.source_file_name = secrets.token_hex(16) + ".zip" self.source_file_name = (
filepath = os.path.join( secrets.token_hex(16) + "." + filename.split(".")[-1]
settings.DMOJ_SUBMISSION_ROOT, self.source_file_name )
) filepath = os.path.join(
with open(filepath, "wb+") as destination: settings.DMOJ_SUBMISSION_ROOT, self.source_file_name
for chunk in self.files["source_file"].chunks(): )
destination.write(chunk) with open(filepath, "wb+") as destination:
self.cleaned_data["source"] = self.request.build_absolute_uri( for chunk in self.files["source_file"].chunks():
reverse("submission_source_file", args=(self.source_file_name,)) 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"] del self.files["source_file"]
return self.cleaned_data return self.cleaned_data

View file

@ -153,9 +153,15 @@
if (file.name.endsWith('zip')) { if (file.name.endsWith('zip')) {
update_submit_area(file.name); update_submit_area(file.name);
} }
else if (file.name.endsWith('sb3')) { {% if output_only %}
get_source_scratch(file); else if (file.name.endsWith('sb3')) {
} update_submit_area(file.name);
}
{% else %}
else if (file.name.endsWith('sb3')) {
get_source_scratch(file);
}
{% endif %}
else { else {
get_source_default(file); get_source_default(file);
} }