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
MESSAGE = """
Found {} corrupt plugins.
Here's their ids:
{}
"""
class Command(NoArgsCommand):
help = 'Finds plugins whose numchild field is incorrect.'
def handle_noargs(self, **options):
corrupt_plugins = []
plugins = CMSPlugin.objects.values_list('pk', 'numchild').iterator()
plugin_lookup = CMSPlugin.objects.filter
for plugin_id, numchild in plugins:
count = plugin_lookup(parent=plugin_id).count()
if numchild != count:
corrupt_plugins.append(unicode(plugin_id))
self.stdout.write("Found corrupt plugins. %s \n" % plugin_id)
self.stdout.write("Found %d corrupt plugins.\n" % len(corrupt_plugins))
self.stdout.write(MESSAGE.format(len(corrupt_plugins), '\n'.join(corrupt_plugins))
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.