def create_ttw_layout_examples(portal):
    request = getRequest()
    alsoProvides(request, IMosaicLayer)

    sitelayout = getPersistentResourceDirectory(SITE_LAYOUT_RESOURCE_NAME)
    custom = getPersistentResourceDirectory('custom', sitelayout)
    custom.writeFile(MANIFEST_FILENAME, StringIO("""\
[sitelayout]
title = Plone layout (Custom)
description = TTW customizable default layout
file = site.html
"""))
    custom.writeFile(
        'site.html',
        StringIO(resolveResource('++sitelayout++default/default.html')
                 .encode('utf-8'))
    )

    contentlayout = getPersistentResourceDirectory(CONTENT_LAYOUT_RESOURCE_NAME)
    custom = getPersistentResourceDirectory('custom', contentlayout)
    custom.writeFile(MANIFEST_FILENAME, StringIO("""\
[contentlayout]
title = Basic layout (Custom)
description = TTW customizable content layout
file = content.html
"""))
    custom.writeFile(
        'content.html',
        StringIO(resolveResource('++contentlayout++default/basic.html')
                 .encode('utf-8'))
    )
def create_ttw_layout_examples(portal):
    request = getRequest()
    alsoProvides(request, IMosaicLayer)

    sitelayout = getPersistentResourceDirectory(SITE_LAYOUT_RESOURCE_NAME)
    custom = getPersistentResourceDirectory('custom', sitelayout)
    custom.writeFile(MANIFEST_FILENAME, StringIO("""\
[sitelayout]
title = Plone layout (Custom)
description = TTW customizable default layout
file = site.html
"""))
    custom.writeFile(
        'site.html',
        StringIO(resolveResource('++sitelayout++default/default.html')
                 .encode('utf-8'))
    )

    contentlayout = getPersistentResourceDirectory(CONTENT_LAYOUT_RESOURCE_NAME)
    custom = getPersistentResourceDirectory('custom', contentlayout)
    custom.writeFile(MANIFEST_FILENAME, StringIO("""\
[contentlayout]
title = Basic layout (Custom)
description = Default content layout
file = basic.html

[contentlayout]
title = Document layout (Custom)
description = Default document layout
file = document.html

[contentlayout]
title = Event layout (Custom)
description = Default event layout
file = event.html
"""))
    custom.writeFile(
        'basic.html',
        StringIO(resolveResource('++contentlayout++default/basic.html')
                 .encode('utf-8'))
    )
    custom.writeFile(
        'document.html',
        StringIO(resolveResource('++contentlayout++default/document.html')
                 .encode('utf-8'))
    )
    custom.writeFile(
        'event.html',
        StringIO(resolveResource('++contentlayout++default/event.html')
                 .encode('utf-8'))
    )
Exemple #3
0
def setDefaultLayoutForNewPage(obj, event):
    """When a new page is created, set its layout based on the default in
    the FTI
    """
    
    layoutAware = ILayoutAware(obj, None)
    if layoutAware is None:
        return
    
    # Initialise object
    layoutAware.content = ILayoutAware['content'].missing_value
    layoutAware.pageSiteLayout = ILayoutAware['pageSiteLayout'].missing_value
    layoutAware.sectionSiteLayout = ILayoutAware['sectionSiteLayout'].missing_value
    
    portal_type = obj.portal_type
    template = getDefaultPageLayout(portal_type)
    
    if template is None:
        raise ValueError("Cannot find layout template for %s" % portal_type)
    
    templatePath = urlparse.urljoin(obj.absolute_url_path(), template)
    
    try:
        layoutAware.content = resolveResource(templatePath)
    except:
        LOGGER.exception("Could not resolve default page layout %s" % portal_type)
def create_ttw_site_layout_examples(portal):
    request = portal.REQUEST
    alsoProvides(request, IMosaicLayer)
    sitelayout = getPersistentResourceDirectory(SITE_LAYOUT_RESOURCE_NAME)
    custom = getPersistentResourceDirectory('custom', sitelayout)
    custom.writeFile(MANIFEST_FILENAME, EXAMPLE_SITE_LAYOUT)
    custom.writeFile(
        'site.html',
        resolveResource('++sitelayout++default/default.html').encode('utf-8'),
    )
    def __call__(self):
        """Render the contents of the "content" field coming from
        the ILayoutAware behavior.

        This result is supposed to be transformed by plone.app.blocks.
        """
        behavior_data = ILayoutAware(self.context)
        if behavior_data.contentLayout:
            from plone.app.blocks.utils import resolveResource
            try:
                path = behavior_data.contentLayout
                resolved = resolveResource(path)
                layout = applyTilePersistent(path, resolved)
            except (NotFound, RuntimeError):
                layout = ''
        else:
            layout = behavior_data.content

        if not layout:
            from plone.app.blocks.utils import resolveResource
            registry = getUtility(IRegistry)
            try:
                path = registry['%s.%s' % (
                    DEFAULT_CONTENT_LAYOUT_REGISTRY_KEY,
                    self.context.portal_type.replace(' ', '-'))]
            except (KeyError, AttributeError):
                path = None
            try:
                path = path or registry[DEFAULT_CONTENT_LAYOUT_REGISTRY_KEY]
                resolved = resolveResource(path)
                layout = applyTilePersistent(path, resolved)
            except (KeyError, NotFound, RuntimeError):
                pass

        if not layout:
            layout = ERROR_LAYOUT

        # Here we skip legacy portal_transforms and call plone.outputfilters
        # directly by purpose
        filters = [f for _, f
                   in getAdapters((self.context, self.request), IFilter)]
        return apply_filters(filters, layout)
Exemple #6
0
 def content_layout(self):
     """Returns the content HTML layout.
     """
     layout = None
     path = self.content_layout_path()
     try:
         resolved = resolveResource(path)
         layout = applyTilePersistent(path, resolved)
     except (NotFound, RuntimeError, IOError):
         pass
     return layout
def create_ttw_content_layout_examples(portal):
    request = portal.REQUEST
    alsoProvides(request, IMosaicLayer)
    contentlayout = getPersistentResourceDirectory(
        CONTENT_LAYOUT_RESOURCE_NAME)
    custom = getPersistentResourceDirectory('custom', contentlayout)
    custom.writeFile(MANIFEST_FILENAME, StringIO(EXAMPLE_CONTENT_LAYOUT))
    custom.writeFile(
        'basic.html',
        StringIO(
            resolveResource('++contentlayout++default/basic.html').encode(
                'utf-8')))
 def content_layout(self):
     """Returns the content HTML layout.
     """
     layout = None
     path = self.content_layout_path()
     try:
         resolved = resolveResource(path)
         if isinstance(resolved, six.text_type):
             resolved = resolved.encode('utf-8')
         layout = applyTilePersistent(path, resolved)
     except (NotFound, RuntimeError, IOError):
         pass
     return layout
def create_ttw_site_layout_examples(portal):
    request = portal.REQUEST
    alsoProvides(request, IMosaicLayer)
    sitelayout = getPersistentResourceDirectory(SITE_LAYOUT_RESOURCE_NAME)
    custom = getPersistentResourceDirectory('custom', sitelayout)
    custom.writeFile(MANIFEST_FILENAME, StringIO(EXAMPLE_SITE_LAYOUT))
    custom.writeFile(
        'site.html',
        StringIO(
            resolveResource(
                '++sitelayout++default/default.html'
            ).encode('utf-8')
        )
    )
Exemple #10
0
 def __call__(self):
     layout = self._getLayout()
     if layout is None:
         raise NotFound("No default site layout set")
     
     pathContext = self.context
     while not ITraversable.providedBy(pathContext):
         pathContext = aq_parent(pathContext)
         if pathContext is None:
             break
     
     path = layout
     if pathContext is not None:
         path = urlparse.urljoin(pathContext.absolute_url_path(), layout)
     
     return resolveResource(path)
def getPortalTypeDefaultContentLayoutContent(portal_type):
    types_tool = api.portal.get_tool('portal_types')
    fti = getattr(types_tool, portal_type, None)
    if fti is None:
        return u''

    aliases = fti.getMethodAliases() or {}
    layout = absolute_path(aliases.get(CONTENT_LAYOUT_DEFAULT_DISPLAY,
                                       CONTENT_LAYOUT_DEFAULT_LAYOUT))

    if layout:
        try:
            return resolveResource(layout)
        except NotFound as e:
            logger.warning('Missing layout {0:s}'.format(e))
    return u''
Exemple #12
0
    def __call__(self):
        layout = self._getLayout()
        if layout is None:
            raise NotFound("No default site layout set")

        pathContext = self.context
        while not ITraversable.providedBy(pathContext):
            pathContext = aq_parent(pathContext)
            if pathContext is None:
                break

        path = layout
        if pathContext is not None:
            path = urlparse.urljoin(pathContext.absolute_url_path(), layout)

        return resolveResource(path)
def create_ttw_content_layout_examples(portal):
    request = portal.REQUEST
    alsoProvides(request, IMosaicLayer)
    contentlayout = getPersistentResourceDirectory(
        CONTENT_LAYOUT_RESOURCE_NAME
    )
    custom = getPersistentResourceDirectory('custom', contentlayout)
    custom.writeFile(MANIFEST_FILENAME, StringIO(EXAMPLE_CONTENT_LAYOUT))
    custom.writeFile(
        'basic.html',
        StringIO(
            resolveResource(
                '++contentlayout++default/basic.html'
            ).encode('utf-8')
        )
    )
Exemple #14
0
    def template(self):
        if self.request.form.get('ajax_load'):
            layout_resource_path = getDefaultAjaxLayout(self.context)
        else:
            layout_resource_path = getDefaultSiteLayout(self.context)

        if layout_resource_path is None:
            return self.main_template
        try:
            layout = resolveResource(layout_resource_path)
        except NotFound as e:
            logger.warning('Missing layout {0:s}'.format(e))

        cooked = cook_layout(layout)
        pt = PageTemplate()
        pt.write(cooked)
        return pt
Exemple #15
0
def getPortalTypeDefaultContentLayoutContent(portal_type):
    types_tool = api.portal.get_tool('portal_types')
    fti = getattr(types_tool, portal_type, None)
    if fti is None:
        return u''

    aliases = fti.getMethodAliases() or {}
    layout = absolute_path(
        aliases.get(CONTENT_LAYOUT_DEFAULT_DISPLAY,
                    CONTENT_LAYOUT_DEFAULT_LAYOUT))

    if layout:
        try:
            return resolveResource(layout)
        except NotFound as e:
            logger.warning('Missing layout {0:s}'.format(e))
    return u''
def create_ttw_site_layout_examples(portal):
    request = getRequest()
    alsoProvides(request, IMosaicLayer)

    sitelayout = getPersistentResourceDirectory(SITE_LAYOUT_RESOURCE_NAME)
    custom = getPersistentResourceDirectory('custom', sitelayout)
    custom.writeFile(
        MANIFEST_FILENAME,
        StringIO("""\
[sitelayout]
title = Plone layout (Custom)
description = Example site layout
file = site.html
"""))
    custom.writeFile(
        'site.html',
        StringIO(
            resolveResource('++sitelayout++default/default.html').encode(
                'utf-8')))
def getDefaultContentLayoutContent(adapter):
    portal_type = getattr(getattr(
        adapter.view, '__parent__', adapter.view), 'portal_type', None)
    if not portal_type:
        return u''

    types_tool = getToolByName(adapter.context, 'portal_types')
    fti = getattr(types_tool, portal_type, None)
    if fti is None:
        return u''

    aliases = fti.getMethodAliases() or {}
    layout = aliases.get('++layout++default')

    if layout:
        try:
            return resolveResource(layout)
        except NotFound as e:
            logger.warning('Missing layout {0:s}'.format(e))
    return u''
Exemple #18
0
def getDefaultContentLayoutContent(adapter):
    portal_type = getattr(getattr(adapter.view, '__parent__', adapter.view),
                          'portal_type', None)
    if not portal_type:
        return u''

    types_tool = getToolByName(adapter.context, 'portal_types')
    fti = getattr(types_tool, portal_type, None)
    if fti is None:
        return u''

    aliases = fti.getMethodAliases() or {}
    layout = aliases.get('++layout++default')

    if layout:
        try:
            return resolveResource(layout)
        except NotFound as e:
            logger.warning('Missing layout {0:s}'.format(e))
    return u''
def create_ttw_content_layout_examples(portal):
    request = getRequest()
    alsoProvides(request, IMosaicLayer)

    contentlayout = getPersistentResourceDirectory(
        CONTENT_LAYOUT_RESOURCE_NAME)
    custom = getPersistentResourceDirectory('custom', contentlayout)
    custom.writeFile(
        MANIFEST_FILENAME,
        StringIO("""\
[contentlayout]
title = Basic (Custom)
description = Example content layout
file = basic.html
"""))
    custom.writeFile(
        'basic.html',
        StringIO(
            resolveResource('++contentlayout++default/basic.html').encode(
                'utf-8')))
def layoutFieldDefaultValue(context, request):
    # XXX: Context cannot be used yet, because plone.dexterity does not
    # bound fields to support context aware default factories
    layout = absolute_path(CONTENT_LAYOUT_DEFAULT_LAYOUT)

    # XXX: This is a workaround for a subrequest bug, where parent_app
    # ends up being a view with publishTraverse returning always NotFound.
    try:
        parent_app = request.PARENTS[-1]
        if IWidgetsView.providedBy(parent_app):
            return u''
    except AttributeError:
        pass
    except IndexError:
        pass

    try:
        return resolveResource(layout)
    except NotFound:
        return u''
def getDefaultContentLayoutContent(adapter):
    portal_type = getattr(getattr(
        adapter.view, '__parent__', adapter.view), 'portal_type', None)
    if portal_type is None:
        return u''

    types_tool = getToolByName(adapter.context, 'portal_types')
    fti = getattr(types_tool, portal_type, None)
    if fti is None:
        return u''

    aliases = fti.getMethodAliases() or {}
    layout = absolute_path(aliases.get(CONTENT_LAYOUT_DEFAULT_DISPLAY,
                                       CONTENT_LAYOUT_DEFAULT_LAYOUT))

    if layout:
        try:
            return resolveResource(layout)
        except NotFound as e:
            logger.warning('Missing layout {0:s}'.format(e))
    return u''
 def layout(self):
     published = self.request.get('PUBLISHED')
     if isinstance(published, DefaultAddView):
         # Handle the special case of DX add form of layout aware context
         layout = None
         adapter = ILayoutAware(self.context, None)
         if adapter is not None:
             if getattr(adapter, 'sectionSiteLayout', None):
                 layout = adapter.sectionSiteLayout
         if layout:
             layout = urljoin(self.context.absolute_url_path(), layout)
             layout = resolveResource(layout)
         if not layout:
             layout = getMultiAdapter((self.context, self.request),
                                      name='default-site-layout').index()
     else:
         layout = getMultiAdapter((self.context, self.request),
                                  name='page-site-layout').index()
     cooked = cook_layout(layout, self.request.get('ajax_load'))
     pt = ViewPageTemplateString(cooked)
     bound_pt = pt.__get__(self, type(self))
     return bound_pt
 def layout(self):
     published = self.request.get('PUBLISHED')
     if isinstance(published, DefaultAddView):
         # Handle the special case of DX add form of layout aware context
         layout = None
         adapter = ILayoutAware(self.context, None)
         if adapter is not None:
             if getattr(adapter, 'sectionSiteLayout', None):
                 layout = adapter.sectionSiteLayout
         if layout:
             layout = urljoin(self.context.absolute_url_path(), layout)
             layout = resolveResource(layout)
         if not layout:
             layout = getMultiAdapter((self.context, self.request),
                                      name='default-site-layout').index()
     else:
         layout = getMultiAdapter((self.context, self.request),
                                  name='page-site-layout').index()
     cooked = cook_layout(layout, self.request.get('ajax_load'))
     pt = ViewPageTemplateString(cooked)
     bound_pt = pt.__get__(self, type(self))
     return bound_pt
Exemple #24
0
def layoutFieldDefaultValue(context, request):
    if context and ILayoutAware(context, None):
        return getPortalTypeDefaultContentLayoutContent(context.portal_type)

    # XXX: Context cannot be used yet, because plone.dexterity does not
    # bound fields to support context aware default factories
    layout = absolute_path(CONTENT_LAYOUT_DEFAULT_LAYOUT)

    # XXX: This is a workaround for a subrequest bug, where parent_app
    # ends up being a view with publishTraverse returning always NotFound.
    try:
        parent_app = request.PARENTS[-1]
        if IWidgetsView.providedBy(parent_app):
            return u''
    except AttributeError:
        pass
    except IndexError:
        pass

    try:
        return resolveResource(layout)
    except NotFound:
        return u''
Exemple #25
0
 def index(self):
     return resolveResource(self.layout)
Exemple #26
0
 def test_resolve_resource(self):
     layout = resolveResource('/++sitelayout++testlayout1/site.html')
     self.assertIn(u'Layout panel 1', layout)
Exemple #27
0
 def test_resolve_resource_with_query(self):
     layout = resolveResource('/++sitelayout++testlayout1/site.html?ajax_load=1')
     self.assertIn(u'Layout panel 1', layout)
Exemple #28
0
 def index(self):
     return resolveResource(self.layout)
 def __call__(self):
     try:
         return resolveResource(self.resource_path)
     except NotFound as e:
         logger.warning('Missing layout {0:s}'.format(e))
         raise
Exemple #30
0
 def __call__(self):
     try:
         return resolveResource(self.resource_path)
     except NotFound as e:
         logger.warning('Missing layout {0:s}'.format(e))
         raise