def handle(self, *args, **options):
        urls = list(
            Page.objects.exclude(application_urls='').exclude(
                application_urls__isnull=True
            ).values_list(
                'application_urls', 'publisher_is_draft', 'application_namespace'
            )
        )
        apphooks = {}
        for apphook, is_draft, application_namespace in urls:
            state = 'draft' if is_draft else 'published'
            if apphook in apphooks:
                apphooks[apphook][0].append(state)
            else:
                apphooks[apphook] = [[state], application_namespace]
        for apphook, attributes in apphooks.items():
            attributes[0].sort()
            if attributes[1]:
                self.stdout.write('{0}[instance: {1}] ({2})\n'.format(
                    apphook, attributes[1], '/'.join(attributes[0])
                ))
            else:
                self.stdout.write('{0} ({1})\n'.format(
                    apphook, '/'.join(attributes[0])
                ))
dataset/ETHPy150Open divio/django-cms/cms/management/commands/subcommands/list.py/ListApphooksCommand.handle/original