Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# -*- coding: utf-8 -*-
from import NoArgsCommand
from cms.models import CMSPlugin
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:
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