From 0857df08f998f08e086d14c230753942bf450d4e Mon Sep 17 00:00:00 2001 From: pierre-24 Date: Tue, 23 Feb 2016 11:58:00 +0100 Subject: [PATCH] Also deal with contents that would have been created DURING v16. --- .../management/commands/adjust_slugs.py | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/zds/tutorialv2/management/commands/adjust_slugs.py b/zds/tutorialv2/management/commands/adjust_slugs.py index b3ac5a7b71..a52838fa04 100644 --- a/zds/tutorialv2/management/commands/adjust_slugs.py +++ b/zds/tutorialv2/management/commands/adjust_slugs.py @@ -5,6 +5,7 @@ from django.core.management.base import BaseCommand from zds.settings import ZDS_APP from zds.tutorialv2.models.models_database import PublishableContent +from django.utils.translation import ugettext_lazy as _ class Command(BaseCommand): @@ -19,13 +20,35 @@ def handle(self, *args, **options): good_slug = slugify(c.title) if c.slug != good_slug: if os.path.isdir(os.path.join(ZDS_APP['content']['repo_private_path'], good_slug)): - self.stdout.write(u'Fixing content #{} (« {} ») ... '.format(c.pk, c.title), ending='') + # this content was created before v16 and is probably broken + self.stdout.write(u'Fixing pre-v16 content #{} (« {} ») ... '.format(c.pk, c.title), ending='') c.save() if os.path.isdir(c.get_repo_path()): self.stdout.write(u'[OK]') else: self.stdout.write(u'[KO]') + elif os.path.isdir(os.path.join(ZDS_APP['content']['repo_private_path'], c.slug)): + # this content was created during v16 and will be broken if nothing is done + self.stdout.write(u'Fixing in-v16 content #{} (« {} ») ... '.format(c.pk, c.title), ending='') + try: + versioned = c.load_version() + except IOError: + self.stdout.write(u'[KO]') + else: + c.sha_draft = versioned.repo_update_top_container( + c.title, + good_slug, + versioned.get_introduction(), + versioned.get_conclusion(), + commit_message=_(u'[hotfix] Corrige le slug pour éviter un bug')) + + c.save() + + if os.path.isdir(c.get_repo_path()): + self.stdout.write(u'[OK]') + else: + self.stdout.write(u'[KO]') else: self.stderr.write( - u'Content #{} (« {} ») cannot be fixed: there is no directory named "{}" in "{}".\n'. - format(c.pk, c.title, good_slug, ZDS_APP['content']['repo_private_path'])) + u'Content #{} (« {} ») is an orphan: there is no directory named "{}" or "{}".\n'. + format(c.pk, c.title, good_slug, c.slug))