def plugin_report():
    """
    Returns a report of existing plugins

    structure of report:
    [
        {
            'type': CMSPlugin class,
            'model': plugin_type.model,
            'instances': instances in the CMSPlugin table,
            'unsaved_instances': those with no corresponding model instance,
        },
    ]
    """
    plugin_report = []
    all_plugins = CMSPlugin.objects.order_by('plugin_type')
    plugin_types = list(set(all_plugins.values_list('plugin_type', flat=True)))
    plugin_types.sort()

    for plugin_type in plugin_types:
        plugin = {}
        plugin['type'] = plugin_type
        try:
            # get all plugins of this type
            plugins = CMSPlugin.objects.filter(plugin_type=plugin_type)
            plugin['instances'] = plugins
            # does this plugin have a model? report unsaved instances
            plugin['model'] = plugin_pool.get_plugin(name=plugin_type).model
            unsaved_instances = [p for p in plugins if not p.get_plugin_instance()[0]]
            plugin['unsaved_instances'] = unsaved_instances

        # catch uninstalled plugins
        except __HOLE__:
            plugin['model'] = None
            plugin['instances'] = plugins
            plugin['unsaved_instances'] = []

        plugin_report.append(plugin)

    return plugin_report
dataset/ETHPy150Open divio/django-cms/cms/management/commands/subcommands/list.py/plugin_report