Example #1
0
def mark_layer(site, event):
    """Mark the request with a layer corresponding to the current skin,
    as set in the portal_skins tool.
    """
    if getattr(event.request, "_plonetheme_", False):
        return
    event.request._plonetheme_=True

    portal_skins = getToolByName(site, 'portal_skins', None)
    if portal_skins is not None:
        skin_name = site.getCurrentSkinName()
        skin = queryUtility(IBrowserSkinType, name=skin_name)
        if skin is not None:
            layer_ifaces = []
            default_ifaces = []
            # We need to make sure IDefaultPloneLayer comes after
            # any other layers, even if they don't explicitly extend it.
            if IDefaultPloneLayer in skin.__iro__:
                default_ifaces += [IDefaultPloneLayer]
            for layer in directlyProvidedBy(event.request):
                if layer in default_layers:
                    default_ifaces.append(layer)
                elif IBrowserSkinType.providedBy(layer):
                    continue
                else:
                    layer_ifaces.append(layer)
            ifaces = [skin, ] + layer_ifaces + default_ifaces
            directlyProvides(event.request, *ifaces)
Example #2
0
def mark_layer(site, event):
    """Mark the request with a layer corresponding to the current skin,
    as set in the portal_skins tool.
    """
    if getattr(event.request, "_plonetheme_", False):
        return
    event.request._plonetheme_ = True

    portal_skins = getToolByName(site, 'portal_skins', None)
    if portal_skins is not None:
        skin_name = site.getCurrentSkinName()
        skin = queryUtility(IBrowserSkinType, name=skin_name)
        if skin is not None:
            layer_ifaces = []
            default_ifaces = []
            # We need to make sure IDefaultPloneLayer comes after
            # any other layers, even if they don't explicitly extend it.
            if IDefaultPloneLayer in skin.__iro__:
                default_ifaces += [IDefaultPloneLayer]
            for layer in directlyProvidedBy(event.request):
                if layer in default_layers:
                    default_ifaces.append(layer)
                elif IBrowserSkinType.providedBy(layer):
                    continue
                else:
                    layer_ifaces.append(layer)
            ifaces = [
                skin,
            ] + layer_ifaces + default_ifaces
            directlyProvides(event.request, *ifaces)
Example #3
0
    def publishTraverse(self, request, name):
        from euphorie.client.utils import setRequest
        setRequest(request)
        request.client = self.context
        if name == 'api':
            return access_api(request).__of__(self.context)

        ifaces = [iface for iface in directlyProvidedBy(request)
                  if not IBrowserSkinType.providedBy(iface)]
        directlyProvides(request, IOSHAClientSkinLayer, ifaces)
        return super(ClientPublishTraverser, self).publishTraverse(request, name)
Example #4
0
    def publishTraverse(self, request, name):
        from euphorie.client.utils import setRequest

        setRequest(request)
        request.client = self.context

        ifaces = [
            iface
            for iface in directlyProvidedBy(request)
            if not IBrowserSkinType.providedBy(iface)
        ]
        directlyProvides(request, IOSHAClientSkinLayer, ifaces)
        return super(ClientPublishTraverser, self).publishTraverse(request, name)
Example #5
0
def applySkin(request, skin):
    """Change the presentation skin for this request.

    >>> import pprint
    >>> from zope.interface import Interface
    >>> class SkinA(Interface): pass
    >>> directlyProvides(SkinA, IBrowserSkinType)
    >>> class SkinB(Interface): pass
    >>> directlyProvides(SkinB, IBrowserSkinType)
    >>> class IRequest(Interface): pass

    >>> class Request(object):
    ...     implements(IRequest)

    >>> req = Request()

    >>> applySkin(req, SkinA)
    >>> pprint.pprint(list(providedBy(req).interfaces()))
    [<InterfaceClass zope.publisher.browser.SkinA>,
     <InterfaceClass zope.publisher.browser.IRequest>]

    >>> applySkin(req, SkinB)
    >>> pprint.pprint(list(providedBy(req).interfaces()))
    [<InterfaceClass zope.publisher.browser.SkinB>,
     <InterfaceClass zope.publisher.browser.IRequest>]

    Changing the skin on a request triggers the ISkinChanged event:

    >>> import zope.component
    >>> from zope.publisher.interfaces.browser import ISkinChangedEvent
    >>> def receiveSkinEvent(event):
    ...     print event.request
    >>> zope.component.provideHandler(receiveSkinEvent, (ISkinChangedEvent,))
    >>> applySkin(req, SkinA)   # doctest: +ELLIPSIS
    <zope.publisher.browser.Request object at 0x...>

    Make sure our registrations go away again.

    >>> from zope.testing.cleanup import cleanUp
    >>> cleanUp()

    """
    # Remove all existing skin declarations (commonly the default skin).
    ifaces = [
        iface for iface in directlyProvidedBy(request)
        if not IBrowserSkinType.providedBy(iface)
    ]
    # Add the new skin.
    ifaces.append(skin)
    directlyProvides(request, *ifaces)
    zope.event.notify(SkinChangedEvent(request))
Example #6
0
def setskin(site, event):
    """Depending on the skin property set on the subsite we override the
    default skin.
    """
    storage = component.queryUtility(ISubsiteSkinStorage)
    if storage is None:
        return
    R = event.request
    path_info = R.PATH_INFO

    TRNS = R.TraversalRequestNameStack
    if len(TRNS) > 1 and 'virtual_hosting' in TRNS:
        idx = TRNS.index('virtual_hosting') - 1
        trnspath = TRNS[0:idx] + TRNS[idx + 2:]
        trnspath.reverse()
        path = "/".join(site.getPhysicalPath() + tuple(trnspath))
    else:
        path = path_info

    skinname = storage.get(path, None)

    if skinname is None:
        return

    site.changeSkin(skinname, R)
    # this section is copied from plone.theme.layer::mark_layer()
    skin = queryUtility(IBrowserSkinType, name=skinname)
    if skin is not None:
        layer_ifaces = []
        default_ifaces = []
        # We need to make sure IDefaultPloneLayer comes after
        # any other layers, even if they don't explicitly extend it.
        if IDefaultPloneLayer in skin.__iro__:
            default_ifaces += [IDefaultPloneLayer]
        for layer in directlyProvidedBy(event.request):
            if layer in default_layers:
                default_ifaces.append(layer)
            elif IBrowserSkinType.providedBy(layer):
                continue
            else:
                layer_ifaces.append(layer)
        ifaces = [skin, ] + layer_ifaces + default_ifaces
        directlyProvides(event.request, *ifaces)
Example #7
0
def change_skin(site, request):
    """ Change skin
    """
    skin_name = request.cookies.get('plone_skin')
    if not skin_name:
        skin_name = 'EEADesign2006'

    skin = queryUtility(IBrowserSkinType, name=skin_name)
    if skin is not None:
        layer_ifaces = []
        default_ifaces = []
        # We need to make sure IDefaultPloneLayer comes after
        # any other layers, even if they don't explicitly extend it.
        if IDefaultPloneLayer in skin.__iro__:
            default_ifaces += [IDefaultPloneLayer]
        for layer in directlyProvidedBy(request):
            if layer in default_layers:
                default_ifaces.append(layer)
            elif IBrowserSkinType.providedBy(layer):
                continue
            else:
                layer_ifaces.append(layer)
        ifaces = [skin] + layer_ifaces + default_ifaces
        directlyProvides(request, *ifaces)
Example #8
0
def change_skin(site, request):
    """ Change skin
    """
    skin_name = request.cookies.get('plone_skin')
    if not skin_name:
        skin_name = 'EEADesign2006'

    skin = queryUtility(IBrowserSkinType, name=skin_name)
    if skin is not None:
        layer_ifaces = []
        default_ifaces = []
        # We need to make sure IDefaultPloneLayer comes after
        # any other layers, even if they don't explicitly extend it.
        if IDefaultPloneLayer in skin.__iro__:
            default_ifaces += [IDefaultPloneLayer]
        for layer in directlyProvidedBy(request):
            if layer in default_layers:
                default_ifaces.append(layer)
            elif IBrowserSkinType.providedBy(layer):
                continue
            else:
                layer_ifaces.append(layer)
        ifaces = [skin] + layer_ifaces + default_ifaces
        directlyProvides(request, *ifaces)