Skip to content

Instantly share code, notes, and snippets.

@czpython
Created November 13, 2015 10:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save czpython/ea5249a85eb80e6159cb to your computer and use it in GitHub Desktop.
Save czpython/ea5249a85eb80e6159cb to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
from django.core.management.base import NoArgsCommand
from cms.models import CMSPlugin
class Command(NoArgsCommand):
help = 'Fixes plugins whose parent is in another placeholder'
def handle_noargs(self, **options):
plugins = CMSPlugin.objects.filter(parent__isnull=False).select_related('parent')
corrupt_plugins = {}
for plugin in plugins:
if plugin.placeholder_id != plugin.parent.placeholder_id:
self.stdout.write('%d is corrupted\n' % plugin.pk)
corrupt_plugins[plugin.pk] = plugin.parent.placeholder_id
self.stdout.write("Found %d corrupt plugins.\n" % len(corrupt_plugins))
for plugin, placeholder_id in corrupt_plugins.iteritems():
self.stdout.write("Updating plugin %d to have placeholder %d\n" % (plugin, placeholder_id))
CMSPlugin.objects.filter(pk=plugin).update(placeholder=placeholder_id)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment