From: Guillaume Pellerin Date: Fri, 18 Jul 2014 09:56:02 +0000 (+0200) Subject: slugify script filename X-Git-Tag: 1.1~408 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=8f4638f7d0194322a27f4067de738ddc36ffb3dd;p=teleforma.git slugify script filename --- diff --git a/teleforma/exam/models.py b/teleforma/exam/models.py index 86748834..a6e399b4 100644 --- a/teleforma/exam/models.py +++ b/teleforma/exam/models.py @@ -277,13 +277,21 @@ 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[:-1] - filename, ext = os.path.splitext(old_list[-1]) - new = os.sep.join(path) + os.sep + slugify(filename) + ext - os.rename(old, new) - self.file.path = new + old_abs = self.file.path + old_abs_list = old_abs.split(os.sep) + old_abs_root = old_abs_list[:-1] + + old_rel = unicode(self.file) + old_rel_list = old_rel.split(os.sep) + old_rel_root = old_rel_list[:-1] + + filename, ext = os.path.splitext(old_abs_list[-1]) + + new_abs = os.sep.join(old_abs_root) + os.sep + slugify(filename) + ext + new_rel = os.sep.join(old_rel_root) + os.sep + slugify(filename) + ext + + os.rename(old_abs, new_abs) + self.file = new_rel self.save() def submit(self): diff --git a/teleforma/management/commands/teleforma-exam-submit-scripts.py b/teleforma/management/commands/teleforma-exam-submit-scripts.py index 0c171e8c..faa5ac05 100644 --- a/teleforma/management/commands/teleforma-exam-submit-scripts.py +++ b/teleforma/management/commands/teleforma-exam-submit-scripts.py @@ -33,6 +33,9 @@ class Command(BaseCommand): for script in Script.objects.filter(status=2): script.fix_filename() logger.logger.info(script.title) - script.submit() + try: + script.submit() + except: + logger.logger.error('ERROR') logger.logger.info('OK') time.sleep(10)