Another fix pdf_description save
This commit is contained in:
parent
a4b06a354c
commit
580a4019c7
2 changed files with 9 additions and 11 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
import errno
|
||||||
from operator import attrgetter
|
from operator import attrgetter
|
||||||
from math import sqrt
|
from math import sqrt
|
||||||
|
|
||||||
|
@ -561,16 +562,18 @@ class Problem(models.Model):
|
||||||
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.code != self.__original_code:
|
||||||
try:
|
if hasattr(self, "data_files") or self.pdf_description:
|
||||||
problem_data = self.data_files
|
try:
|
||||||
except AttributeError:
|
problem_data_storage.rename(self.__original_code, self.code)
|
||||||
pass
|
except OSError as e:
|
||||||
else:
|
if e.errno != errno.ENOENT:
|
||||||
problem_data._update_code(self.__original_code, self.code)
|
raise
|
||||||
if self.pdf_description:
|
if self.pdf_description:
|
||||||
self.pdf_description.name = problem_directory_file_helper(
|
self.pdf_description.name = problem_directory_file_helper(
|
||||||
self.code, self.pdf_description.name
|
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
|
save.alters_data = True
|
||||||
|
|
||||||
|
|
|
@ -151,11 +151,6 @@ class ProblemData(models.Model):
|
||||||
return problem_data_storage.exists("%s/init.yml" % self.problem.code)
|
return problem_data_storage.exists("%s/init.yml" % self.problem.code)
|
||||||
|
|
||||||
def _update_code(self, original, new):
|
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:
|
if self.zipfile:
|
||||||
self.zipfile.name = problem_directory_file_helper(new, self.zipfile.name)
|
self.zipfile.name = problem_directory_file_helper(new, self.zipfile.name)
|
||||||
if self.generator:
|
if self.generator:
|
||||||
|
|
Loading…
Reference in a new issue