[Checkins] SVN: z3ext.layout/tags/1.4.5/ tag for release
Nikolay Kim
fafhrd at datacom.kz
Mon Aug 18 03:53:38 EDT 2008
Log message for revision 89955:
tag for release
Changed:
A z3ext.layout/tags/1.4.5/
D z3ext.layout/tags/1.4.5/CHANGES.txt
A z3ext.layout/tags/1.4.5/CHANGES.txt
U z3ext.layout/tags/1.4.5/setup.py
D z3ext.layout/tags/1.4.5/src/z3ext/layout/pagelet.txt
A z3ext.layout/tags/1.4.5/src/z3ext/layout/pagelet.txt
D z3ext.layout/tags/1.4.5/src/z3ext/layout/zcml.py
A z3ext.layout/tags/1.4.5/src/z3ext/layout/zcml.py
-=-
Copied: z3ext.layout/tags/1.4.5 (from rev 89951, z3ext.layout/trunk)
Deleted: z3ext.layout/tags/1.4.5/CHANGES.txt
===================================================================
--- z3ext.layout/trunk/CHANGES.txt 2008-08-18 01:54:48 UTC (rev 89951)
+++ z3ext.layout/tags/1.4.5/CHANGES.txt 2008-08-18 07:53:38 UTC (rev 89955)
@@ -1,105 +0,0 @@
-=======
-CHANGES
-=======
-
-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.4.5/CHANGES.txt (from rev 89954, z3ext.layout/trunk/CHANGES.txt)
===================================================================
--- z3ext.layout/tags/1.4.5/CHANGES.txt (rev 0)
+++ z3ext.layout/tags/1.4.5/CHANGES.txt 2008-08-18 07:53:38 UTC (rev 89955)
@@ -0,0 +1,111 @@
+=======
+CHANGES
+=======
+
+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
Modified: z3ext.layout/tags/1.4.5/setup.py
===================================================================
--- z3ext.layout/trunk/setup.py 2008-08-18 01:54:48 UTC (rev 89951)
+++ z3ext.layout/tags/1.4.5/setup.py 2008-08-18 07:53:38 UTC (rev 89955)
@@ -21,7 +21,7 @@
def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
-version='1.4.5dev'
+version='1.4.5'
setup(name='z3ext.layout',
Deleted: z3ext.layout/tags/1.4.5/src/z3ext/layout/pagelet.txt
===================================================================
--- z3ext.layout/trunk/src/z3ext/layout/pagelet.txt 2008-08-18 01:54:48 UTC (rev 89951)
+++ z3ext.layout/tags/1.4.5/src/z3ext/layout/pagelet.txt 2008-08-18 07:53:38 UTC (rev 89955)
@@ -1,223 +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'
\ No newline at end of file
Copied: z3ext.layout/tags/1.4.5/src/z3ext/layout/pagelet.txt (from rev 89954, z3ext.layout/trunk/src/z3ext/layout/pagelet.txt)
===================================================================
--- z3ext.layout/tags/1.4.5/src/z3ext/layout/pagelet.txt (rev 0)
+++ z3ext.layout/tags/1.4.5/src/z3ext/layout/pagelet.txt 2008-08-18 07:53:38 UTC (rev 89955)
@@ -0,0 +1,242 @@
+=================
+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 IMyPagelet(interface.Interface):
+ ... pass
+
+ >>> context = xmlconfig.string("""
+ ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+ ... <z3ext:pagelet
+ ... template="%s"
+ ... provides="z3ext.layout.TESTS.IMyPagelet"
+ ... permission="zope.Public" />
+ ... </configure>
+ ... """%template, context)
+
+ >>> pagelet = component.queryMultiAdapter((object(), TestRequest()), IMyPagelet)
+ >>> IMyPagelet.providedBy(pagelet)
+ True
\ No newline at end of file
Deleted: z3ext.layout/tags/1.4.5/src/z3ext/layout/zcml.py
===================================================================
--- z3ext.layout/trunk/src/z3ext/layout/zcml.py 2008-08-18 01:54:48 UTC (rev 89951)
+++ z3ext.layout/tags/1.4.5/src/z3ext/layout/zcml.py 2008-08-18 07:53:38 UTC (rev 89955)
@@ -1,366 +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
-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 = True)
-
- 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, name, permission, 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)
-
- # check interfaces
- ifaces = list(interface.Declaration(provides).flattened())
- if IPagelet not in ifaces:
- provides.append(IPagelet)
-
- # 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)
- 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:pagelet', for_, layer, name),
- callable = handler,
- args = ('registerAdapter',
- new_class, (for_, layer), IPagelet, name, _context.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.4.5/src/z3ext/layout/zcml.py (from rev 89954, z3ext.layout/trunk/src/z3ext/layout/zcml.py)
===================================================================
--- z3ext.layout/tags/1.4.5/src/z3ext/layout/zcml.py (rev 0)
+++ z3ext.layout/tags/1.4.5/src/z3ext/layout/zcml.py 2008-08-18 07:53:38 UTC (rev 89955)
@@ -0,0 +1,365 @@
+##############################################################################
+#
+# 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
+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
+ for iface in provides:
+ _context.action(
+ discriminator = ('z3ext:pagelet', for_, layer, name),
+ callable = handler,
+ args = ('registerAdapter',
+ new_class, (for_, layer), iface, name, _context.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