Fix problem code change bug
This commit is contained in:
parent
b053c43b19
commit
7a05ad1c3b
6 changed files with 23 additions and 8 deletions
7
judge/logging.py
Normal file
7
judge/logging.py
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import logging
|
||||||
|
|
||||||
|
error_log = logging.getLogger("judge.errors")
|
||||||
|
|
||||||
|
|
||||||
|
def log_exception(msg):
|
||||||
|
error_log.exception(msg)
|
|
@ -556,7 +556,7 @@ class Problem(models.Model, PageVotable, Bookmarkable):
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
super(Problem, self).save(*args, **kwargs)
|
super(Problem, self).save(*args, **kwargs)
|
||||||
if self.code != self.__original_code:
|
if self.__original_code and self.code != self.__original_code:
|
||||||
if hasattr(self, "data_files") or self.pdf_description:
|
if hasattr(self, "data_files") or self.pdf_description:
|
||||||
try:
|
try:
|
||||||
problem_data_storage.rename(self.__original_code, self.code)
|
problem_data_storage.rename(self.__original_code, self.code)
|
||||||
|
|
|
@ -162,9 +162,9 @@ class ProblemData(models.Model):
|
||||||
get_file_cachekey(file),
|
get_file_cachekey(file),
|
||||||
)
|
)
|
||||||
cache.delete(cache_key)
|
cache.delete(cache_key)
|
||||||
except BadZipFile:
|
except (BadZipFile, FileNotFoundError):
|
||||||
pass
|
pass
|
||||||
if self.zipfile != self.__original_zipfile and self.__original_zipfile:
|
if self.zipfile != self.__original_zipfile:
|
||||||
self.__original_zipfile.delete(save=False)
|
self.__original_zipfile.delete(save=False)
|
||||||
return super(ProblemData, self).save(*args, **kwargs)
|
return super(ProblemData, self).save(*args, **kwargs)
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,8 @@ from django.urls import reverse
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
from django.core.cache import cache
|
from django.core.cache import cache
|
||||||
|
|
||||||
|
from judge.logging import log_exception
|
||||||
|
|
||||||
if os.altsep:
|
if os.altsep:
|
||||||
|
|
||||||
def split_path_first(
|
def split_path_first(
|
||||||
|
@ -323,11 +325,13 @@ def get_problem_case(problem, files):
|
||||||
settings.DMOJ_PROBLEM_DATA_ROOT, str(problem.data_files.zipfile)
|
settings.DMOJ_PROBLEM_DATA_ROOT, str(problem.data_files.zipfile)
|
||||||
)
|
)
|
||||||
if not os.path.exists(archive_path):
|
if not os.path.exists(archive_path):
|
||||||
raise Exception('archive file "%s" does not exist' % archive_path)
|
log_exception('archive file "%s" does not exist' % archive_path)
|
||||||
|
return {}
|
||||||
try:
|
try:
|
||||||
archive = zipfile.ZipFile(archive_path, "r")
|
archive = zipfile.ZipFile(archive_path, "r")
|
||||||
except zipfile.BadZipfile:
|
except zipfile.BadZipfile:
|
||||||
raise Exception('bad archive: "%s"' % archive_path)
|
log_exception('bad archive: "%s"' % archive_path)
|
||||||
|
return {}
|
||||||
|
|
||||||
for file in uncached_files:
|
for file in uncached_files:
|
||||||
cache_key = "problem_archive:%s:%s" % (problem.code, get_file_cachekey(file))
|
cache_key = "problem_archive:%s:%s" % (problem.code, get_file_cachekey(file))
|
||||||
|
|
|
@ -56,6 +56,7 @@ from judge.utils.fine_uploader import (
|
||||||
FineUploadForm,
|
FineUploadForm,
|
||||||
)
|
)
|
||||||
from judge.views.problem import ProblemMixin
|
from judge.views.problem import ProblemMixin
|
||||||
|
from judge.logging import log_exception
|
||||||
|
|
||||||
mimetypes.init()
|
mimetypes.init()
|
||||||
mimetypes.add_type("application/x-yaml", ".yml")
|
mimetypes.add_type("application/x-yaml", ".yml")
|
||||||
|
@ -249,6 +250,9 @@ class ProblemDataView(TitleMixin, ProblemManagerMixin):
|
||||||
return ZipFile(data.zipfile.path).namelist()
|
return ZipFile(data.zipfile.path).namelist()
|
||||||
except BadZipfile:
|
except BadZipfile:
|
||||||
return []
|
return []
|
||||||
|
except FileNotFoundError as e:
|
||||||
|
log_exception(e)
|
||||||
|
return []
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
|
|
|
@ -195,8 +195,8 @@ def get_cases_data(submission):
|
||||||
continue
|
continue
|
||||||
count += 1
|
count += 1
|
||||||
problem_data[count] = {
|
problem_data[count] = {
|
||||||
"input": case_data[case.input_file] if case.input_file else "",
|
"input": case_data.get(case.input_file, "") if case.input_file else "",
|
||||||
"answer": case_data[case.output_file] if case.output_file else "",
|
"answer": case_data.get(case.output_file, "") if case.output_file else "",
|
||||||
}
|
}
|
||||||
|
|
||||||
return problem_data
|
return problem_data
|
||||||
|
|
Loading…
Reference in a new issue