Skip to main content

Browser layer management for Zope 2 applications

Project description

Introduction

This package aims to make it easier to register visual components (e.g. views and viewlets) so that they only show up in a Plone site where they have been explicitly installed.

It requires GenericSetup 1.4 later.

Basic usage

To use this feature, you should:

  • declare plone.browserlayer as a dependency, e.g. in setup.py:

    install_requires=[
          'plone.browserlayer',
      ],
  • ensure that its ZCML is loaded, e.g. with an include from your own package:

    <include package="plone.browserlayer" />
  • create a layer marker interface unique to your product:

    from zope.interface import Interface
    class IMyProductLayer(Interface):
        """A layer specific to my product
        """
  • register this with GenericSetup, in a browserlayer.xml file:

    <layers>
        <layer name="my.product"
               interface="my.product.interfaces.IMyProductLayer" />
    </layers>
  • register visual components in ZCML for this layer, e.g.:

    <browser:page
        name="my-view"
        for="*"
        layer=".interfaces.IMyProductLayer"
        permission="zope.Public"
        template="my-view.pt"
        />

No seriously, it works, just look here

In testing.zcml we have registered a view, layer-test-view, available only for the layer plone.browserlayer.tests.interfaces.IMyProductLayer.

Before the product is installed, we cannot view this:

>>> from plone.browserlayer.tests.interfaces import IMyProductLayer
>>> from plone.browserlayer import utils
>>> IMyProductLayer in utils.registered_layers()
False
>>> from Products.Five.testbrowser import Browser
>>> browser = Browser()
>>> browser.open(self.portal.absolute_url() + '/@@layer-test-view')
Traceback (most recent call last):
...
HTTPError: HTTP Error 404: Not Found

We can view a view registered for the default layer, though:

>>> browser.open(self.portal.absolute_url() + '/@@standard-test-view')
>>> print browser.contents
A standard view

However, if we install the product the interface is registered in the local site manager. Here we use the utility method directly, though we could also use GenericSetup.

>>> utils.register_layer(IMyProductLayer, name='my.product')
>>> IMyProductLayer in utils.registered_layers()
True

And if we now traverse over the site root and render the view, it should be there.

>>> browser.open(self.portal.absolute_url() + '/@@layer-test-view')
>>> print browser.contents
A local view

Unlike when applying a new skin, layers installed in this way do not override views registered for the default layer.

>>> browser.open(self.portal.absolute_url() + '/@@standard-test-view')
>>> print browser.contents
A standard view

It is also possible to uninstall a layer:

>>> IMyProductLayer in utils.registered_layers()
True
>>> utils.unregister_layer(name='my.product')
>>> IMyProductLayer in utils.registered_layers()
False
>>> browser.open(self.portal.absolute_url() + '/@@layer-test-view')
Traceback (most recent call last):
...
HTTPError: HTTP Error 404: Not Found

GenericSetup support

Most of the time, you will be registering layers using GenericSetup. Here is how that looks.

>>> from Products.CMFCore.utils import getToolByName
>>> portal_setup = getToolByName(self.portal, 'portal_setup')

We should be able to install our product’s profile. For the purposes of this test, the profile is defined in tests/profiles/default/testing and registered in testing.zcml. It has a file called browserlayer.xml which contains:

<layers>
    <layer name="plone.browserlayer.tests"
           interface="plone.browserlayer.tests.interfaces.IMyProductLayer" />
</layers>

Let’s import it:

>>> IMyProductLayer in utils.registered_layers()
False
>>> _ = portal_setup.runAllImportStepsFromProfile('profile-plone.browserlayer:testing')
>>> IMyProductLayer in utils.registered_layers()
True

And just to prove that everything still works:

>>> browser.open(self.portal.absolute_url() + '/@@layer-test-view')
>>> print browser.contents
A local view
>>> browser.open(self.portal.absolute_url() + '/@@standard-test-view')
>>> print browser.contents
A standard view

Changelog

1.0.0 - April 20th 2008

  • Unchanged from 1.0rc4

1.0rc4

  • Register the GenericSetup import and export steps using zcml. This means you will no longer need to install this package manually. [wichert]

1.0rc3

  • Include README.txt and HISTORY.txt in the package’s long description. [wichert]

  • Add metadata.xml to the GenericSetup profile. This fixes a deprecation warning for Plone 3.1 and later. [wichert]

1.0b1

  • Initial package structure. [zopeskel]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plone.browserlayer-1.0.0.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plone.browserlayer-1.0.0-py2.4.egg (17.3 kB view details)

Uploaded Egg

File details

Details for the file plone.browserlayer-1.0.0.tar.gz.

File metadata

File hashes

Hashes for plone.browserlayer-1.0.0.tar.gz
Algorithm Hash digest
SHA256 95b6d1c3ad445f00092dadf425d09a25d8866b78467de1e8c7f1d0cf6b1fb24c
MD5 392478f8ff4f581db34c1dcd9df89a79
BLAKE2b-256 cf54b3023b23c48d824b1dcc3890f6def467f2b982a90ae105477497245da43d

See more details on using hashes here.

File details

Details for the file plone.browserlayer-1.0.0-py2.4.egg.

File metadata

File hashes

Hashes for plone.browserlayer-1.0.0-py2.4.egg
Algorithm Hash digest
SHA256 11b49a19ac757db8442e876ca747e384457c2131e6ccca9484a8322daa1fdb2e
MD5 36291dc9844d68219f78525678837068
BLAKE2b-256 06104b15d60992672ac191bb18061005f814e2564b4dcf950be23900961f7043

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page