From: Guillaume Pellerin Date: Tue, 15 Jul 2014 15:12:01 +0000 (+0200) Subject: Rename uploaded script by uuid X-Git-Tag: 1.1~434 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=31a98e643de8d834c9a7da87fd79663e1e27f257;p=teleforma.git Rename uploaded script by uuid --- diff --git a/teleforma/exam/models.py b/teleforma/exam/models.py index 29bc6122..777f3e86 100644 --- a/teleforma/exam/models.py +++ b/teleforma/exam/models.py @@ -270,6 +270,7 @@ class Script(BaseResource): if self.status == 2: self.status = 3 super(Script, self).save(*args, **kwargs) + self.fix_filename() self.submit() if self.status == 4 and self.score: self.mark() @@ -278,6 +279,14 @@ class Script(BaseResource): super(Script, self).save(*args, **kwargs) + def fix_filename(self): + old = self.file.path + old_list = old.split(os.sep) + path = old_list[:-2] + new = os.sep.join(path) + os.sep + unicode(self.uuid) + '.pdf' + os.rename(old, new) + self.file = new + def submit(self): self.date_submitted = datetime.datetime.now() self.url = settings.MEDIA_URL + unicode(self.file)