From 580a4019c70d608113ea06e1c895df6e7af88b45 Mon Sep 17 00:00:00 2001 From: cuom1999 Date: Sun, 12 Mar 2023 03:25:23 -0500 Subject: [PATCH] Another fix pdf_description save --- judge/models/problem.py | 15 +++++++++------ judge/models/problem_data.py | 5 ----- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/judge/models/problem.py b/judge/models/problem.py index 76eca0a..89e88f4 100644 --- a/judge/models/problem.py +++ b/judge/models/problem.py @@ -1,3 +1,4 @@ +import errno from operator import attrgetter from math import sqrt @@ -561,16 +562,18 @@ class Problem(models.Model): def save(self, *args, **kwargs): super(Problem, self).save(*args, **kwargs) if self.code != self.__original_code: - try: - problem_data = self.data_files - except AttributeError: - pass - else: - problem_data._update_code(self.__original_code, self.code) + if hasattr(self, "data_files") or self.pdf_description: + try: + problem_data_storage.rename(self.__original_code, self.code) + except OSError as e: + if e.errno != errno.ENOENT: + raise if self.pdf_description: self.pdf_description.name = problem_directory_file_helper( self.code, self.pdf_description.name ) + if hasattr(self, "data_files"): + self.data_files._update_code(self.__original_code, self.code) save.alters_data = True diff --git a/judge/models/problem_data.py b/judge/models/problem_data.py index 9f181ea..38a214b 100644 --- a/judge/models/problem_data.py +++ b/judge/models/problem_data.py @@ -151,11 +151,6 @@ class ProblemData(models.Model): return problem_data_storage.exists("%s/init.yml" % self.problem.code) def _update_code(self, original, new): - try: - problem_data_storage.rename(original, new) - except OSError as e: - if e.errno != errno.ENOENT: - raise if self.zipfile: self.zipfile.name = problem_directory_file_helper(new, self.zipfile.name) if self.generator: