Skip to main content

gocept.pagelet

Easier z3c.pagelet handling

Copyright (c) 2007-2016 gocept gmbh & co. kg All Rights Reserved.

This software is subject to the provisions of the Zope Public License, Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution. THIS SOFTWARE IS PROVIDED “AS IS” AND ANY AND ALL EXPRESS OR IMPLIED WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS FOR A PARTICULAR PURPOSE.

Changes

2.1 (2025-10-24)

  • Replace pkg_resources with pep420 namespace package.

2.0 (2023-07-18)

  • Drop support for Python 2.7, 3.5, 3.6.

  • Add support for Python 3.9, 3.10, 3.11.

1.1 (2019-06-10)

  • Claim support of Python 3.5, 3.6, 3.7, 3.8, PyPy and PyPy3.

  • Use tox for testing.

1.0 (2016-04-06)

  • Update bootstrap.py to a zc.buildout 2.3.

  • Use py.test as test runner.

  • Declare the explicit support of Python 2.7. No other Python versions are currently supported.

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

Metadata

Release files for gocept.pagelet 2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gocept.pagelet 2.1
File Size Uploaded
gocept_pagelet-2.1.tar.gz 9.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gocept.pagelet 2.1
File Interpreter ABI Platform
gocept_pagelet-2.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 18.3 kB

Release files / gocept_pagelet-2.1.tar.gz

Download URL gocept_pagelet-2.1.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
9fbe68b14949cf32442f0fe998bf4e0c11da2ad076e0d74b294938566ea22e71
BLAKE2b-256 checksum
How to use checksums
572fcd9df4279566b10611eecc2e3429b7f5bf91dab35de375375edca639c24e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release files / gocept_pagelet-2.1-py2.py3-none-any.whl

Download URL gocept_pagelet-2.1-py2.py3-none-any.whl
Size 9.1 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
2e6515fc5968ac2e797e9df21aaef0b1e3945a6e6d10125a9ccd0488d2c4e91f
BLAKE2b-256 checksum
How to use checksums
3711d84123eeed105e663069a354d77e4f9ba648be443b870d4f6f222868950b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.9

Release history Release notifications | RSS feed

This release

2.1 This release

2 release files

2.0

2 release files

1.1

1 release file

1.0

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

0.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page