import logging
from wagtail_commons.core.management.commands.bootstrap_content import load_attributes_from_file, SiteNode
import os

from django.conf import settings
from wagtail.wagtailcore.models import Page, Site

__author__ = 'bgrace'

logger = logging.getLogger('wagtail_commons.core')


def live_preview(request):

    try:
        if u'/' == request.path:
            page = Site.find_for_request(request).root_page.specific
        else:
            logger.info("path: %s", '//'+request.path)
            page = Page.objects.get(url_path='//'+request.path).specific
    except Page.DoesNotExist:
        return {}

    content_file = os.path.join(settings.BOOTSTRAP_CONTENT_DIR, 'pages', request.path.strip('/') + '.yml')
    if not os.path.isfile(content_file):
        return {}

    content_attributes = load_attributes_from_file(content_file)
    SiteNode.set_page_attributes(page, content_attributes)

    return {'self': page}


@@ -114,16 +114,45 @@
 SiteNode
+, %5C%0A    get_relation_mappings
 %0Aimport 
@@ -881,65 +881,268 @@
 le)%0A
-    SiteNode.set_page_attributes(page, content_attributes
+%0A    try:%0A        del content_attributes%5B'type'%5D%0A    except KeyError:%0A        pass%0A%0A    SiteNode.set_page_attributes(page, content_attributes,%0A                                 get_relation_mappings(os.path.join(settings.BOOTSTRAP_CONTENT_DIR, 'relations.yml'))
 )%0A%0A 

Improve markdown preview