Skip to content

Instantly share code, notes, and snippets.

@czpython
Created April 8, 2017 15:16
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/bacfd888e45b6713abb7395acd44ec1d to your computer and use it in GitHub Desktop.
Save czpython/bacfd888e45b6713abb7395acd44ec1d to your computer and use it in GitHub Desktop.
# -*- 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