[Checkins] SVN: z3ext.layout/tags/2.0.1/ release tag
Nikolay Kim
fafhrd at datacom.kz
Thu Dec 25 06:55:36 EST 2008
Log message for revision 94323:
release tag
Changed:
A z3ext.layout/tags/2.0.1/
D z3ext.layout/tags/2.0.1/CHANGES.txt
A z3ext.layout/tags/2.0.1/CHANGES.txt
U z3ext.layout/tags/2.0.1/setup.py
D z3ext.layout/tags/2.0.1/src/z3ext/layout/zcml.py
A z3ext.layout/tags/2.0.1/src/z3ext/layout/zcml.py
-=-
Deleted: z3ext.layout/tags/2.0.1/CHANGES.txt
===================================================================
--- z3ext.layout/trunk/CHANGES.txt 2008-12-24 21:29:33 UTC (rev 94312)
+++ z3ext.layout/tags/2.0.1/CHANGES.txt 2008-12-25 11:55:35 UTC (rev 94323)
@@ -1,229 +0,0 @@
-=======
-CHANGES
-=======
-
-2.0.0 (2008-12-22)
-------------------
-
-- Pagelet without name is not allowed
-
-- Added 'type' attribute to 'z3ext:pagelet'
-
-- Added 'z3ext:pageletType' directive for registering new pagelet types
-
-- multiple params is allowed for 'for' attribute
-
-- Removed pagelet 'manager' attribute
-
-- 'pagelet' tales expression and 'pagelet' view checks additional context IPageletContext
- if exists use it as adapter parameter
-
-
-1.7.3 (2008-12-18)
-------------------
-
-- Use IPagelet instead of IPageTemplate for pagelet rendering
-
-
-1.7.2 (2008-12-17)
-------------------
-
-- Update default styles
-
-
-1.7.1 (2008-12-15)
-------------------
-
-- Check if context provides interface in @@pagelet view and pagelet: tales expresion
-
-
-1.7.0 (2008-12-11)
-------------------
-
-- Added `manager` attribute to z3ext:pagelet directive
- this allow use getMultiAdapter((content, request, manager1, manager2, ...), IPagelet)
-
-- Use 'provides' schema for converting kwargs in z3ext:pagelet directive
-
-
-1.6.0 (2008-11-27)
-------------------
-
-- Added 'uid' attribute to z3ext:layout directive.
- Send ILayoutCreatedEvent event only if layout has uid
-
-
-1.5.9 (2008-11-24)
-------------------
-
-- Fixed python2.4 compatibility
-
-
-1.5.7 (2008-11-17)
-------------------
-
-- Update css styles
-
-
-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
Copied: z3ext.layout/tags/2.0.1/CHANGES.txt (from rev 94322, z3ext.layout/trunk/CHANGES.txt)
===================================================================
--- z3ext.layout/tags/2.0.1/CHANGES.txt (rev 0)
+++ z3ext.layout/tags/2.0.1/CHANGES.txt 2008-12-25 11:55:35 UTC (rev 94323)
@@ -0,0 +1,235 @@
+=======
+CHANGES
+=======
+
+2.0.1 (2008-12-25)
+------------------
+
+- Pagelet should implement provided interfaces
+
+
+2.0.0 (2008-12-22)
+------------------
+
+- Pagelet without name is not allowed
+
+- Added 'type' attribute to 'z3ext:pagelet'
+
+- Added 'z3ext:pageletType' directive for registering new pagelet types
+
+- multiple params is allowed for 'for' attribute
+
+- Removed pagelet 'manager' attribute
+
+- 'pagelet' tales expression and 'pagelet' view checks additional context IPageletContext
+ if exists use it as adapter parameter
+
+
+1.7.3 (2008-12-18)
+------------------
+
+- Use IPagelet instead of IPageTemplate for pagelet rendering
+
+
+1.7.2 (2008-12-17)
+------------------
+
+- Update default styles
+
+
+1.7.1 (2008-12-15)
+------------------
+
+- Check if context provides interface in @@pagelet view and pagelet: tales expresion
+
+
+1.7.0 (2008-12-11)
+------------------
+
+- Added `manager` attribute to z3ext:pagelet directive
+ this allow use getMultiAdapter((content, request, manager1, manager2, ...), IPagelet)
+
+- Use 'provides' schema for converting kwargs in z3ext:pagelet directive
+
+
+1.6.0 (2008-11-27)
+------------------
+
+- Added 'uid' attribute to z3ext:layout directive.
+ Send ILayoutCreatedEvent event only if layout has uid
+
+
+1.5.9 (2008-11-24)
+------------------
+
+- Fixed python2.4 compatibility
+
+
+1.5.7 (2008-11-17)
+------------------
+
+- Update css styles
+
+
+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
Modified: z3ext.layout/tags/2.0.1/setup.py
===================================================================
--- z3ext.layout/trunk/setup.py 2008-12-24 21:29:33 UTC (rev 94312)
+++ z3ext.layout/tags/2.0.1/setup.py 2008-12-25 11:55:35 UTC (rev 94323)
@@ -21,7 +21,7 @@
def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
-version='2.0.1dev'
+version='2.0.1'
setup(name='z3ext.layout',
Deleted: z3ext.layout/tags/2.0.1/src/z3ext/layout/zcml.py
===================================================================
--- z3ext.layout/trunk/src/z3ext/layout/zcml.py 2008-12-24 21:29:33 UTC (rev 94312)
+++ z3ext.layout/tags/2.0.1/src/z3ext/layout/zcml.py 2008-12-25 11:55:35 UTC (rev 94323)
@@ -1,473 +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.schema.interfaces import IFromUnicode
-from zope.component import getUtility, queryUtility
-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 import IPublishTraverse
-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 zope.security.zcml import Permission
-
-from interfaces import IPagelet, IPageletType
-from interfaces import ILayout, ILayoutCreatedEvent
-
-from pagelet import BrowserPagelet
-from layout import Layout, LayoutTemplateFile
-
-
-class IPageletTypeDirective(interface.Interface):
- """A directive to register a new pagelet type."""
-
- name = schema.TextLine(
- title = u'Name',
- description = u'Pagelet type name',
- required = True)
-
- interface = GlobalInterface(
- title = u'Interface',
- description = u'Interface that is used as pagelet type.',
- required = True)
-
-
-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_ = Tokens(
- title = u"Context",
- description = u"The content interface or class this pagelet is for.",
- value_type = GlobalObject(missing_value=object()),
- required = True)
-
- name = schema.TextLine(
- title = u"The name of the pagelet.",
- description = u"The name shows up in URLs/paths. For example 'foo'.",
- required = False)
-
- type = Tokens(
- title = u"Pagelet type.",
- required = False,
- value_type = schema.TextLine())
-
- 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())
-
- 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)
-
- layer = GlobalObject(
- title = u'Layer',
- description = u'The layer for which the template should be available',
- required = False,
- default = IDefaultBrowserLayer)
-
-
-# Arbitrary keys and values are allowed to be passed to the pagelet.
-IPageletDirective.setTaggedValue('keyword_arguments', True)
-
-
-class ILayoutDirective(interface.Interface):
-
- uid = schema.TextLine(
- title = u"Unique layout id",
- default = u'',
- required = False)
-
- 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 pageletTypeDirective(_context, name, interface):
- if interface is not IPagelet and interface.isOrExtends(IPublishTraverse):
- raise ConfigurationError("Can't use IPublishTraverse as base for pagelet type")
-
- provideInterface(name, interface, IPageletType)
-
-
-def layoutDirective(
- _context, uid='', 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
- if uid:
- _context.action(
- discriminator = ('z3ext.layout', uid),
- callable = sendNotification,
- args = (uid, 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
- if uid:
- _context.action(
- discriminator = ('z3ext.layout', uid),
- callable = sendNotification,
- args = (uid, name, view, interface.Interface, layer, newclass, kwargs),
- order = 99999999)
-
-
-class LayoutCreatedEvent(object):
- interface.implements(ILayoutCreatedEvent)
-
- def __init__(self, uid, name, view,
- context, layer, layoutclass, keywords):
- self.uid = uid
- self.name = name
- self.view = view
- self.context = context
- self.layer = layer
- self.layoutclass = layoutclass
- self.keywords = keywords
-
-
-def sendNotification(uid, name, view, context, layer, layoutclass, keywords):
- event.notify(LayoutCreatedEvent(
- uid, name, view, context, layer, layoutclass, keywords))
-
-
-Type = type
-
-# pagelet directive
-def pageletDirective(_context, for_, name=u'', type=(),
- class_=None, layer=IDefaultBrowserLayer, provides=[],
- allowed_interface=[], allowed_attributes=[],
- template=u'', layout=u'', permission='zope.Public', **kwargs):
-
- # Check paeglet name
- if not name and not type:
- raise ConfigurationError("Can't create pagelet without name.")
-
- # Add IPagelet to provides
- provides = list(provides)
- if IPagelet not in provides:
- provides.append(IPagelet)
-
- # 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)
-
- # extend provides with type
- for tp in type:
- iface = queryUtility(IPageletType, tp)
- if iface is not None:
- provides.append(iface)
-
- # convert kwargs
- for iface in provides:
- for fname, field in schema.getFields(iface).items():
- if fname in kwargs:
- if not IFromUnicode.providedBy(field):
- raise ConfigurationError("Can't convert value", fname)
-
- setattr(new_class, fname, field.fromUnicode(kwargs[fname]))
- else:
- if field.required and not hasattr(new_class, fname):
- print provides, new_class, fname
- raise ConfigurationError("Required field is missing", fname)
-
- if not hasattr(new_class, fname):
- setattr(new_class, fname, field.default)
-
- # 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)
- 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_.append(layer)
- if type:
- _context.action(
- discriminator = ('z3ext.layout:registerPagelets', new_class),
- callable = registerTypedPagelets,
- args = (for_, new_class, type, name, _context.info))
- else:
- _context.action(
- discriminator = ('z3ext.layout:registerPagelets', tuple(for_), layer, name),
- callable = registerPagelets,
- args = (for_, new_class, provides, name, _context.info))
-
-
-def registerPagelets(required, newClass, provides, name, info):
- handler('registerAdapter', newClass, required, IPagelet, name, info)
-
- for iface in provides:
- if iface is IPagelet:
- continue
-
- if IPageletType.providedBy(iface):
- handler('registerAdapter', newClass, required, iface, '', info)
-
-
-def registerTypedPagelets(required, newClass, type, name, info):
- for tp in type:
- iface = getUtility(IPageletType, tp)
- handler('registerAdapter', newClass, required, 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_):
- for iface in for_:
- if iface is not None:
- _context.action(
- discriminator = None,
- callable = provideInterface,
- args = ('', iface))
Copied: z3ext.layout/tags/2.0.1/src/z3ext/layout/zcml.py (from rev 94322, z3ext.layout/trunk/src/z3ext/layout/zcml.py)
===================================================================
--- z3ext.layout/tags/2.0.1/src/z3ext/layout/zcml.py (rev 0)
+++ z3ext.layout/tags/2.0.1/src/z3ext/layout/zcml.py 2008-12-25 11:55:35 UTC (rev 94323)
@@ -0,0 +1,475 @@
+##############################################################################
+#
+# 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.interface.verify import verifyClass
+from zope.schema.interfaces import IFromUnicode
+from zope.component import getUtility, queryUtility
+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 import IPublishTraverse
+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 zope.security.zcml import Permission
+
+from interfaces import IPagelet, IPageletType
+from interfaces import ILayout, ILayoutCreatedEvent
+
+from pagelet import BrowserPagelet
+from layout import Layout, LayoutTemplateFile
+
+
+class IPageletTypeDirective(interface.Interface):
+ """A directive to register a new pagelet type."""
+
+ name = schema.TextLine(
+ title = u'Name',
+ description = u'Pagelet type name',
+ required = True)
+
+ interface = GlobalInterface(
+ title = u'Interface',
+ description = u'Interface that is used as pagelet type.',
+ required = True)
+
+
+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_ = Tokens(
+ title = u"Context",
+ description = u"The content interface or class this pagelet is for.",
+ value_type = GlobalObject(missing_value=object()),
+ required = True)
+
+ name = schema.TextLine(
+ title = u"The name of the pagelet.",
+ description = u"The name shows up in URLs/paths. For example 'foo'.",
+ required = False)
+
+ type = Tokens(
+ title = u"Pagelet type.",
+ required = False,
+ value_type = schema.TextLine())
+
+ 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())
+
+ 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)
+
+ layer = GlobalObject(
+ title = u'Layer',
+ description = u'The layer for which the template should be available',
+ required = False,
+ default = IDefaultBrowserLayer)
+
+
+# Arbitrary keys and values are allowed to be passed to the pagelet.
+IPageletDirective.setTaggedValue('keyword_arguments', True)
+
+
+class ILayoutDirective(interface.Interface):
+
+ uid = schema.TextLine(
+ title = u"Unique layout id",
+ default = u'',
+ required = False)
+
+ 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 pageletTypeDirective(_context, name, interface):
+ if interface is not IPagelet and interface.isOrExtends(IPublishTraverse):
+ raise ConfigurationError("Can't use IPublishTraverse as base for pagelet type")
+
+ provideInterface(name, interface, IPageletType)
+
+
+def layoutDirective(
+ _context, uid='', 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
+ if uid:
+ _context.action(
+ discriminator = ('z3ext.layout', uid),
+ callable = sendNotification,
+ args = (uid, 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
+ if uid:
+ _context.action(
+ discriminator = ('z3ext.layout', uid),
+ callable = sendNotification,
+ args = (uid, name, view, interface.Interface, layer, newclass, kwargs),
+ order = 99999999)
+
+
+class LayoutCreatedEvent(object):
+ interface.implements(ILayoutCreatedEvent)
+
+ def __init__(self, uid, name, view,
+ context, layer, layoutclass, keywords):
+ self.uid = uid
+ self.name = name
+ self.view = view
+ self.context = context
+ self.layer = layer
+ self.layoutclass = layoutclass
+ self.keywords = keywords
+
+
+def sendNotification(uid, name, view, context, layer, layoutclass, keywords):
+ event.notify(LayoutCreatedEvent(
+ uid, name, view, context, layer, layoutclass, keywords))
+
+
+Type = type
+
+# pagelet directive
+def pageletDirective(_context, for_, name=u'', type=(),
+ class_=None, layer=IDefaultBrowserLayer, provides=[],
+ allowed_interface=[], allowed_attributes=[],
+ template=u'', layout=u'', permission='zope.Public', **kwargs):
+
+ # Check paeglet name
+ if not name and not type:
+ raise ConfigurationError("Can't create pagelet without name.")
+
+ # Add IPagelet to provides
+ provides = list(provides)
+ if IPagelet not in provides:
+ provides.append(IPagelet)
+
+ # 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)
+
+ # extend provides with type
+ for tp in type:
+ iface = queryUtility(IPageletType, tp)
+ if iface is not None:
+ provides.append(iface)
+
+ # convert kwargs
+ for iface in provides:
+ for fname, field in schema.getFields(iface).items():
+ if fname in kwargs:
+ if not IFromUnicode.providedBy(field):
+ raise ConfigurationError("Can't convert value", fname)
+
+ setattr(new_class, fname, field.fromUnicode(kwargs[fname]))
+ else:
+ if field.required and not hasattr(new_class, fname):
+ raise ConfigurationError("Required field is missing", fname)
+
+ if not hasattr(new_class, fname):
+ setattr(new_class, fname, field.default)
+
+ # 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)
+ 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)
+
+ verifyClass(iface, new_class)
+
+ # Create the security checker for the new class
+ defineChecker(new_class, Checker(required))
+
+ # register pagelet
+ for_.append(layer)
+ if type:
+ _context.action(
+ discriminator = ('z3ext.layout:registerPagelets', new_class),
+ callable = registerTypedPagelets,
+ args = (for_, new_class, type, name, _context.info))
+ else:
+ _context.action(
+ discriminator = ('z3ext.layout:registerPagelets', tuple(for_), layer, name),
+ callable = registerPagelets,
+ args = (for_, new_class, provides, name, _context.info))
+
+
+def registerPagelets(required, newClass, provides, name, info):
+ handler('registerAdapter', newClass, required, IPagelet, name, info)
+
+ for iface in provides:
+ if iface is IPagelet:
+ continue
+
+ if IPageletType.providedBy(iface):
+ handler('registerAdapter', newClass, required, iface, '', info)
+
+
+def registerTypedPagelets(required, newClass, type, name, info):
+ for tp in type:
+ iface = getUtility(IPageletType, tp)
+ handler('registerAdapter', newClass, required, 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_):
+ for iface in for_:
+ if iface is not None:
+ _context.action(
+ discriminator = None,
+ callable = provideInterface,
+ args = ('', iface))
More information about the Checkins
mailing list