Skip to content

Commit

Permalink
Also deal with contents that would have been created DURING v16.
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre-24 committed Feb 23, 2016
1 parent fa03565 commit 0857df0
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions zds/tutorialv2/management/commands/adjust_slugs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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))

0 comments on commit 0857df0

Please sign in to comment.