]> git.parisson.com Git - teleforma.git/commitdiff
Rename uploaded script by uuid
authorGuillaume Pellerin <yomguy@parisson.com>
Tue, 15 Jul 2014 15:12:01 +0000 (17:12 +0200)
committerGuillaume Pellerin <yomguy@parisson.com>
Tue, 15 Jul 2014 15:12:01 +0000 (17:12 +0200)
teleforma/exam/models.py

index 29bc6122f4cca41c178336fe0f22ee1bcaf15815..777f3e86fd198123d488a5c9cd9c529858319a4c 100644 (file)
@@ -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)