Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
# -*- 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
You can’t perform that action at this time.