[Checkins] SVN: z3ext.layout/trunk/ ZTK support
Nikolay Kim
fafhrd91 at gmail.com
Tue Dec 1 20:44:08 EST 2009
Log message for revision 106153:
ZTK support
Changed:
U z3ext.layout/trunk/CHANGES.txt
U z3ext.layout/trunk/setup.py
U z3ext.layout/trunk/src/z3ext/layout/README.txt
U z3ext.layout/trunk/src/z3ext/layout/interfaces.py
U z3ext.layout/trunk/src/z3ext/layout/layout.py
U z3ext.layout/trunk/src/z3ext/layout/pagelet.py
U z3ext.layout/trunk/src/z3ext/layout/pagelet.txt
U z3ext.layout/trunk/src/z3ext/layout/tests.py
U z3ext.layout/trunk/src/z3ext/layout/zcml.py
-=-
Modified: z3ext.layout/trunk/CHANGES.txt
===================================================================
--- z3ext.layout/trunk/CHANGES.txt 2009-12-01 22:25:12 UTC (rev 106152)
+++ z3ext.layout/trunk/CHANGES.txt 2009-12-02 01:44:08 UTC (rev 106153)
@@ -2,10 +2,12 @@
CHANGES
=======
-2.2.3 (Unreleased)
+2.3.0 (Unreleased)
------------------
+- ZTK support
+
2.2.2 (2009-09-14)
------------------
Modified: z3ext.layout/trunk/setup.py
===================================================================
--- z3ext.layout/trunk/setup.py 2009-12-01 22:25:12 UTC (rev 106152)
+++ z3ext.layout/trunk/setup.py 2009-12-02 01:44:08 UTC (rev 106153)
@@ -21,7 +21,7 @@
def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()
-version='2.2.3dev'
+version='0'
setup(name='z3ext.layout',
@@ -62,15 +62,13 @@
'zope.configuration',
'zope.pagetemplate',
'zope.tales',
- 'zope.app.component',
- 'zope.app.publisher',
'zope.app.pagetemplate',
'z3c.pt',
],
- extras_require = dict(test=['zope.app.container',
+ extras_require = dict(test=['zope.site',
+ 'zope.container',
'zope.app.testing',
'zope.testing',
]),
include_package_data = True,
- zip_safe = False
- )
+ zip_safe = False)
Modified: z3ext.layout/trunk/src/z3ext/layout/README.txt
===================================================================
--- z3ext.layout/trunk/src/z3ext/layout/README.txt 2009-12-01 22:25:12 UTC (rev 106152)
+++ z3ext.layout/trunk/src/z3ext/layout/README.txt 2009-12-02 01:44:08 UTC (rev 106153)
@@ -10,7 +10,7 @@
>>> from zope.configuration import xmlconfig
>>> context = xmlconfig.file('meta.zcml', z3ext.layout)
- >>> import os, tempfile
+ >>> import os, tempfile, shutil
>>> from zope import interface, component
>>> from z3ext.layout import tests, interfaces
>>> from z3ext.layout.pagelet import BrowserPagelet
@@ -35,22 +35,34 @@
... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
... <z3ext:layout
... name="portal"
- ... for="zope.app.component.interfaces.ISite"
+ ... for="zope.component.interfaces.ISite"
... template="%s" />
... </configure>"""%layoutportal, context)
-Here another layout.
+Here another layout. But layout template registered separatly.
>>> layoutworkspace = os.path.join(temp_dir, 'layoutworkspace.pt')
>>> open(layoutworkspace, 'w').write('''
- ... <div id="workspace" tal:content="structure view/render"></div>''')
+ ... <div id="workspace" tal:content="structure context/view/render"></div>''')
+ >>> from z3ext.layout.interfaces import ILayout
+
+ >>> class IWorkspaceLayout(ILayout):
+ ... pass
+
>>> context = xmlconfig.string("""
... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
... <z3ext:layout
... name="workspace"
- ... layout="portal"
- ... for="zope.app.component.interfaces.ISite"
+ ... layout="portal"
+ ... for="zope.component.interfaces.ISite"
+ ... provides="z3ext.layout.TESTS.IWorkspaceLayout" />
+ ... <z3ext:pageletType
+ ... name="layout"
+ ... interface="z3ext.layout.interfaces.ILayoutView" />
+ ... <z3ext:pagelet
+ ... type="layout"
+ ... for="z3ext.layout.TESTS.IWorkspaceLayout"
... template="%s" />
... </configure>"""%layoutworkspace, context)
@@ -89,7 +101,7 @@
... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
... <z3ext:layout
... layout="workspace"
- ... for="zope.app.component.interfaces.ISite"
+ ... for="zope.component.interfaces.ISite"
... template="%s" />
... </configure>"""%layoutcontent, context)
@@ -100,6 +112,22 @@
</body>
</html>
+We can use 'queryLayout' to get layout for view
+
+ >>> from z3ext.layout.pagelet import queryLayout
+
+ >>> layout = queryLayout(view, request, name='workspace')
+ >>> layout
+ <z3ext.layout.zcml.Layout<workspace> object at ...>
+
+ >>> print layout()
+ <html>
+ <body>
+ <div id="portal"><div id="workspace">root</div></div>
+ </body>
+ </html>
+
+
All 3 our layout rendered. view rendered inside nameless layout then in
-> 'workspace' layout -> 'portal' layout
@@ -278,3 +306,5 @@
</table></div>
</body>
</html>
+
+ >>> shutil.rmtree(temp_dir)
Modified: z3ext.layout/trunk/src/z3ext/layout/interfaces.py
===================================================================
--- z3ext.layout/trunk/src/z3ext/layout/interfaces.py 2009-12-01 22:25:12 UTC (rev 106152)
+++ z3ext.layout/trunk/src/z3ext/layout/interfaces.py 2009-12-02 01:44:08 UTC (rev 106153)
@@ -30,6 +30,8 @@
contexts = interface.Attribute('Additional contexts')
+ layoutname = interface.Attribute('Layout name')
+
isRedirected = interface.Attribute('is redirected')
def redirect(url=''):
Modified: z3ext.layout/trunk/src/z3ext/layout/layout.py
===================================================================
--- z3ext.layout/trunk/src/z3ext/layout/layout.py 2009-12-01 22:25:12 UTC (rev 106152)
+++ z3ext.layout/trunk/src/z3ext/layout/layout.py 2009-12-02 01:44:08 UTC (rev 106153)
@@ -103,10 +103,4 @@
if layout is not None:
return layout(view=view, *args, **kw)
- layout = queryLayout(
- self.view, self.context, self.request, name=self.layout)
-
- if layout is not None:
- return layout(*args, **kw)
-
raise LayoutNotFound(self.layout)
Modified: z3ext.layout/trunk/src/z3ext/layout/pagelet.py
===================================================================
--- z3ext.layout/trunk/src/z3ext/layout/pagelet.py 2009-12-01 22:25:12 UTC (rev 106152)
+++ z3ext.layout/trunk/src/z3ext/layout/pagelet.py 2009-12-02 01:44:08 UTC (rev 106153)
@@ -18,11 +18,11 @@
import logging, sys
from zope import interface, component
from zope.component import queryUtility, queryAdapter, queryMultiAdapter
-from zope.publisher.browser import BrowserPage
from zope.publisher.interfaces import NotFound
from zope.publisher.interfaces.browser import IBrowserPublisher
+from zope.publisher.browser import BrowserPage
+from zope.publisher.defaultview import queryDefaultViewName
from zope.tales.expressions import SimpleModuleImporter
-from zope.app.publisher.browser import queryDefaultViewName
from interfaces import ILayout, IPagelet, IPageletType, IPageletContext
@@ -83,6 +83,7 @@
@component.adapter(interface.Interface, interface.Interface)
def queryDefaultView(context, request):
name = queryDefaultViewName(context, request, None)
+
if name:
view = queryMultiAdapter((context, request), name=name)
if IPagelet.providedBy(view):
Modified: z3ext.layout/trunk/src/z3ext/layout/pagelet.txt
===================================================================
--- z3ext.layout/trunk/src/z3ext/layout/pagelet.txt 2009-12-01 22:25:12 UTC (rev 106152)
+++ z3ext.layout/trunk/src/z3ext/layout/pagelet.txt 2009-12-02 01:44:08 UTC (rev 106153)
@@ -244,7 +244,28 @@
...
ZopeXMLConfigurationError:...ConfigurationError: ("Can't convert value", 'date')
+If 'provides' is IPageletType type interface, then pagelet also
+registered as default adapter for this interface
+ >>> context = xmlconfig.string("""
+ ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+ ... <z3ext:pagelet
+ ... for="*"
+ ... name="typedpagelet.html"
+ ... class="z3ext.layout.TESTS.NewPagelet"
+ ... provides="z3ext.layout.TESTS.INewPagelet3" />
+ ... </configure>
+ ... """, context)
+
+ >>> pagelet1 = component.getMultiAdapter(
+ ... (object(), TestRequest()), IPagelet, name='typedpagelet.html')
+
+ >>> pagelet2 = component.getMultiAdapter(
+ ... (object(), TestRequest()), INewPagelet3)
+
+ >>> pagelet1.__class__ is pagelet2.__class__
+ True
+
We can create pagelet without specific class
>>> context = xmlconfig.string("""
@@ -298,6 +319,22 @@
>>> pagelet.template
<z3c.pt.pagetemplate.BoundViewPageTemplateFile '...'>
+ >>> print pagelet()
+ <div>My pagelet</div>
+
+ >>> print pagelet.updateAndRender()
+ <div>My pagelet</div>
+
+if pagelet redirected during update or not available, then call
+returns empty string
+
+ >>> pagelet.redirect('.')
+ >>> pagelet()
+ u''
+
+ >>> pagelet.updateAndRender()
+ u''
+
We can create pagelet with additional context
>>> class IContext2(interface.Interface):
@@ -593,6 +630,18 @@
... <z3ext:pagelet
... for="*"
... template="%s"
+ ... type="z3ext.layout.TESTS.IUnknown"
+ ... permission="zope.Public" />
+ ... </configure>"""%template6, context)
+ Traceback (most recent call last):
+ ...
+ ZopeXMLConfigurationError:...ConfigurationError: Can't resolve pagelet type: 'z3ext.layout.TESTS.IUnknown'
+
+ >>> context = xmlconfig.string("""
+ ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+ ... <z3ext:pagelet
+ ... for="*"
+ ... template="%s"
... type="z3ext.layout.TESTS.IMyPagelet6"
... permission="zope.Public" />
... </configure>"""%template6, context)
@@ -601,7 +650,6 @@
>>> print pagelet.publishTraverse(request, 'myPagelet6')
<div>My pagelet6</div>
-
we can call named pagelets
>>> template7 = os.path.join(temp_dir, 'pagelet7.pt')
@@ -1003,3 +1051,38 @@
</div>
</body>
</html>
+
+
+pagelet with unknown layouts
+
+ >>> from zope.publisher.browser import TestRequest
+
+ >>> class MyView(BrowserPagelet):
+ ...
+ ... layoutname = 'unknown'
+ ...
+ ... def render(self):
+ ... return self.context.__name__
+
+ >>> view = MyView(root, TestRequest())
+
+if layout unnkown just render view
+
+ >>> print view()
+ root
+
+if parent layout is unknown then raise exception
+
+ >>> context = xmlconfig.string("""
+ ... <configure xmlns:z3ext="http://namespaces.zope.org/z3ext">
+ ... <z3ext:layout
+ ... name="content"
+ ... layout="unknown"
+ ... for="zope.component.interfaces.ISite" />
+ ... </configure>""", context)
+
+ >>> MyView.layoutname = 'content'
+ >>> print view()
+ Traceback (most recent call last):
+ ...
+ LayoutNotFound: unknown
Modified: z3ext.layout/trunk/src/z3ext/layout/tests.py
===================================================================
--- z3ext.layout/trunk/src/z3ext/layout/tests.py 2009-12-01 22:25:12 UTC (rev 106152)
+++ z3ext.layout/trunk/src/z3ext/layout/tests.py 2009-12-02 01:44:08 UTC (rev 106153)
@@ -19,7 +19,7 @@
from zope import interface, component
from zope.testing.doctestunit import DocFileSuite
from zope.app.testing import setup
-from zope.app.container.sample import SampleContainer
+from zope.container.sample import SampleContainer
from z3c.pt import expressions
from z3ext.layout import pagelet
Modified: z3ext.layout/trunk/src/z3ext/layout/zcml.py
===================================================================
--- z3ext.layout/trunk/src/z3ext/layout/zcml.py 2009-12-01 22:25:12 UTC (rev 106152)
+++ z3ext.layout/trunk/src/z3ext/layout/zcml.py 2009-12-02 01:44:08 UTC (rev 106153)
@@ -30,12 +30,11 @@
from zope.publisher.interfaces.browser import IBrowserPage
from zope.publisher.interfaces.browser import IBrowserPublisher
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
-from zope.app.component.metadirectives import IBasicViewInformation
+from zope.component.zcml import IBasicViewInformation
from z3c.pt.pagetemplate import ViewPageTemplateFile
-from interfaces import IPagelet, IPageletType
-from interfaces import ILayout, ILayoutCreatedEvent
+from interfaces import IPagelet, IPageletType, ILayout, ILayoutCreatedEvent
from pagelet import BrowserPagelet
from layout import Layout, LayoutTemplateFile
@@ -347,7 +346,7 @@
try:
iface = _context.resolve(tp)
except Exception, err:
- pass
+ raise ConfigurationError("Can't resolve pagelet type: '%s'"%tp)
if iface is not None:
provides.append(iface)
@@ -375,7 +374,8 @@
if name:
inProvides = False
for iface in provides:
- if IPagelet.isOrExtends(iface) and not IPageletType.providedBy(iface):
+ if IPagelet.isOrExtends(iface) and \
+ not IPageletType.providedBy(iface):
inProvides = True
if not inProvides:
@@ -442,10 +442,7 @@
for tp in type:
iface = queryUtility(IPageletType, tp)
if iface is None:
- try:
- iface = _context.resolve(tp)
- except Exception, err:
- pass
+ iface = _context.resolve(tp)
handler('registerAdapter', newClass, required, iface,name,_context.info)
More information about the checkins
mailing list