From ae5b7a6e653b4a683011957da29ed7c6ca636d79 Mon Sep 17 00:00:00 2001 From: ayang818 Date: Fri, 18 Oct 2019 12:04:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=B8=8A=E4=BC=A0=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E7=94=A8=E4=BE=8B=E9=BB=98=E8=AE=A4=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E4=B8=BANone=20&&=20=E4=BF=AE=E6=94=B9=E5=BD=93=E4=BC=A0?= =?UTF-8?q?=E5=85=A5dir=E5=8F=82=E6=95=B0=E4=B8=8D=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E6=97=B6,=20=E4=B8=8D=E6=89=A7=E8=A1=8Cjudge=5Fdir=E5=87=BD?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- problem/views/admin.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/problem/views/admin.py b/problem/views/admin.py index 54396749..b713c345 100644 --- a/problem/views/admin.py +++ b/problem/views/admin.py @@ -32,13 +32,14 @@ from ..utils import TEMPLATE_BASE, build_problem_template class TestCaseZipProcessor(object): - def process_zip(self, uploaded_zip_file, spj, dir=""): + def process_zip(self, uploaded_zip_file, spj, dir=None): try: zip_file = zipfile.ZipFile(uploaded_zip_file, "r") except zipfile.BadZipFile: raise APIError("Bad zip file") name_list = zip_file.namelist() - dir = self.judge_dir(name_list, dir) + if not dir: + dir = self.judge_dir(name_list) test_case_list = self.filter_name_list(name_list, spj=spj, dir=dir) if not test_case_list: raise APIError("Empty file") @@ -110,8 +111,8 @@ class TestCaseZipProcessor(object): continue else: return sorted(ret, key=natural_sort_key) - - def judge_dir(self, name_list, dir=""): + + def judge_dir(self, name_list): is_native = True for i, item_i in enumerate(name_list): if "/" not in item_i: @@ -129,6 +130,7 @@ class TestCaseZipProcessor(object): dir = name_list[0].split("/")[0]+"/" return dir + class TestCaseAPI(CSRFExemptAPIView, TestCaseZipProcessor): request_parsers = ()