Skip to content

Commit 00edb1a

Browse files
committed
fix(problem): problem path using id not display id
1 parent 5539109 commit 00edb1a

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

judge/tasks.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def judge_task(submission_id, problem_id):
2121
def local_judge_task(submission_id, problem_id, user_id):
2222
submission = Submission.objects.get(id=submission_id)
2323

24-
problem = Problem.objects.get(_id=problem_id)
24+
problem = Problem.objects.get(id=problem_id)
2525
problem.submission_number += 1
2626
try:
2727
if SubmissionTester(submission).judge():

judge/testing.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class TestResult:
2424
Error = 1
2525
Timeout = 2
2626

27-
def create_new_problem_from_template(new_problem_id: str, old_problem_id: str):
27+
def create_new_problem_from_template(new_problem_id: int, old_problem_id: int):
2828
old_path = PathManager.problem_dir(old_problem_id)
2929
new_path = PathManager.problem_dir(new_problem_id)
3030
os.makedirs(new_path, exist_ok=True)
@@ -67,8 +67,8 @@ def run_command_with_timeout(command: list, timeout: float) -> int:
6767

6868
class PathManager:
6969
@staticmethod
70-
def problem_dir(problem_id: str) -> str:
71-
return join(DATA_DIR, PROBLEM_DIR, problem_id)
70+
def problem_dir(id: int) -> str:
71+
return join(DATA_DIR, PROBLEM_DIR, str(id))
7272

7373
@staticmethod
7474
def submission_dir(user_id: str, submission_id: str) -> str:
@@ -91,7 +91,7 @@ def __init__(self, uploaded_file, problem: Problem):
9191
else:
9292
raise Exception("zipfile is None")
9393
self.problem = problem
94-
self.problem_dir_path = PathManager.problem_dir(problem._id)
94+
self.problem_dir_path = PathManager.problem_dir(problem.id)
9595
if not exists(self.problem_dir_path):
9696
os.makedirs(self.problem_dir_path)
9797
self._error_message: str = ""
@@ -165,7 +165,7 @@ def __init__(self, submission: Submission):
165165
if not exists(self.sub_dirpath):
166166
os.makedirs(self.sub_dirpath, exist_ok=True)
167167
problem: Problem = submission.problem
168-
prob_dir = PathManager.problem_dir(problem._id) # use display id
168+
prob_dir = PathManager.problem_dir(problem.id) # use display id
169169
if not exists(prob_dir):
170170
raise Exception("problem dir {} not exists".format(prob_dir))
171171
for filename in os.listdir(prob_dir):

problem/views/admin.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def delete(self, request):
125125
except Problem.DoesNotExist:
126126
return self.error("Problem does not exists")
127127
ensure_created_by(problem, request.user)
128-
d = PathManager.problem_dir(problem._id)
128+
d = PathManager.problem_dir(problem.id)
129129
if os.path.isdir(d):
130130
print('remove dir', d)
131131
shutil.rmtree(d, ignore_errors=True)
@@ -322,7 +322,7 @@ def post(self, request):
322322
new_problem = Problem.objects.create(**data)
323323
new_problem.tags.set(tags)
324324

325-
create_new_problem_from_template(new_problem._id, old_problem._id)
325+
create_new_problem_from_template(new_problem.id, old_problem.id)
326326

327327
return self.success()
328328

0 commit comments

Comments
 (0)