Fix scat bug

This commit is contained in:
cuom1999 2023-03-26 03:00:05 -05:00
parent ef813f5dbe
commit 90ea6a7844
2 changed files with 7 additions and 2 deletions

View file

@ -131,10 +131,11 @@ class ProblemSubmitForm(ModelForm):
judge = ChoiceField(choices=(), widget=forms.HiddenInput(), required=False) judge = ChoiceField(choices=(), widget=forms.HiddenInput(), required=False)
source_file = FileField(required=False, validators=[file_size_validator]) source_file = FileField(required=False, validators=[file_size_validator])
def __init__(self, *args, judge_choices=(), request=None, **kwargs): def __init__(self, *args, judge_choices=(), request=None, problem=None, **kwargs):
super(ProblemSubmitForm, self).__init__(*args, **kwargs) super(ProblemSubmitForm, self).__init__(*args, **kwargs)
self.source_file_name = None self.source_file_name = None
self.request = request self.request = request
self.problem = problem
self.fields["language"].empty_label = None self.fields["language"].empty_label = None
self.fields["language"].label_from_instance = attrgetter("display_name") self.fields["language"].label_from_instance = attrgetter("display_name")
self.fields["language"].queryset = Language.objects.filter( self.fields["language"].queryset = Language.objects.filter(
@ -149,7 +150,10 @@ 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 in ["OUTPUT", "SCAT"]: if (
self.cleaned_data["language"].key in ["OUTPUT", "SCAT"]
and self.problem.data_files.output_only
):
filename = self.files["source_file"].name filename = self.files["source_file"].name
if filename.endswith(".zip") or filename.endswith(".sb3"): if filename.endswith(".zip") or filename.endswith(".sb3"):
self.source_file_name = ( self.source_file_name = (

View file

@ -1044,6 +1044,7 @@ def problem_submit(request, problem, submission=None):
judge_choices=judge_choices, judge_choices=judge_choices,
instance=Submission(user=profile, problem=problem), instance=Submission(user=profile, problem=problem),
request=request, request=request,
problem=problem,
) )
if form.is_valid(): if form.is_valid():
if ( if (