[Checkins] SVN: z3ext.layout/tags/1.5.6/ release tag
Nikolay Kim
fafhrd at datacom.kz
Thu Nov 6 04:24:51 EST 2008
Log message for revision 92804:
release tag
Changed:
A z3ext.layout/tags/1.5.6/
D z3ext.layout/tags/1.5.6/CHANGES.txt
A z3ext.layout/tags/1.5.6/CHANGES.txt
D z3ext.layout/tags/1.5.6/setup.py
A z3ext.layout/tags/1.5.6/setup.py
D z3ext.layout/tags/1.5.6/src/z3ext/layout/pagelet.txt
A z3ext.layout/tags/1.5.6/src/z3ext/layout/pagelet.txt
D z3ext.layout/tags/1.5.6/src/z3ext/layout/zcml.py
A z3ext.layout/tags/1.5.6/src/z3ext/layout/zcml.py
-=-
Copied: z3ext.layout/tags/1.5.6 (from rev 92788, z3ext.layout/trunk)
Deleted: z3ext.layout/tags/1.5.6/CHANGES.txt
===================================================================
--- z3ext.layout/trunk/CHANGES.txt 2008-11-05 00:03:57 UTC (rev 92788)
+++ z3ext.layout/tags/1.5.6/CHANGES.txt 2008-11-06 09:24:50 UTC (rev 92804)
@@ -1,153 +0,0 @@
-=======
-CHANGES
-=======
-
-1.5.4 (2008-10-30)
-------------------
-
-- Added 'pagelet' tales expression (same as @@pagelet)
-
-- Update css styles
-
-
-1.5.3 (2008-10-16)
-------------------
-
-- Update css styles
-
-
-1.5.2 (2008-10-15)
-------------------
-
-- Render IPagelet adapter for @@pagelet view
-
-
-1.5.1 (2008-10-14)
-------------------
-
-- Fixed missing NotFount in @@pagelet
-
-- Log errors in @@pagelet
-
-- Default css styles
-
-
-1.5.0 (2008-10-06)
-------------------
-
-- Added @@pagelet browser view for fast access pagelets
-
-
-1.4.6 (2008-10-03)
-------------------
-
-- Fixed bug with multple nameless pagelet
-
-
-1.4.5 (2008-08-18)
-------------------
-
-- `name` attribute is optional for <z3ext:pagelet/> directive
-
-
-1.4.4 (2008-07-22)
-------------------
-
-- Fix IPagelet adapter for content
-
-
-1.4.3 (2008-05-22)
-------------------
-
-- Added LayoutNotFound exception
-
-
-1.4.2 (2008-05-14)
-------------------
-
-- Remove unused interfaces
-
-- Tests updated
-
-
-1.4.1 (2008-04-23)
-------------------
-
-- Use newer version of z3ext.autoinclude
-
-
-1.4 (2008-03-21)
-----------------
-
-- Added z3ext:pagelet directive
-
-- Code cleanup
-
-- Moved to svn.zope.org
-
-
-1.3.2 (2008-03-06)
-------------------
-
-- Removed context layouts
-
-
-1.3.1 (2008-02-21)
-------------------
-
-- Code cleanup
-
-- Remove code related to zope.formlib
-
-
-1.3.0 (2008-02-20)
-------------------
-
-- Removed code related to z3c.form
-
-
-1.2.1 (2008-02-18)
-------------------
-
-- Added 'redirect' method to IBrowserPagelet, this is usefull
- when we need redirect during 'update' method and we don't
- need render pagelet at all.
-
-- Added adapter to IPagelet for (context, request),
- this adapter gets browser:defaultView for context and if it IPagelet return it
-
-
-1.2.0 (2008-02-13)
-------------------
-
-- Remove all code related to persistent templates
-
-
-1.1.2 (2008-02-12)
-------------------
-
-- Added 'title' and 'description' fields layout directive
-
-- check ILayoutTemplateTAL for ISite
-
-
-1.1.0 (2008-02-08)
-------------------
-
-- Added compatibility with z3c.template layouts
-
-- Added ILayoutTemplateTAL interface, other packages
- can define adapter to this interface and change layout template
- TAL program (layout customization)
-
-
-1.0.1 (2008-02-02)
-------------------
-
-- Added required dependencies
-
-
-1.0.0 (2008-01-15)
-------------------
-
-- Initial release
Copied: z3ext.layout/tags/1.5.6/CHANGES.txt (from rev 92803, z3ext.layout/trunk/CHANGES.txt)
===================================================================
--- z3ext.layout/tags/1.5.6/CHANGES.txt (rev 0)
+++ z3ext.layout/tags/1.5.6/CHANGES.txt 2008-11-06 09:24:50 UTC (rev 92804)
@@ -0,0 +1,166 @@
+=======
+CHANGES
+=======
+
+1.5.6 (2008-11-06)
+------------------
+
+- Register nameless pagelet only if provided interface is not
+inherited from IBrowserPublisher
+
+
+1.5.5 (2008-11-05)
+------------------
+
+- Add IPagelet interface to pagelet provides
+
+
+1.5.4 (2008-10-30)
+------------------
+
+- Added 'pagelet' tales expression (same as @@pagelet)
+
+- Update css styles
+
+
+1.5.3 (2008-10-16)
+------------------
+
+- Update css styles
+
+
+1.5.2 (2008-10-15)
+------------------
+
+- Render IPagelet adapter for @@pagelet view
+
+
+1.5.1 (2008-10-14)
+------------------
+
+- Fixed missing NotFount in @@pagelet
+
+- Log errors in @@pagelet
+
+- Default css styles
+
+
+1.5.0 (2008-10-06)
+------------------
+
+- Added @@pagelet browser view for fast access pagelets
+
+
+1.4.6 (2008-10-03)
+------------------
+
+- Fixed bug with multple nameless pagelet
+
+
+1.4.5 (2008-08-18)
+------------------
+
+- `name` attribute is optional for <z3ext:pagelet/> directive
+
+
+1.4.4 (2008-07-22)
+------------------
+
+- Fix IPagelet adapter for content
+
+
+1.4.3 (2008-05-22)
+------------------
+
+- Added LayoutNotFound exception
+
+
+1.4.2 (2008-05-14)
+------------------
+
+- Remove unused interfaces
+
+- Tests updated
+
+
+1.4.1 (2008-04-23)
+------------------
+
+- Use newer version of z3ext.autoinclude
+
+
+1.4 (2008-03-21)
+----------------
+
+- Added z3ext:pagelet directive
+
+- Code cleanup
+
+- Moved to svn.zope.org
+
+
+1.3.2 (2008-03-06)
+------------------
+
+- Removed context layouts
+
+
+1.3.1 (2008-02-21)
+------------------
+
+- Code cleanup
+
+- Remove code related to zope.formlib
+
+
+1.3.0 (2008-02-20)
+------------------
+
+- Removed code related to z3c.form
+
+
+1.2.1 (2008-02-18)
+------------------
+
+- Added 'redirect' method to IBrowserPagelet, this is usefull
+ when we need redirect during 'update' method and we don't
+ need render pagelet at all.
+
+- Added adapter to IPagelet for (context, request),
+ this adapter gets browser:defaultView for context and if it IPagelet return it
+
+
+1.2.0 (2008-02-13)
+------------------
+
+- Remove all code related to persistent templates
+
+
+1.1.2 (2008-02-12)
+------------------
+
+- Added 'title' and 'description' fields layout directive
+
+- check ILayoutTemplateTAL for ISite
+
+
+1.1.0 (2008-02-08)
+------------------
+
+- Added compatibility with z3c.template layouts
+
+- Added ILayoutTemplateTAL interface, other packages
+ can define adapter to this interface and change layout template
+ TAL program (layout customization)
+
+
+1.0.1 (2008-02-02)
+------------------
+
+- Added required dependencies
+
+
+1.0.0 (2008-01-15)
+------------------
+
+- Initial release
Deleted: z3ext.layout/tags/1.5.6/setup.py
===================================================================
--- z3ext.layout/trunk/setup.py 2008-11-05 00:03:57 UTC (rev 92788)
+++ z3ext.layout/tags/1.5.6/setup.py 2008-11-06 09:24:50 UTC (rev 92804)
@@ -1,76 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2007 Zope Corporation and Contributors.
-# 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.
-#
-##############################################################################
-"""Setup for z3ext.layout package
-
-$Id$
-"""
-import sys, os
-from setuptools import setup, find_packages
-
-def read(*rnames):
- return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
-
-version='1.5.5dev'
-
-
-setup(name='z3ext.layout',
- version=version,
- description="A package implementing advanced Page Template patterns.",
- long_description=(
- 'Detailed Documentation\n' +
- '======================\n'
- + '\n\n' +
- read('src', 'z3ext', 'layout', 'README.txt')
- + '\n\n' +
- read('CHANGES.txt')
- ),
- classifiers=[
- 'Development Status :: 5 - Production/Stable',
- 'Environment :: Web Environment',
- 'Intended Audience :: Developers',
- 'License :: OSI Approved :: Zope Public License',
- 'Programming Language :: Python',
- 'Natural Language :: English',
- 'Operating System :: OS Independent',
- 'Topic :: Internet :: WWW/HTTP',
- 'Framework :: Zope3'],
- author='Nikolay Kim',
- author_email='fafhrd91 at gmail.com',
- url='http://z3ext.net/',
- license='ZPL 2.1',
- packages=find_packages('src'),
- package_dir = {'':'src'},
- namespace_packages=['z3ext'],
- install_requires = ['setuptools',
- 'zope.event',
- 'zope.schema',
- 'zope.component',
- 'zope.interface',
- 'zope.security',
- 'zope.publisher',
- 'zope.configuration',
- 'zope.pagetemplate',
- 'zope.tales',
- 'zope.app.component',
- 'zope.app.publisher',
- 'zope.app.pagetemplate',
- 'z3c.autoinclude',
- ],
- extras_require = dict(test=['zope.app.container',
- 'zope.app.testing',
- 'zope.testing',
- ]),
- include_package_data = True,
- zip_safe = False
- )
Copied: z3ext.layout/tags/1.5.6/setup.py (from rev 92791, z3ext.layout/trunk/setup.py)
===================================================================
--- z3ext.layout/tags/1.5.6/setup.py (rev 0)
+++ z3ext.layout/tags/1.5.6/setup.py 2008-11-06 09:24:50 UTC (rev 92804)
@@ -0,0 +1,76 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation and Contributors.
+# 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.
+#
+##############################################################################
+"""Setup for z3ext.layout package
+
+$Id$
+"""
+import sys, os
+from setuptools import setup, find_packages
+
+def read(*rnames):
+ return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
+
+version='1.5.6'
+
+
+setup(name='z3ext.layout',
+ version=version,
+ description="A package implementing advanced Page Template patterns.",
+ long_description=(
+ 'Detailed Documentation\n' +
+ '======================\n'
+ + '\n\n' +
+ read('src', 'z3ext', 'layout', 'README.txt')
+ + '\n\n' +
+ read('CHANGES.txt')
+ ),
+ classifiers=[
+ 'Development Status :: 5 - Production/Stable',
+ 'Environment :: Web Environment',
+ 'Intended Audience :: Developers',
+ 'License :: OSI Approved :: Zope Public License',
+ 'Programming Language :: Python',
+ 'Natural Language :: English',
+ 'Operating System :: OS Independent',
+ 'Topic :: Internet :: WWW/HTTP',
+ 'Framework :: Zope3'],
+ author='Nikolay Kim',
+ author_email='fafhrd91 at gmail.com',
+ url='http://z3ext.net/',
+ license='ZPL 2.1',
+ packages=find_packages('src'),
+ package_dir = {'':'src'},
+ namespace_packages=['z3ext'],
+ install_requires = ['setuptools',
+ 'zope.event',
+ 'zope.schema',
+ 'zope.component',
+ 'zope.interface',
+ 'zope.security',
+ 'zope.publisher',
+ 'zope.configuration',
+ 'zope.pagetemplate',
+ 'zope.tales',
+ 'zope.app.component',
+ 'zope.app.publisher',
+ 'zope.app.pagetemplate',
+ 'z3c.autoinclude',
+ ],
+ extras_require = dict(test=['zope.app.container',
+ 'zope.app.testing',
+ 'zope.testing',
+ ]),
+ include_package_data = True,
+ zip_safe = False
+ )
Deleted: z3ext.layout/tags/1.5.6/src/z3ext/layout/pagelet.txt
===================================================================
--- z3ext.layout/trunk/src/z3ext/layout/pagelet.txt 2008-11-05 00:03:57 UTC (rev 92788)
+++ z3ext.layout/tags/1.5.6/src/z3ext/layout/pagelet.txt 2008-11-06 09:24:50 UTC (rev 92804)
@@ -1,469 +0,0 @@
-=================
-Pagelet directive
-=================
-
-Show how we can use the pagelet directive. Register the meta configuration for
-the directive.
-
- >>> import os, tempfile
- >>> from zope import interface, component
- >>> from zope.configuration import xmlconfig
- >>> import z3ext.layout
- >>> context = xmlconfig.file('meta.zcml', z3ext.layout)
-
-We need also a custom pagelet class:
-
- >>> from z3ext.layout.pagelet import BrowserPagelet
- >>> class MyPagelet(BrowserPagelet):
- ... """Custom pagelet"""
-
-Register a pagelet within the directive with minimal attributes:
-
- >>> context = xmlconfig.string("""
- ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
- ... <z3ext:pagelet
- ... name="index.html"
- ... class="z3ext.layout.TESTS.MyPagelet"
- ... permission="zope.Public"
- ... />
- ... </configure>
- ... """, context)
-
-Let's get the pagelet
-
- >>> from zope.publisher.browser import TestRequest
- >>> pagelet = component.queryMultiAdapter((object(), TestRequest()),
- ... name='index.html')
-
-and check them:
-
- >>> pagelet
- <z3ext.layout.zcml.PageletClass from <class 'z3ext.layout.TESTS.MyPagelet'> ...>
-
- >>> pagelet.context
- <object object at ...>
-
-Register the pagelet with a different name and more attributes provided from
-the directive. We also use a custom attribute called label here.
-Also we don't use BrowserPagelet as parent class, pagelet directive automaticly
-adds BrowserPagetlet to bases classes. Let's define some more components...
-
- >>> class SecondPagelet(object):
- ... label = u''
-
- >>> import zope.interface
- >>> class IContent(zope.interface.Interface):
- ... """Content interface."""
-
- >>> class Content(object):
- ... zope.interface.implements(IContent)
-
- >>> context = xmlconfig.string("""
- ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
- ... <z3ext:pagelet
- ... name="custom.html"
- ... class="z3ext.layout.TESTS.SecondPagelet"
- ... for="z3ext.layout.TESTS.IContent"
- ... permission="zope.Public"
- ... label="my Label" />
- ... </configure>
- ... """, context)
-
-Get the pagelet for the new content object
-
- >>> import zope.component
- >>> pagelet = zope.component.queryMultiAdapter((Content(), TestRequest()),
- ... name='custom.html')
-
-and check them:
-
- >>> pagelet
- <z3ext.layout.zcml.PageletClass from <class 'z3ext.layout.TESTS.SecondPagelet'> ...>
-
- >>> pagelet.label
- u'my Label'
-
-We also can provide another interface then the IPagelet within the directive.
-Such a interface must be inherited from IPagelet.
-
- >>> class NewPagelet(BrowserPagelet):
- ... """New pagelet"""
-
-Now register the pagelet within a interface.
-
- >>> class INewPagelet(interface.Interface):
- ... """New pagelet interface."""
-
- >>> context = xmlconfig.string("""
- ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
- ... <z3ext:pagelet
- ... name="new.html"
- ... class="z3ext.layout.TESTS.NewPagelet"
- ... permission="zope.Public"
- ... provides="z3ext.layout.TESTS.INewPagelet" />
- ... </configure>
- ... """, context)
-
-And if we get the pagelet, we can see that the object provides the new
-pagelet interface:
-
- >>> pagelet = component.queryMultiAdapter((object(), TestRequest()),
- ... name='new.html')
- >>> pagelet
- <z3ext.layout.zcml.PageletClass from <class 'z3ext.layout.TESTS.NewPagelet'> ...>
-
- >>> INewPagelet.providedBy(pagelet)
- True
-
-We can create pagelet without specific class
-
- >>> context = xmlconfig.string("""
- ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
- ... <z3ext:pagelet
- ... name="noclass.html"
- ... permission="zope.Public" />
- ... </configure>
- ... """, context)
-
- >>> pagelet = component.queryMultiAdapter((object(), TestRequest()),
- ... name='noclass.html')
- >>> pagelet
- <z3ext.layout.zcml.PageletClass from None ...>
-
-
-We can create pagelet with template:
-
- >>> context = xmlconfig.string("""
- ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
- ... <z3ext:pagelet
- ... name="unknown.html"
- ... template="unknown.pt"
- ... permission="zope.Public" />
- ... </configure>
- ... """, context)
- Traceback (most recent call last):
- ...
- ZopeXMLConfigurationError: File "<string>", line 3.2-6.33
- ConfigurationError: ('No such file', ...unknown.pt')
-
- >>> temp_dir = tempfile.mkdtemp()
- >>> template = os.path.join(temp_dir, 'pagelet.pt')
- >>> open(template, 'w').write('''<div>My pagelet</div>''')
-
- >>> context = xmlconfig.string("""
- ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
- ... <z3ext:pagelet
- ... name="template.html"
- ... template="%s"
- ... permission="zope.Public" />
- ... </configure>
- ... """%template, context)
-
- >>> pagelet = component.queryMultiAdapter((object(), TestRequest()),
- ... name='template.html')
- >>> pagelet
- <z3ext.layout.zcml.PageletClass from None ...>
-
- >>> pagelet.template
- <BoundPageTemplateFile of <z3ext.layout.zcml.PageletClass from None ...>>
-
-Pagelet rendering
-
- >>> print pagelet.render()
- <div>My pagelet</div>
- <BLANKLINE>
-
-We should use page template as template for pagelet or we should
-provide IPageTemplate adapter for pagelet
-
- >>> pagelet = component.queryMultiAdapter((object(), TestRequest()),
- ... name='noclass.html')
- >>> pagelet.render()
- Traceback (most recent call last):
- ...
- LookupError: Can't find IPageTemplate for pagelet.
-
- >>> from zope.pagetemplate.interfaces import IPageTemplate
- >>> from zope.app.pagetemplate import ViewPageTemplateFile
- >>> pt = ViewPageTemplateFile(template)
- >>> def getPT(context, request):
- ... return pt
- >>> component.getSiteManager().registerAdapter(
- ... getPT, (pagelet.__class__, interface.Interface), IPageTemplate, '')
-
- >>> print pagelet()
- <div>My pagelet</div>
- <BLANKLINE>
-
-We can redirect during pagelet rendering, in this case render method
-doesn't call.
-
- >>> pagelet = component.queryMultiAdapter((object(), TestRequest()),
- ... name='noclass.html')
- >>> pagelet.redirect('/')
- >>> pagelet.isRedirected
- True
- >>> pagelet()
- u''
-
-We can get default pagelet view for content. First register default view
-
- >>> from zope.component.interfaces import IDefaultViewName
- >>> component.getSiteManager().registerAdapter(
- ... 'index.html', (interface.Interface, interface.Interface),
- ... IDefaultViewName)
-
- >>> view = component.getMultiAdapter(
- ... (object(), TestRequest()), z3ext.layout.interfaces.IPagelet)
-
- >>> view
- <z3ext.layout.zcml.PageletClass from <class 'z3ext.layout.TESTS.MyPagelet'> ...>
-
- >>> view.__name__
- u'index.html'
-
-
-Pagelet without name
-
- >>> class IMyPagelet1(interface.Interface):
- ... pass
-
- >>> class IMyPagelet2(interface.Interface):
- ... pass
-
- >>> template2 = os.path.join(temp_dir, 'pagelet2.pt')
- >>> open(template2, 'w').write('''<div>My pagelet2</div>''')
-
- >>> from z3ext.layout.tests import ITestPagelet
-
- >>> context = xmlconfig.string("""
- ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
- ... <z3ext:pagelet
- ... template="%s"
- ... provides="z3ext.layout.tests.ITestPagelet"
- ... permission="zope.Public" />
- ... <z3ext:pagelet
- ... template="%s"
- ... provides="z3ext.layout.TESTS.IMyPagelet2"
- ... permission="zope.Public" />
- ... <z3ext:pagelet
- ... template="%s"
- ... permission="zope.Public" />
- ... </configure>
- ... """%(template, template2, template2), context)
-
- >>> pagelet = component.queryMultiAdapter(
- ... (object(), TestRequest()), ITestPagelet)
-
- >>> ITestPagelet.providedBy(pagelet)
- True
- >>> pagelet.render()
- u'<div>My pagelet</div>'
-
- >>> request = TestRequest()
- >>> pagelet = component.queryMultiAdapter((object(), request), IMyPagelet2)
- >>> IMyPagelet2.providedBy(pagelet)
- True
- >>> pagelet.render()
- u'<div>My pagelet2</div>'
-
-
-Access nameless pagelet from view
-
- >>> pagelet = component.getMultiAdapter((object(), request), name='pagelet')
-
- >>> print pagelet.publishTraverse(
- ... request, 'test.unknown')
- Traceback (most recent call last):
- ...
- NotFound: Object: ..., name: 'test.unknown'
-
- >>> pagelet.browserDefault(request)
- (..., ('',))
-
-by default IPagelet
-
- >>> print pagelet()
- <div>My pagelet2</div>
-
- >>> print pagelet.publishTraverse(request, '')
- <div>My pagelet2</div>
-
- >>> print pagelet.publishTraverse(
- ... request, 'z3ext.layout.tests.ITestPagelet')
- <div>My pagelet</div>
-
-We can register our marker interface as named utility and use name
-instead of full module path
-
- >>> component.provideUtility(
- ... ITestPagelet, z3ext.layout.interfaces.IPageletType, name='testPageletType')
-
- >>> print pagelet.publishTraverse(request, 'testPageletType')
- <div>My pagelet</div>
-
-
-The TALES `pagelet` expression
-==============================
-
-The ``pagelet`` expression will look up the interaface or IPageletType
-name, call it and return the HTML content. The first step, however, will be to
-register our pagelet with the component architecture:
-
-Let's now create a view using a page template:
-
- >>> import os, tempfile
- >>> temp_dir = tempfile.mkdtemp()
- >>> templateFileName = os.path.join(temp_dir, 'template.pt')
- >>> open(templateFileName, 'w').write('''
- ... <html>
- ... <body>
- ... <h1>My Web Page</h1>
- ... <div class="left-column">
- ... <tal:block replace="structure pagelet:z3ext.layout.tests.ITestPagelet" />
- ... </div>
- ... <div class="main">
- ... Content here
- ... </div>
- ... </body>
- ... </html>
- ... ''')
-
-Also we should register tales expression
-
- >>> from z3ext.layout import tales
- >>> from zope.app.pagetemplate.metaconfigure import registerType
- >>> registerType('pagelet', tales.TALESPageletExpression)
-
-Finally we look up the view and render it.
-
- >>> from zope.app.pagetemplate.simpleviewclass import SimpleViewClass
-
- >>> FrontPage = SimpleViewClass(templateFileName, name='main.html')
- >>> component.provideAdapter(
- ... FrontPage,
- ... (interface.Interface, interface.Interface), interface.Interface,
- ... name='main.html')
-
- >>> view = component.getMultiAdapter((object(), request), name='main.html')
- >>> print view()
- <html>
- <body>
- <h1>My Web Page</h1>
- <div class="left-column">
- <div>My pagelet</div>
- </div>
- <div class="main">
- Content here
- </div>
- </body>
- </html>
-
-Or we can use typed pagelet interface
-
- >>> open(templateFileName, 'w').write('''
- ... <html>
- ... <body>
- ... <h1>My Web Page</h1>
- ... <div class="left-column">
- ... <tal:block replace="structure pagelet:testPageletType" />
- ... </div>
- ... <div class="main">
- ... Content here
- ... </div>
- ... </body>
- ... </html>
- ... ''')
-
- >>> FrontPage = SimpleViewClass(templateFileName, name='main.html')
- >>> component.provideAdapter(
- ... FrontPage,
- ... (interface.Interface, interface.Interface), interface.Interface,
- ... name='main.html')
-
- >>> view = component.getMultiAdapter((object(), request), name='main.html')
- >>> print view()
- <html>
- <body>
- <h1>My Web Page</h1>
- <div class="left-column">
- <div>My pagelet</div>
- </div>
- <div class="main">
- Content here
- </div>
- </body>
- </html>
-
-Default IPagelet
-
- >>> open(templateFileName, 'w').write('''
- ... <html>
- ... <body>
- ... <h1>My Web Page</h1>
- ... <div class="left-column">
- ... <tal:block replace="structure pagelet:" />
- ... </div>
- ... <div class="main">
- ... Content here
- ... </div>
- ... </body>
- ... </html>
- ... ''')
-
- >>> FrontPage = SimpleViewClass(templateFileName, name='main.html')
- >>> component.provideAdapter(
- ... FrontPage,
- ... (interface.Interface, interface.Interface), interface.Interface,
- ... name='main.html')
-
- >>> view = component.getMultiAdapter((object(), request), name='main.html')
- >>> print view()
- <html>
- <body>
- <h1>My Web Page</h1>
- <div class="left-column">
- <div>My pagelet2</div>
- </div>
- <div class="main">
- Content here
- </div>
- </body>
- </html>
-
-
-If pagelet is not exist, just return empty string
-
- >>> open(templateFileName, 'w').write('''
- ... <html>
- ... <body>
- ... <h1>My Web Page</h1>
- ... <div class="left-column">
- ... <tal:block replace="structure pagelet:test.unknown" />
- ... </div>
- ... <div class="main">
- ... Content here
- ... </div>
- ... </body>
- ... </html>
- ... ''')
-
- >>> FrontPage = SimpleViewClass(templateFileName, name='main.html')
- >>> component.provideAdapter(
- ... FrontPage,
- ... (interface.Interface, interface.Interface), interface.Interface,
- ... name='main.html')
-
- >>> view = component.getMultiAdapter((object(), request), name='main.html')
- >>> print view()
- <html>
- <body>
- <h1>My Web Page</h1>
- <div class="left-column">
- <BLANKLINE>
- </div>
- <div class="main">
- Content here
- </div>
- </body>
- </html>
Copied: z3ext.layout/tags/1.5.6/src/z3ext/layout/pagelet.txt (from rev 92803, z3ext.layout/trunk/src/z3ext/layout/pagelet.txt)
===================================================================
--- z3ext.layout/tags/1.5.6/src/z3ext/layout/pagelet.txt (rev 0)
+++ z3ext.layout/tags/1.5.6/src/z3ext/layout/pagelet.txt 2008-11-06 09:24:50 UTC (rev 92804)
@@ -0,0 +1,525 @@
+=================
+Pagelet directive
+=================
+
+Show how we can use the pagelet directive. Register the meta configuration for
+the directive.
+
+ >>> import os, tempfile
+ >>> from zope import interface, component
+ >>> from zope.configuration import xmlconfig
+ >>> from z3ext.layout.interfaces import IPagelet
+ >>> import z3ext.layout
+ >>> context = xmlconfig.file('meta.zcml', z3ext.layout)
+
+We need also a custom pagelet class:
+
+ >>> from z3ext.layout.pagelet import BrowserPagelet
+ >>> class MyPagelet(BrowserPagelet):
+ ... """Custom pagelet"""
+
+Register a pagelet within the directive with minimal attributes:
+
+ >>> context = xmlconfig.string("""
+ ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+ ... <z3ext:pagelet
+ ... name="index.html"
+ ... class="z3ext.layout.TESTS.MyPagelet"
+ ... permission="zope.Public"
+ ... />
+ ... </configure>
+ ... """, context)
+
+Let's get the pagelet
+
+ >>> from zope.publisher.browser import TestRequest
+ >>> pagelet = component.queryMultiAdapter((object(), TestRequest()),
+ ... name='index.html')
+
+and check them:
+
+ >>> pagelet
+ <z3ext.layout.zcml.PageletClass from <class 'z3ext.layout.TESTS.MyPagelet'> ...>
+
+ >>> pagelet.context
+ <object object at ...>
+
+Register the pagelet with a different name and more attributes provided from
+the directive. We also use a custom attribute called label here.
+Also we don't use BrowserPagelet as parent class, pagelet directive automaticly
+adds BrowserPagetlet to bases classes. Let's define some more components...
+
+ >>> class SecondPagelet(object):
+ ... label = u''
+
+ >>> import zope.interface
+ >>> class IContent(zope.interface.Interface):
+ ... """Content interface."""
+
+ >>> class Content(object):
+ ... zope.interface.implements(IContent)
+
+ >>> context = xmlconfig.string("""
+ ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+ ... <z3ext:pagelet
+ ... name="custom.html"
+ ... class="z3ext.layout.TESTS.SecondPagelet"
+ ... for="z3ext.layout.TESTS.IContent"
+ ... permission="zope.Public"
+ ... label="my Label" />
+ ... </configure>
+ ... """, context)
+
+Get the pagelet for the new content object
+
+ >>> import zope.component
+ >>> pagelet = zope.component.queryMultiAdapter((Content(), TestRequest()),
+ ... name='custom.html')
+
+and check them:
+
+ >>> pagelet
+ <z3ext.layout.zcml.PageletClass from <class 'z3ext.layout.TESTS.SecondPagelet'> ...>
+
+ >>> pagelet.label
+ u'my Label'
+
+We also can provide another interface then the IPagelet within the directive.
+Such a interface must be inherited from IPagelet.
+
+ >>> class NewPagelet(BrowserPagelet):
+ ... """New pagelet"""
+
+Now register the pagelet within a interface.
+
+ >>> class INewPagelet(interface.Interface):
+ ... """New pagelet interface."""
+
+ >>> context = xmlconfig.string("""
+ ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+ ... <z3ext:pagelet
+ ... name="new.html"
+ ... class="z3ext.layout.TESTS.NewPagelet"
+ ... permission="zope.Public"
+ ... provides="z3ext.layout.TESTS.INewPagelet" />
+ ... </configure>
+ ... """, context)
+
+And if we get the pagelet, we can see that the object provides the new
+pagelet interface:
+
+ >>> pagelet = component.queryMultiAdapter((object(), TestRequest()),
+ ... name='new.html')
+ >>> pagelet
+ <z3ext.layout.zcml.PageletClass from <class 'z3ext.layout.TESTS.NewPagelet'> ...>
+
+ >>> INewPagelet.providedBy(pagelet)
+ True
+
+We can create pagelet without specific class
+
+ >>> context = xmlconfig.string("""
+ ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+ ... <z3ext:pagelet
+ ... name="noclass.html"
+ ... permission="zope.Public" />
+ ... </configure>
+ ... """, context)
+
+ >>> pagelet = component.queryMultiAdapter((object(), TestRequest()),
+ ... name='noclass.html')
+ >>> pagelet
+ <z3ext.layout.zcml.PageletClass from None ...>
+
+
+We can create pagelet with template:
+
+ >>> context = xmlconfig.string("""
+ ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+ ... <z3ext:pagelet
+ ... name="unknown.html"
+ ... template="unknown.pt"
+ ... permission="zope.Public" />
+ ... </configure>
+ ... """, context)
+ Traceback (most recent call last):
+ ...
+ ZopeXMLConfigurationError: File "<string>", line 3.2-6.33
+ ConfigurationError: ('No such file', ...unknown.pt')
+
+ >>> temp_dir = tempfile.mkdtemp()
+ >>> template = os.path.join(temp_dir, 'pagelet.pt')
+ >>> open(template, 'w').write('''<div>My pagelet</div>''')
+
+ >>> context = xmlconfig.string("""
+ ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+ ... <z3ext:pagelet
+ ... name="template.html"
+ ... template="%s"
+ ... permission="zope.Public" />
+ ... </configure>
+ ... """%template, context)
+
+ >>> pagelet = component.queryMultiAdapter((object(), TestRequest()),
+ ... name='template.html')
+ >>> pagelet
+ <z3ext.layout.zcml.PageletClass from None ...>
+
+ >>> pagelet.template
+ <BoundPageTemplateFile of <z3ext.layout.zcml.PageletClass from None ...>>
+
+Pagelet rendering
+
+ >>> print pagelet.render()
+ <div>My pagelet</div>
+ <BLANKLINE>
+
+We should use page template as template for pagelet or we should
+provide IPageTemplate adapter for pagelet
+
+ >>> pagelet = component.queryMultiAdapter((object(), TestRequest()),
+ ... name='noclass.html')
+ >>> pagelet.render()
+ Traceback (most recent call last):
+ ...
+ LookupError: Can't find IPageTemplate for pagelet.
+
+ >>> from zope.pagetemplate.interfaces import IPageTemplate
+ >>> from zope.app.pagetemplate import ViewPageTemplateFile
+ >>> pt = ViewPageTemplateFile(template)
+ >>> def getPT(context, request):
+ ... return pt
+ >>> component.getSiteManager().registerAdapter(
+ ... getPT, (pagelet.__class__, interface.Interface), IPageTemplate, '')
+
+ >>> print pagelet()
+ <div>My pagelet</div>
+ <BLANKLINE>
+
+We can redirect during pagelet rendering, in this case render method
+doesn't call.
+
+ >>> pagelet = component.queryMultiAdapter((object(), TestRequest()),
+ ... name='noclass.html')
+ >>> pagelet.redirect('/')
+ >>> pagelet.isRedirected
+ True
+ >>> pagelet()
+ u''
+
+We can get default pagelet view for content. First register default view
+
+ >>> from zope.component.interfaces import IDefaultViewName
+ >>> component.getSiteManager().registerAdapter(
+ ... 'index.html', (interface.Interface, interface.Interface),
+ ... IDefaultViewName)
+
+ >>> view = component.getMultiAdapter(
+ ... (object(), TestRequest()), z3ext.layout.interfaces.IPagelet)
+
+ >>> view
+ <z3ext.layout.zcml.PageletClass from <class 'z3ext.layout.TESTS.MyPagelet'> ...>
+
+ >>> view.__name__
+ u'index.html'
+
+
+Pagelet without name
+
+ >>> class IMyPagelet1(interface.Interface):
+ ... pass
+
+ >>> class IMyPagelet2(interface.Interface):
+ ... pass
+
+ >>> template2 = os.path.join(temp_dir, 'pagelet2.pt')
+ >>> open(template2, 'w').write('''<div>My pagelet2</div>''')
+
+ >>> from z3ext.layout.tests import ITestPagelet
+
+ >>> context = xmlconfig.string("""
+ ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+ ... <z3ext:pagelet
+ ... template="%s"
+ ... provides="z3ext.layout.tests.ITestPagelet"
+ ... permission="zope.Public" />
+ ... <z3ext:pagelet
+ ... template="%s"
+ ... provides="z3ext.layout.TESTS.IMyPagelet2"
+ ... permission="zope.Public" />
+ ... <z3ext:pagelet
+ ... template="%s"
+ ... permission="zope.Public" />
+ ... </configure>
+ ... """%(template, template2, template2), context)
+
+ >>> pagelet = component.queryMultiAdapter(
+ ... (object(), TestRequest()), ITestPagelet)
+
+ >>> ITestPagelet.providedBy(pagelet)
+ True
+ >>> pagelet.render()
+ u'<div>My pagelet</div>'
+
+ >>> request = TestRequest()
+ >>> pagelet = component.queryMultiAdapter((object(), request), IMyPagelet2)
+ >>> IMyPagelet2.providedBy(pagelet)
+ True
+ >>> pagelet.render()
+ u'<div>My pagelet2</div>'
+
+
+Access nameless pagelet from view
+
+ >>> pagelet = component.getMultiAdapter((object(), request), name='pagelet')
+
+ >>> print pagelet.publishTraverse(
+ ... request, 'test.unknown')
+ Traceback (most recent call last):
+ ...
+ NotFound: Object: ..., name: 'test.unknown'
+
+ >>> pagelet.browserDefault(request)
+ (..., ('',))
+
+by default IPagelet
+
+ >>> print pagelet()
+ <div>My pagelet2</div>
+
+ >>> print pagelet.publishTraverse(request, '')
+ <div>My pagelet2</div>
+
+ >>> print pagelet.publishTraverse(
+ ... request, 'z3ext.layout.tests.ITestPagelet')
+ <div>My pagelet</div>
+
+We can register our marker interface as named utility and use name
+instead of full module path
+
+ >>> component.provideUtility(
+ ... ITestPagelet, z3ext.layout.interfaces.IPageletType, name='testPageletType')
+ >>> interface.alsoProvides(ITestPagelet, z3ext.layout.interfaces.IPageletType)
+
+ >>> print pagelet.publishTraverse(request, 'testPageletType')
+ <div>My pagelet</div>
+
+We can register nameless pagelet only if provided interface is not
+inherited from IBrowserPublisher, because we can override
+IBrowserPublisher for content.
+
+ >>> class IWrongPageletInterface(IPagelet):
+ ... pass
+
+ >>> context = xmlconfig.string("""
+ ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+ ... <z3ext:pagelet
+ ... template="%s"
+ ... provides="z3ext.layout.TESTS.IWrongPageletInterface"
+ ... permission="zope.Public" />
+ ... </configure>
+ ... """%template, context)
+ Traceback (most recent call last):
+ ...
+ ZopeXMLConfigurationError:...
+ ConfigurationError: You can't register nameless pagelet...
+
+If we still need nameless adapter we can use IPagelet interface
+
+ >>> context = xmlconfig.string("""
+ ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+ ... <z3ext:pagelet
+ ... for="z3ext.layout.TESTS.IContent"
+ ... template="%s"
+ ... provides="z3ext.layout.interfaces.IPagelet"
+ ... permission="zope.Public" />
+ ... </configure>
+ ... """%template, context)
+
+
+If we register named pagelet and provided interface provides IPageletType,
+also nameless adapter registered
+
+ >>> context = xmlconfig.string("""
+ ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+ ... <z3ext:pagelet
+ ... name="test.html"
+ ... for="z3ext.layout.TESTS.IContent"
+ ... template="%s"
+ ... provides="z3ext.layout.TESTS.ITestPagelet"
+ ... permission="zope.Public" />
+ ... </configure>
+ ... """%template, context)
+
+ >>> content = Content()
+ >>> pagelet1 = component.getMultiAdapter((content, request), name='test.html')
+ >>> pagelet2 = component.getMultiAdapter((content, request), ITestPagelet)
+
+ >>> pagelet1.__class__ is pagelet2.__class__
+ True
+
+
+The TALES `pagelet` expression
+==============================
+
+The ``pagelet`` expression will look up the interaface or IPageletType
+name, call it and return the HTML content. The first step, however, will be to
+register our pagelet with the component architecture:
+
+Let's now create a view using a page template:
+
+ >>> import os, tempfile
+ >>> temp_dir = tempfile.mkdtemp()
+ >>> templateFileName = os.path.join(temp_dir, 'template.pt')
+ >>> open(templateFileName, 'w').write('''
+ ... <html>
+ ... <body>
+ ... <h1>My Web Page</h1>
+ ... <div class="left-column">
+ ... <tal:block replace="structure pagelet:z3ext.layout.tests.ITestPagelet" />
+ ... </div>
+ ... <div class="main">
+ ... Content here
+ ... </div>
+ ... </body>
+ ... </html>
+ ... ''')
+
+Also we should register tales expression
+
+ >>> from z3ext.layout import tales
+ >>> from zope.app.pagetemplate.metaconfigure import registerType
+ >>> registerType('pagelet', tales.TALESPageletExpression)
+
+Finally we look up the view and render it.
+
+ >>> from zope.app.pagetemplate.simpleviewclass import SimpleViewClass
+
+ >>> FrontPage = SimpleViewClass(templateFileName, name='main.html')
+ >>> component.provideAdapter(
+ ... FrontPage,
+ ... (interface.Interface, interface.Interface), interface.Interface,
+ ... name='main.html')
+
+ >>> view = component.getMultiAdapter((object(), request), name='main.html')
+ >>> print view()
+ <html>
+ <body>
+ <h1>My Web Page</h1>
+ <div class="left-column">
+ <div>My pagelet</div>
+ </div>
+ <div class="main">
+ Content here
+ </div>
+ </body>
+ </html>
+
+Or we can use typed pagelet interface
+
+ >>> open(templateFileName, 'w').write('''
+ ... <html>
+ ... <body>
+ ... <h1>My Web Page</h1>
+ ... <div class="left-column">
+ ... <tal:block replace="structure pagelet:testPageletType" />
+ ... </div>
+ ... <div class="main">
+ ... Content here
+ ... </div>
+ ... </body>
+ ... </html>
+ ... ''')
+
+ >>> FrontPage = SimpleViewClass(templateFileName, name='main.html')
+ >>> component.provideAdapter(
+ ... FrontPage,
+ ... (interface.Interface, interface.Interface), interface.Interface,
+ ... name='main.html')
+
+ >>> view = component.getMultiAdapter((object(), request), name='main.html')
+ >>> print view()
+ <html>
+ <body>
+ <h1>My Web Page</h1>
+ <div class="left-column">
+ <div>My pagelet</div>
+ </div>
+ <div class="main">
+ Content here
+ </div>
+ </body>
+ </html>
+
+Default IPagelet
+
+ >>> open(templateFileName, 'w').write('''
+ ... <html>
+ ... <body>
+ ... <h1>My Web Page</h1>
+ ... <div class="left-column">
+ ... <tal:block replace="structure pagelet:" />
+ ... </div>
+ ... <div class="main">
+ ... Content here
+ ... </div>
+ ... </body>
+ ... </html>
+ ... ''')
+
+ >>> FrontPage = SimpleViewClass(templateFileName, name='main.html')
+ >>> component.provideAdapter(
+ ... FrontPage,
+ ... (interface.Interface, interface.Interface), interface.Interface,
+ ... name='main.html')
+
+ >>> view = component.getMultiAdapter((object(), request), name='main.html')
+ >>> print view()
+ <html>
+ <body>
+ <h1>My Web Page</h1>
+ <div class="left-column">
+ <div>My pagelet2</div>
+ </div>
+ <div class="main">
+ Content here
+ </div>
+ </body>
+ </html>
+
+
+If pagelet is not exist, just return empty string
+
+ >>> open(templateFileName, 'w').write('''
+ ... <html>
+ ... <body>
+ ... <h1>My Web Page</h1>
+ ... <div class="left-column">
+ ... <tal:block replace="structure pagelet:test.unknown" />
+ ... </div>
+ ... <div class="main">
+ ... Content here
+ ... </div>
+ ... </body>
+ ... </html>
+ ... ''')
+
+ >>> FrontPage = SimpleViewClass(templateFileName, name='main.html')
+ >>> component.provideAdapter(
+ ... FrontPage,
+ ... (interface.Interface, interface.Interface), interface.Interface,
+ ... name='main.html')
+
+ >>> view = component.getMultiAdapter((object(), request), name='main.html')
+ >>> print view()
+ <html>
+ <body>
+ <h1>My Web Page</h1>
+ <div class="left-column">
+ <BLANKLINE>
+ </div>
+ <div class="main">
+ Content here
+ </div>
+ </body>
+ </html>
Deleted: z3ext.layout/tags/1.5.6/src/z3ext/layout/zcml.py
===================================================================
--- z3ext.layout/trunk/src/z3ext/layout/zcml.py 2008-11-05 00:03:57 UTC (rev 92788)
+++ z3ext.layout/tags/1.5.6/src/z3ext/layout/zcml.py 2008-11-06 09:24:50 UTC (rev 92804)
@@ -1,371 +0,0 @@
-##############################################################################
-#
-# Copyright (c) 2007 Zope Corporation and Contributors.
-# 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.
-#
-##############################################################################
-"""
-
-$Id$
-"""
-import os.path
-from zope import schema, interface, event
-from zope.component.interface import provideInterface
-from zope.component.zcml import handler, adapter, utility
-from zope.security.checker import defineChecker, Checker, CheckerPublic
-from zope.configuration.fields import Path, Tokens, GlobalObject, GlobalInterface
-from zope.configuration.exceptions import ConfigurationError
-from zope.publisher.interfaces.browser import IDefaultBrowserLayer
-from zope.app.component.metadirectives import IBasicViewInformation
-from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
-
-from interfaces import IPagelet, IPageletType
-from interfaces import ILayout, ILayoutCreatedEvent
-
-from pagelet import BrowserPagelet
-from layout import Layout, LayoutTemplateFile
-
-
-class IPageletDirective(IBasicViewInformation):
- """A directive to register a new pagelet.
-
- The pagelet directive also supports an undefined set of keyword arguments
- that are set as attributes on the pagelet after creation.
- """
-
- for_ = GlobalObject(
- title = u"Context",
- description = u"The content interface or class this pagelet is for.",
- required = False)
-
- name = schema.TextLine(
- title = u"The name of the pagelet.",
- description = u"The name shows up in URLs/paths. For example 'foo'.",
- required = False)
-
- provides = Tokens(
- title = u"The interface this pagelets provides.",
- description = u"""A pagelet can provide an interface. This would be used for
- views that support other views.""",
- required = False,
- value_type = GlobalInterface(),
- default = [IPagelet,])
-
- class_ = GlobalObject(
- title=u"Class",
- description=u"A class that provides attributes used by the pagelet.",
- required=False,
- )
-
- template = Path(
- title = u'Pagelet template.',
- description = u"Refers to a file containing a page template (should "\
- "end in extension ``.pt`` or ``.html``).",
- required=False)
-
- layout = schema.TextLine(
- title = u'The name of the layout.',
- description = u"The name is used to look up the layout.",
- default=u'',
- required=False)
-
-# Arbitrary keys and values are allowed to be passed to the pagelet.
-IPageletDirective.setTaggedValue('keyword_arguments', True)
-
-
-class ILayoutDirective(interface.Interface):
-
- template = Path(
- title=u'Layout template.',
- description=u"Refers to a file containing a page template (should "
- "end in extension ``.pt`` or ``.html``).",
- required=False,
- )
-
- name = schema.TextLine(
- title=u"The name of the layout.",
- description=u"The name is used to look up the layout.",
- default=u'',
- required=False)
-
- layer = GlobalObject(
- title = u'Layer',
- description = u'The layer for which the template should be available',
- required = False,
- default=IDefaultBrowserLayer,
- )
-
- contentType = schema.BytesLine(
- title = u'Content Type',
- description=u'The content type identifies the type of data.',
- default='text/html',
- required=False,
- )
-
- provides = GlobalInterface(
- title=u"Interface the layout provides",
- description=u"This attribute specifies the interface the layout"
- " instance will provide.",
- default=ILayout,
- required=False,
- )
-
- for_ = GlobalObject(
- title = u'Context',
- description = u'The object for which the layout should be available',
- default=interface.Interface,
- required = False)
-
- view = GlobalObject(
- title = u'View',
- description = u'The view for which the layout should be available',
- default=interface.Interface,
- required = False)
-
- class_ = GlobalObject(
- title=u"Class",
- description=u"A class that provides attributes used by the layout.",
- required=False,
- )
-
- layout = schema.TextLine(
- title = u'Layout',
- description = u'Custom layout name.',
- required = False)
-
- title = schema.TextLine(
- title = u'Layout title',
- required = False)
-
- description = schema.TextLine(
- title = u'Layout description',
- required = False)
-
-# Arbitrary keys and values are allowed
-ILayoutDirective.setTaggedValue('keyword_arguments', True)
-
-
-def layoutDirective(
- _context, template='', for_=None, view=None, name = u'',
- layer = IDefaultBrowserLayer, provides = ILayout,
- contentType='text/html', class_ = None, layout = '',
- title='', description='', **kwargs):
-
- if not layout:
- layout = None
- elif layout == '.':
- layout = ''
-
- # Make sure that the template exists
- if template:
- template = os.path.abspath(str(_context.path(template)))
- if not os.path.isfile(template):
- raise ConfigurationError("No such file", template)
-
- # Check
- if (for_ is None) and (view is None):
- raise ConfigurationError("FOR or VIEW are required.")
-
- # Build a new class that we can use different permission settings if we
- # use the class more then once.
- cdict = {}
- cdict['__name__'] = name
- cdict['layout'] = layout
- cdict['title'] = title
- cdict['description'] = description
-
- if template:
- cdict['template'] = LayoutTemplateFile(template, content_type=contentType)
-
- cdict.update(kwargs)
-
- class_name = 'Layout<%s>'%name
-
- if class_ is None:
- bases = (Layout,)
- else:
- bases = (class_, Layout)
-
- newclass = type(str(class_name), bases, cdict)
-
- # Set up permission mapping for various accessible attributes
- required = {}
-
- for iface in (provides, ILayout):
- for iname in iface:
- required[iname] = CheckerPublic
-
- required = {'__call__': CheckerPublic,
- 'browserDefault': CheckerPublic,
- 'publishTraverse': CheckerPublic}
-
- # provide the custom provides interface if not allready provided
- if not provides.implementedBy(newclass):
- interface.classImplements(newclass, provides)
-
- # security checker
- defineChecker(newclass, Checker(required))
-
- if for_ is not None:
- # register the template
- if name:
- adapter(_context, (newclass,),
- provides, (interface.Interface, for_, layer), name=name)
- else:
- adapter(_context, (newclass,),
- provides, (interface.Interface, for_, layer))
-
- # send ILayoutCreatedEvent event
- _context.action(
- discriminator = ('z3ext.layout', name, interface.Interface, for_, layer),
- callable = sendNotification,
- args = (name, interface.Interface, for_, layer, newclass, kwargs),
- order = 99999999)
-
- if view is not None:
- # register the template
- if name:
- adapter(_context, (newclass,),
- provides, (view, interface.Interface, layer), name=name)
- else:
- adapter(_context, (newclass,),
- provides, (view, interface.Interface, layer))
-
- # send ILayoutCreatedEvent event
- _context.action(
- discriminator = ('z3ext.layout', name, view, interface.Interface, layer),
- callable = sendNotification,
- args = (name, view, interface.Interface, layer, newclass, kwargs),
- order = 99999999)
-
-
-class LayoutCreatedEvent(object):
- interface.implements(ILayoutCreatedEvent)
-
- def __init__(self, name, view, context, layer, layoutclass, keywords):
- self.name = name
- self.view = view
- self.context = context
- self.layer = layer
- self.layoutclass = layoutclass
- self.keywords = keywords
-
-
-def sendNotification(name, view, context, layer, layoutclass, keywords):
- event.notify(LayoutCreatedEvent(
- name, view, context, layer, layoutclass, keywords))
-
-
-# pagelet directive
-def pageletDirective(
- _context, permission, name=u'', class_=None, for_=interface.Interface,
- layer=IDefaultBrowserLayer, provides=[IPagelet,],
- allowed_interface=[], allowed_attributes=[],
- template=u'', layout=u'', **kwargs):
-
- # Security map dictionary
- required = {}
-
- # Get the permission; mainly to correctly handle CheckerPublic.
- if permission == 'zope.Public':
- permission = CheckerPublic
-
- # Make sure that the template exists
- if template:
- template = os.path.abspath(str(_context.path(template)))
- if not os.path.isfile(template):
- raise ConfigurationError("No such file", template)
- kwargs['template'] = ViewPageTemplateFile(template)
-
- # Build a new class that we can use different permission settings if we
- # use the class more then once.
- cdict = {}
- cdict.update(kwargs)
- cdict['__name__'] = name
- cdict['layoutname'] = layout
-
- if class_ is not None:
- if issubclass(class_, BrowserPagelet):
- bases = (class_,)
- else:
- bases = (class_, BrowserPagelet)
- else:
- bases = (BrowserPagelet,)
-
- new_class = type('PageletClass from %s'%class_, bases, cdict)
-
- # prepare allowed interfaces and attributes
- allowed_interface.extend(provides)
- if IPagelet not in provides:
- allowed_interface.append(IPagelet)
-
- allowed_attributes.extend(kwargs.keys())
- allowed_attributes.extend(('__call__', 'browserDefault',
- 'update', 'render', 'publishTraverse'))
-
- # Set up permission mapping for various accessible attributes
- _handle_allowed_interface(
- _context, allowed_interface, permission, required)
- _handle_allowed_attributes(
- _context, allowed_attributes, permission, required)
-
- # Register the interfaces.
- _handle_for(_context, for_)
-
- # provide the custom provides interface if not allready provided
- for iface in provides:
- if not iface.implementedBy(new_class):
- interface.classImplements(new_class, iface)
-
- # Create the security checker for the new class
- defineChecker(new_class, Checker(required))
-
- # register pagelet
- _context.action(
- discriminator = ('z3ext.layout:registerPagelets', new_class),
- callable = registerPagelets,
- args = (for_, layer, new_class, provides, name, _context.info))
-
-
-def registerPagelets(for_, layer, newClass, provides, name, info):
- for iface in provides:
- if IPageletType.providedBy(iface):
- handler('registerAdapter', newClass, (for_, layer), iface, '', info)
- else:
- handler('registerAdapter', newClass, (for_, layer), iface, name, info)
-
-
-def _handle_allowed_interface(
- _context, allowed_interface, permission, required):
- # Allow access for all names defined by named interfaces
- if allowed_interface:
- for i in allowed_interface:
- _context.action(
- discriminator = None,
- callable = provideInterface,
- args = (None, i))
-
- for name in i:
- required[name] = permission
-
-def _handle_allowed_attributes(
- _context, allowed_attributes, permission, required):
-
- # Allow access for all named attributes
- if allowed_attributes:
- for name in allowed_attributes:
- required[name] = permission
-
-def _handle_for(_context, for_):
- if for_ is not None:
- _context.action(
- discriminator = None,
- callable = provideInterface,
- args = ('', for_))
Copied: z3ext.layout/tags/1.5.6/src/z3ext/layout/zcml.py (from rev 92803, z3ext.layout/trunk/src/z3ext/layout/zcml.py)
===================================================================
--- z3ext.layout/tags/1.5.6/src/z3ext/layout/zcml.py (rev 0)
+++ z3ext.layout/tags/1.5.6/src/z3ext/layout/zcml.py 2008-11-06 09:24:50 UTC (rev 92804)
@@ -0,0 +1,394 @@
+##############################################################################
+#
+# Copyright (c) 2007 Zope Corporation and Contributors.
+# 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.
+#
+##############################################################################
+"""
+
+$Id$
+"""
+import os.path
+from zope import schema, interface, event
+from zope.component.interface import provideInterface
+from zope.component.zcml import handler, adapter, utility
+from zope.security.checker import defineChecker, Checker, CheckerPublic
+from zope.configuration.fields import Path, Tokens, GlobalObject, GlobalInterface
+from zope.configuration.exceptions import ConfigurationError
+from zope.publisher.interfaces.browser import IBrowserPublisher
+from zope.publisher.interfaces.browser import IDefaultBrowserLayer
+from zope.app.component.metadirectives import IBasicViewInformation
+from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
+
+from interfaces import IPagelet, IPageletType
+from interfaces import ILayout, ILayoutCreatedEvent
+
+from pagelet import BrowserPagelet
+from layout import Layout, LayoutTemplateFile
+
+
+class IPageletDirective(IBasicViewInformation):
+ """A directive to register a new pagelet.
+
+ The pagelet directive also supports an undefined set of keyword arguments
+ that are set as attributes on the pagelet after creation.
+ """
+
+ for_ = GlobalObject(
+ title = u"Context",
+ description = u"The content interface or class this pagelet is for.",
+ required = False)
+
+ name = schema.TextLine(
+ title = u"The name of the pagelet.",
+ description = u"The name shows up in URLs/paths. For example 'foo'.",
+ required = False)
+
+ provides = Tokens(
+ title = u"The interface this pagelets provides.",
+ description = u"""A pagelet can provide an interface. This would be used for
+ views that support other views.""",
+ required = False,
+ value_type = GlobalInterface(),
+ default = [IPagelet,])
+
+ class_ = GlobalObject(
+ title=u"Class",
+ description=u"A class that provides attributes used by the pagelet.",
+ required=False,
+ )
+
+ template = Path(
+ title = u'Pagelet template.',
+ description = u"Refers to a file containing a page template (should "\
+ "end in extension ``.pt`` or ``.html``).",
+ required=False)
+
+ layout = schema.TextLine(
+ title = u'The name of the layout.',
+ description = u"The name is used to look up the layout.",
+ default=u'',
+ required=False)
+
+# Arbitrary keys and values are allowed to be passed to the pagelet.
+IPageletDirective.setTaggedValue('keyword_arguments', True)
+
+
+class ILayoutDirective(interface.Interface):
+
+ template = Path(
+ title=u'Layout template.',
+ description=u"Refers to a file containing a page template (should "
+ "end in extension ``.pt`` or ``.html``).",
+ required=False,
+ )
+
+ name = schema.TextLine(
+ title=u"The name of the layout.",
+ description=u"The name is used to look up the layout.",
+ default=u'',
+ required=False)
+
+ layer = GlobalObject(
+ title = u'Layer',
+ description = u'The layer for which the template should be available',
+ required = False,
+ default=IDefaultBrowserLayer,
+ )
+
+ contentType = schema.BytesLine(
+ title = u'Content Type',
+ description=u'The content type identifies the type of data.',
+ default='text/html',
+ required=False,
+ )
+
+ provides = GlobalInterface(
+ title=u"Interface the layout provides",
+ description=u"This attribute specifies the interface the layout"
+ " instance will provide.",
+ default=ILayout,
+ required=False,
+ )
+
+ for_ = GlobalObject(
+ title = u'Context',
+ description = u'The object for which the layout should be available',
+ default=interface.Interface,
+ required = False)
+
+ view = GlobalObject(
+ title = u'View',
+ description = u'The view for which the layout should be available',
+ default=interface.Interface,
+ required = False)
+
+ class_ = GlobalObject(
+ title=u"Class",
+ description=u"A class that provides attributes used by the layout.",
+ required=False,
+ )
+
+ layout = schema.TextLine(
+ title = u'Layout',
+ description = u'Custom layout name.',
+ required = False)
+
+ title = schema.TextLine(
+ title = u'Layout title',
+ required = False)
+
+ description = schema.TextLine(
+ title = u'Layout description',
+ required = False)
+
+# Arbitrary keys and values are allowed
+ILayoutDirective.setTaggedValue('keyword_arguments', True)
+
+
+def layoutDirective(
+ _context, template='', for_=None, view=None, name = u'',
+ layer = IDefaultBrowserLayer, provides = ILayout,
+ contentType='text/html', class_ = None, layout = '',
+ title='', description='', **kwargs):
+
+ if not layout:
+ layout = None
+ elif layout == '.':
+ layout = ''
+
+ # Make sure that the template exists
+ if template:
+ template = os.path.abspath(str(_context.path(template)))
+ if not os.path.isfile(template):
+ raise ConfigurationError("No such file", template)
+
+ # Check
+ if (for_ is None) and (view is None):
+ raise ConfigurationError("FOR or VIEW are required.")
+
+ # Build a new class that we can use different permission settings if we
+ # use the class more then once.
+ cdict = {}
+ cdict['__name__'] = name
+ cdict['layout'] = layout
+ cdict['title'] = title
+ cdict['description'] = description
+
+ if template:
+ cdict['template'] = LayoutTemplateFile(template, content_type=contentType)
+
+ cdict.update(kwargs)
+
+ class_name = 'Layout<%s>'%name
+
+ if class_ is None:
+ bases = (Layout,)
+ else:
+ bases = (class_, Layout)
+
+ newclass = type(str(class_name), bases, cdict)
+
+ # Set up permission mapping for various accessible attributes
+ required = {}
+
+ for iface in (provides, ILayout):
+ for iname in iface:
+ required[iname] = CheckerPublic
+
+ required = {'__call__': CheckerPublic,
+ 'browserDefault': CheckerPublic,
+ 'publishTraverse': CheckerPublic}
+
+ # provide the custom provides interface if not allready provided
+ if not provides.implementedBy(newclass):
+ interface.classImplements(newclass, provides)
+
+ # security checker
+ defineChecker(newclass, Checker(required))
+
+ if for_ is not None:
+ # register the template
+ if name:
+ adapter(_context, (newclass,),
+ provides, (interface.Interface, for_, layer), name=name)
+ else:
+ adapter(_context, (newclass,),
+ provides, (interface.Interface, for_, layer))
+
+ # send ILayoutCreatedEvent event
+ _context.action(
+ discriminator = ('z3ext.layout', name, interface.Interface, for_, layer),
+ callable = sendNotification,
+ args = (name, interface.Interface, for_, layer, newclass, kwargs),
+ order = 99999999)
+
+ if view is not None:
+ # register the template
+ if name:
+ adapter(_context, (newclass,),
+ provides, (view, interface.Interface, layer), name=name)
+ else:
+ adapter(_context, (newclass,),
+ provides, (view, interface.Interface, layer))
+
+ # send ILayoutCreatedEvent event
+ _context.action(
+ discriminator = ('z3ext.layout', name, view, interface.Interface, layer),
+ callable = sendNotification,
+ args = (name, view, interface.Interface, layer, newclass, kwargs),
+ order = 99999999)
+
+
+class LayoutCreatedEvent(object):
+ interface.implements(ILayoutCreatedEvent)
+
+ def __init__(self, name, view, context, layer, layoutclass, keywords):
+ self.name = name
+ self.view = view
+ self.context = context
+ self.layer = layer
+ self.layoutclass = layoutclass
+ self.keywords = keywords
+
+
+def sendNotification(name, view, context, layer, layoutclass, keywords):
+ event.notify(LayoutCreatedEvent(
+ name, view, context, layer, layoutclass, keywords))
+
+
+# pagelet directive
+def pageletDirective(
+ _context, permission, name=u'', class_=None, for_=interface.Interface,
+ layer=IDefaultBrowserLayer, provides=[IPagelet,],
+ allowed_interface=[], allowed_attributes=[],
+ template=u'', layout=u'', **kwargs):
+
+ # Security map dictionary
+ required = {}
+
+ # Get the permission; mainly to correctly handle CheckerPublic.
+ if permission == 'zope.Public':
+ permission = CheckerPublic
+
+ # Make sure that the template exists
+ if template:
+ template = os.path.abspath(str(_context.path(template)))
+ if not os.path.isfile(template):
+ raise ConfigurationError("No such file", template)
+ kwargs['template'] = ViewPageTemplateFile(template)
+
+ # Build a new class that we can use different permission settings if we
+ # use the class more then once.
+ cdict = {}
+ cdict.update(kwargs)
+ cdict['__name__'] = name
+ cdict['layoutname'] = layout
+
+ if class_ is not None:
+ if issubclass(class_, BrowserPagelet):
+ bases = (class_,)
+ else:
+ bases = (class_, BrowserPagelet)
+ else:
+ bases = (BrowserPagelet,)
+
+ new_class = type('PageletClass from %s'%class_, bases, cdict)
+
+ # check name
+ if not name:
+ for iface in provides:
+ # allow register nameless pagelet as IPagelet
+ if iface is IPagelet:
+ continue
+
+ if iface.isOrExtends(IBrowserPublisher):
+ raise ConfigurationError(
+ "You can't register nameless pagelet, "\
+ "interface '%s' is or extends IBrowserPublisher"%iface)
+
+ # add IPagelet to provides
+ if name:
+ inProvides = False
+ for iface in provides:
+ if IPagelet.isOrExtends(iface) and not IPageletType.providedBy(iface):
+ inProvides = True
+
+ if not inProvides:
+ provides.append(IPagelet)
+
+ # prepare allowed interfaces and attributes
+ allowed_interface.extend(provides)
+ if IPagelet not in provides:
+ allowed_interface.append(IPagelet)
+
+ allowed_attributes.extend(kwargs.keys())
+ allowed_attributes.extend(('__call__', 'browserDefault',
+ 'update', 'render', 'publishTraverse'))
+
+ # Set up permission mapping for various accessible attributes
+ _handle_allowed_interface(
+ _context, allowed_interface, permission, required)
+ _handle_allowed_attributes(
+ _context, allowed_attributes, permission, required)
+
+ # Register the interfaces.
+ _handle_for(_context, for_)
+
+ # provide the custom provides interface if not allready provided
+ for iface in provides:
+ if not iface.implementedBy(new_class):
+ interface.classImplements(new_class, iface)
+
+ # Create the security checker for the new class
+ defineChecker(new_class, Checker(required))
+
+ # register pagelet
+ _context.action(
+ discriminator = ('z3ext.layout:registerPagelets', new_class),
+ callable = registerPagelets,
+ args = (for_, layer, new_class, provides, name, _context.info))
+
+
+def registerPagelets(for_, layer, newClass, provides, name, info):
+ for iface in provides:
+ if IPageletType.providedBy(iface):
+ handler('registerAdapter', newClass, (for_, layer), iface, '', info)
+ else:
+ handler('registerAdapter', newClass, (for_, layer), iface, name, info)
+
+
+def _handle_allowed_interface(
+ _context, allowed_interface, permission, required):
+ # Allow access for all names defined by named interfaces
+ if allowed_interface:
+ for i in allowed_interface:
+ _context.action(
+ discriminator = None,
+ callable = provideInterface,
+ args = (None, i))
+
+ for name in i:
+ required[name] = permission
+
+def _handle_allowed_attributes(
+ _context, allowed_attributes, permission, required):
+
+ # Allow access for all named attributes
+ if allowed_attributes:
+ for name in allowed_attributes:
+ required[name] = permission
+
+def _handle_for(_context, for_):
+ if for_ is not None:
+ _context.action(
+ discriminator = None,
+ callable = provideInterface,
+ args = ('', for_))
More information about the Checkins
mailing list