Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install gocept.pagelet

How to install gocept.pagelet

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install gocept.pagelet
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.3
0.4Never BuiltWhy not?
0.3 Available View build log
Windows (64-bit)
0.3
0.4Never BuiltWhy not?
0.3 Available View build log
Mac OS X (10.5+)
0.3
0.4Never BuiltWhy not?
0.3 Available View build log
Linux (32-bit)
0.3
0.4Never BuiltWhy not?
0.3 Available View build log
Linux (64-bit)
0.4 Available View build log
0.3 Available View build log
 
License
ZPL 2.1
Depended by
Lastest release
version 0.4 on Jan 9th, 2014

Changes

0.4 (2013-03-28)
  • When registering a pagelet using ZCML which only has template, the name of the template is rendered in the repr the generated class to have a clue what is the purpose of this class when debugging.
  • Updated tests to use Python's doctest instead of deprecated zope.testing.doctest.
0.3 (2009-12-27)
  • Using zope.browserpage and zope.browsermenu instead of zope.app.publisher.
0.2 (2009-12-27)
  • Allow arbitrary number of context elements for adaptation.
0.1 (2008-09-20)
  • First public release.

Contributors

  • Michael Howitz <mh at gocept dot com>
  • Christian Theune <ct at gocept dot com>

Easy z3c.pagelet registration

The <gocept:pagelet> directive allows easier registration of z3c.pagelets. It behaves quite like <browser:page>.

Setup

We need some zcml setup:

>>> import sys
>>> from zope.configuration import xmlconfig
>>> import gocept.pagelet
>>> context = xmlconfig.file('meta.zcml', gocept.pagelet)
Template only

It is possible to just use a template as pagelet. A class is not required:

>>> context = xmlconfig.string("""
... <configure
...     xmlns:gocept="http://namespaces.gocept.com/zcml">
...   <gocept:pagelet
...       name="index.html"
...       for="*"
...       permission="zope.Public"
...       template="test-template.pt"
...       />
... </configure>
... """, context)

We should now have a page:

>>> import zope.component
>>> from zope.publisher.browser import TestRequest
>>> pagelet = zope.component.getMultiAdapter(
...     (object, TestRequest()), name='index.html')
>>> pagelet
<gocept.pagelet.zcml.SimplePagelet from .../gocept/pagelet/test-template.pt object at 0x...>
>>> pagelet.__name__
u'index.html'

When we render the pagelet the test-template is used:

>>> pagelet.render()
u'Hello from the test template.\n'
Class only

Of course it's also possible to register a class without a template. Create a class and make it available in a module:

>>> from z3c.pagelet.browser import BrowserPagelet
>>> class MyPagelet(BrowserPagelet):
...     """Custom pagelet"""
...     def render(self):
...         return u"Hello from the custom pagelet."""

Make it available under the fake package custom:

>>> sys.modules['custom'] = type(
...     'Module', (),
...     {'MyPagelet': MyPagelet})()

Make it available via ZCML:

>>> context = xmlconfig.string("""
... <configure
...     xmlns:gocept="http://namespaces.gocept.com/zcml">
...   <gocept:pagelet
...       name="class.html"
...       for="*"
...       permission="zope.Public"
...       class="custom.MyPagelet"
...       />
... </configure>
... """, context)

Get the pagelet:

>>> pagelet = zope.component.getMultiAdapter(
...     (object, TestRequest()), name='class.html')
>>> pagelet
<gocept.pagelet.zcml.MyPagelet object at 0x...>
>>> pagelet.render()
u'Hello from the custom pagelet.'
Class and template

It's for course also possible to specify both class and template. So create another pagelet class and register it:

>>> class MyPagelet2(BrowserPagelet):
...     """Custom pagelet"""
...     i_am_very_custom = True
>>> sys.modules['custom'] = type(
...     'Module', (),
...     {'MyPagelet': MyPagelet2})()

Make it available via zcml:

>>> context = xmlconfig.string("""
... <configure
...     xmlns:gocept="http://namespaces.gocept.com/zcml">
...   <gocept:pagelet
...       name="class-template.html"
...       for="*"
...       permission="zope.Public"
...       class="custom.MyPagelet"
...       template="test-template.pt"
...       />
... </configure>
... """, context)
>>> pagelet = zope.component.getMultiAdapter(
...     (object, TestRequest()), name='class-template.html')
>>> pagelet
<gocept.pagelet.zcml.MyPagelet2 object at 0x...>
>>> pagelet.render()
u'Hello from the test template.\n'
>>> pagelet.i_am_very_custom
True

Subscribe to package updates

Last updated Jan 9th, 2014

Download Stats

Last month:6

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.