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.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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file plone.browserlayer-1.0rc3.tar.gz.
File metadata
- Download URL: plone.browserlayer-1.0rc3.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
512b0ec94dbf6b97c879b0282ab3a1c4a26a556387a41527ba8c5ddef40bab39
|
|
| MD5 |
13d8e3028d960826eceb3e166dea060d
|
|
| BLAKE2b-256 |
50a07dcdb4f0aabee3074aa9ab145f2336abf78544349ea9cb02759815a478bb
|
File details
Details for the file plone.browserlayer-1.0rc3-py2.4.egg.
File metadata
- Download URL: plone.browserlayer-1.0rc3-py2.4.egg
- Upload date:
- Size: 18.8 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8d5024281b162cc34c5379f8e6589754602de6a6e13da86ef30af50819a3b417
|
|
| MD5 |
41b6fd6cf99e893758f6b13649154228
|
|
| BLAKE2b-256 |
d8cda2c189511e61b41e091692ad638d7b5620d7d976b096bad24df447779da7
|