'Ensure that the public pages look the same as their draft versions.
This is done by checking the content of the public pages, and reverting
the draft version to look the same.
The second stage is to go through the draft pages and publish the ones
marked as published.
The end result should be that the public pages and their draft versions
have the same plugins listed. If both versions exist and have content,
the public page has precedence. Otherwise, the draft version is used.'

def handle(self, *args, **options):

    log.info(u'Reverting    drafts    to    public    versions')
    for page in Page.objects.public():
        for language in page.get_languages():
            if CMSPlugin.objects.filter(placeholder__page=page, language=language).exists():
                log.debug((u'Reverting    page    pk=%d' % (page.pk,)))
                page.publisher_draft.revert_to_live(language)
    log.info(u'Publishing    all    published    drafts')
    for title in Title.objects.filter(publisher_is_draft=True, publisher_public_id__gt=0):
        try:
            title.page.publish(title.language)
            log.debug((u'Published    page    pk=%d    in    %s' % (page.pk, title.language)))
        except Exception:
            log.exception((u'Error    publishing    page    pk=%d    in    %s' % (page.pk, title.language)))
