Skip to content

Commit

Permalink
Merge branch 'DMOJ:master' into dmoj
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonLovesDoggo authored Jan 14, 2024
2 parents 25b4710 + 61318c7 commit 430f3ff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
28 changes: 19 additions & 9 deletions judge/views/problem_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import mimetypes
import os
from itertools import chain
from typing import List
from zipfile import BadZipfile, ZipFile

from django.conf import settings
Expand Down Expand Up @@ -169,7 +170,7 @@ def get_case_formset(self, files, post=False):
return ProblemCaseFormSet(data=self.request.POST if post else None, prefix='cases', valid_files=files,
queryset=ProblemTestCase.objects.filter(dataset_id=self.object.pk).order_by('order'))

def get_valid_files(self, data, post=False):
def get_valid_files(self, data, post=False) -> List[str]:
try:
if post and 'problem-data-zipfile-clear' in self.request.POST:
return []
Expand All @@ -178,26 +179,35 @@ def get_valid_files(self, data, post=False):
elif data.zipfile:
return ZipFile(data.zipfile.path).namelist()
except BadZipfile:
return None
raise
return []

def get_context_data(self, **kwargs):
context = super(ProblemDataView, self).get_context_data(**kwargs)
valid_files = []
if 'data_form' not in context:
context['data_form'] = self.get_data_form()
valid_files = context['valid_files'] = self.get_valid_files(context['data_form'].instance)
context['cases_formset'] = self.get_case_formset(valid_files)
if context['valid_files']:
context['valid_files_json'] = mark_safe(json.dumps(context['valid_files']))
context['valid_files'] = set(context['valid_files'])
try:
valid_files = self.get_valid_files(context['data_form'].instance)
except BadZipfile:
pass
context['valid_files'] = set(valid_files)
context['valid_files_json'] = mark_safe(json.dumps(valid_files))

context['cases_formset'] = self.get_case_formset(valid_files)
context['all_case_forms'] = chain(context['cases_formset'], [context['cases_formset'].empty_form])
return context

def post(self, request, *args, **kwargs):
self.object = problem = self.get_object()
data_form = self.get_data_form(post=True)
valid_files = self.get_valid_files(data_form.instance, post=True)
data_form.zip_valid = valid_files is not None
try:
valid_files = self.get_valid_files(data_form.instance, post=True)
data_form.zip_valid = True
except BadZipfile:
valid_files = []
data_form.zip_valid = False

cases_formset = self.get_case_formset(valid_files, post=True)
if data_form.is_valid() and cases_formset.is_valid():
data = data_form.save()
Expand Down
8 changes: 4 additions & 4 deletions resources/table.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@
margin-bottom: 0.5em;
background: rgba($color_primary100, 0.01);

&.striped tr:nth-child(even) {
background: rgba($color_primary100, 0.03);
}

th {
height: 2em;
color: $color_primary0;
Expand Down Expand Up @@ -62,3 +58,7 @@
border-bottom-left-radius: $table_header_rounding;
}
}

.striped tr:nth-child(even) {
background: rgba($color_primary100, 0.03);
}

0 comments on commit 430f3ff

Please sign in to comment.