[z3-checkins] r5760 - in z3/Flon/trunk: . interfaces skins/flon
tests tools
dreamcatcher at codespeak.net
dreamcatcher at codespeak.net
Wed Jul 28 21:31:19 MEST 2004
Author: dreamcatcher
Date: Wed Jul 28 21:31:18 2004
New Revision: 5760
Added:
z3/Flon/trunk/browser.py (contents, props changed)
z3/Flon/trunk/interfaces/
z3/Flon/trunk/interfaces/__init__.py (contents, props changed)
z3/Flon/trunk/skins/flon/view_details.pt (contents, props changed)
z3/Flon/trunk/tests/test_views.py (contents, props changed)
Modified:
z3/Flon/trunk/configure.zcml
z3/Flon/trunk/skins/flon/edit_marker_form.cpt
z3/Flon/trunk/tools/interface.py
Log:
Add 'view_details' view, based on apidoc to report the registered views for a given marker interface.
Added: z3/Flon/trunk/browser.py
==============================================================================
--- (empty file)
+++ z3/Flon/trunk/browser.py Wed Jul 28 21:31:18 2004
@@ -0,0 +1,33 @@
+# Flon is a package for enabling hand picked Five features in Plone
+# Copyright (C) 2004 Enfold Systems, LLC
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+"""
+$Id: __init__.py,v 1.2 2004/07/14 22:23:16 dreamcatcher Exp $
+"""
+
+from Products.Five.browser import BrowserView
+from zope.app.apidoc.viewmodule.browser import SkinLayer as _SkinLayer
+from zope.app.apidoc.viewmodule.browser import ViewsDetails as _ViewsDetails
+
+class SkinLayer(BrowserView):
+
+ getSkins = _SkinLayer.getSkins.im_func
+
+class ViewsDetails(BrowserView):
+
+ __init__ = _ViewsDetails.__init__.im_func
+ getViewsByLayers = _ViewsDetails.getViewsByLayers.im_func
Modified: z3/Flon/trunk/configure.zcml
==============================================================================
--- z3/Flon/trunk/configure.zcml (original)
+++ z3/Flon/trunk/configure.zcml Wed Jul 28 21:31:18 2004
@@ -1,4 +1,5 @@
-<configure xmlns="http://namespaces.zope.org/zope">
+<configure xmlns="http://namespaces.zope.org/zope"
+ xmlns:browser="http://namespaces.zope.org/browser">
<adapter
for='*'
@@ -7,4 +8,36 @@
provides="zope.app.introspector.interfaces.IIntrospector"
/>
+ <adapter
+ for="zope.app.apidoc.viewmodule.ISkinRegistration"
+ provides="zope.app.apidoc.viewmodule.ISkinDocumentation"
+ factory="zope.app.apidoc.viewmodule.SkinDocumentation"
+ />
+
+ <adapter
+ for="zope.app.apidoc.viewmodule.ILayerRegistration"
+ provides="zope.app.apidoc.viewmodule.ILayerDocumentation"
+ factory="zope.app.apidoc.viewmodule.LayerDocumentation" />
+
+ <utility
+ provides="zope.app.apidoc.interfaces.IDocumentationModule"
+ factory="zope.app.apidoc.viewmodule.ViewModule"
+ name="Views"
+ />
+
+ <browser:page
+ for=".interfaces.IInterfaceTool"
+ permission="zope2.View"
+ class=".browser.SkinLayer"
+ name="skin_layer"
+ />
+
+ <browser:page
+ for=".interfaces.IInterfaceTool"
+ permission="zope2.View"
+ class=".browser.ViewsDetails"
+ name="view_details"
+ allowed_attributes="aq_parent getViewsByLayers"
+ />
+
</configure>
Added: z3/Flon/trunk/interfaces/__init__.py
==============================================================================
--- (empty file)
+++ z3/Flon/trunk/interfaces/__init__.py Wed Jul 28 21:31:18 2004
@@ -0,0 +1,34 @@
+from zope.interface import Interface
+
+class IInterfaceTool(Interface):
+ """This tool exposes the Zope2 interface package for TTW applications,
+ by accepting a dotted name of an interface and exporting the
+ IInterface API.
+
+ It also exposes part of the IIntrospector interface from Zope3.
+ """
+
+ def objectImplements(obj, dotted_name):
+ """ Asserts if an object implements a given interface """
+
+ def classImplements(obj, dotted_name):
+ """ Asserts if an object's class implements a given interface """
+
+ def namesAndDescriptions(dotted_name, all=0):
+ """ Returns a list of pairs (name, description) for a given
+ interface"""
+
+ def getDirectlyProvided(context):
+ """See IIntrospector"""
+
+ def getDirectlyProvidedNames(context):
+ """See IIntrospector"""
+
+ def getMarkerInterfaces(context):
+ """See IIntrospector"""
+
+ def getMarkerInterfaceNames(context):
+ """See IIntrospector"""
+
+ def update(context, add=None, remove=None):
+ """Update directly provided interfaces for an instance."""
Modified: z3/Flon/trunk/skins/flon/edit_marker_form.cpt
==============================================================================
--- z3/Flon/trunk/skins/flon/edit_marker_form.cpt (original)
+++ z3/Flon/trunk/skins/flon/edit_marker_form.cpt Wed Jul 28 21:31:18 2004
@@ -69,8 +69,12 @@
<label for=""
i18n:translate=""
tal:attributes="for iface"
- tal:content="iface"
- />
+ tal:content="iface" />
+
+ [<a href=""
+ tal:attributes="href string:${context/absolute_url}/view_details?iface=${iface}&type=zope.publisher.interfaces.browser.IBrowserRequest">
+ Views
+ </a>]
<br />
@@ -113,6 +117,11 @@
tal:content="iface"
/>
+ [<a href=""
+ tal:attributes="href string:${context/absolute_url}/view_details?iface=${iface}&type=zope.publisher.interfaces.browser.IBrowserRequest">
+ Views
+ </a>]
+
<br />
</tal:block>
Added: z3/Flon/trunk/skins/flon/view_details.pt
==============================================================================
--- (empty file)
+++ z3/Flon/trunk/skins/flon/view_details.pt Wed Jul 28 21:31:18 2004
@@ -0,0 +1,90 @@
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
+ lang="en"
+ metal:use-macro="context/main_template/macros/master"
+ i18n:domain="plone">
+
+ <head><title></title></head>
+ <body>
+ <div metal:fill-slot="main"
+ tal:define="iface_tool iface_tool|context/portal_interface;
+ details iface_tool/@@view_details;
+ layers details/getViewsByLayers">
+
+ <h1 class="details-header">
+ <tal:block replace="nothing">
+ <!-- commented out, as we should probably see always the same one -->
+ <span tal:replace="request/type" />
+ </tal:block>
+ <span i18n:translate="">Views for</span>
+ <span tal:replace="request/iface" />
+ </h1>
+
+ <span tal:repeat="layer layers">
+
+ <h2 class="details-section">
+ Layer: <span tal:replace="layer/name" />
+ </h2>
+
+ <div class="indent">
+ <ul>
+ <li tal:repeat="View layer/views">
+ <b tal:content="structure View/name" /><br />
+ <tal:omit-tag condition="View/info">
+ <span class="small">
+ <i tal:content="View/info" />
+ </span>
+ <br />
+ </tal:omit-tag>
+ <div class="indent"><span class="small">
+ <tal:block replace="nothing">
+ <!-- commented out, as most of the time seems to be empty -->
+ <i i18n:translate="">required:</i>
+ <span tal:condition="View/required"
+ tal:content="View/required" />
+ <span tal:condition="not:View/required">None</span>
+ <br />
+ <i i18n:translate="">presentation type:</i>
+ <span tal:content="View/type" />
+ <br />
+ </tal:block>
+ <tal:omit-tag condition="View/factory/path">
+ <i i18n:translate="">factory path:</i>
+ <span tal:content="View/factory/path" />
+ <br />
+ </tal:omit-tag>
+ <tal:omit-tag condition="View/provided">
+ <i i18n:translate="">provided:</i>
+ <span tal:content="View/provided" />
+ <br />
+ </tal:omit-tag>
+ <tal:omit-tag condition="View/factory/template">
+ <i i18n:translate="">template:</i>
+ <span tal:replace="View/factory/template" />
+ <br />
+ </tal:omit-tag>
+ <tal:omit-tag condition="View/factory/resource">
+ <i i18n:translate="">resource:</i>
+ <span tal:content="View/factory/resource" />
+ <br />
+ </tal:omit-tag>
+ <span
+ tal:condition="python: View['read_perm'] and View['write_perm']">
+ <i i18n:translate="">Permissions:</i>
+ <span tal:replace="View/read_perm">zope.View</span> (read),
+ <span tal:replace="View/write_perm">zope.View</span> (write)
+ </span>
+ </span></div>
+ <br />
+ </li>
+ </ul>
+ </div>
+
+ </span>
+
+ <p tal:condition="not: layers">
+ <em i18n:translate="">There are no views for this interface
+ and presentation type.</em>
+ </p>
+ </div>
+ </body>
+</html>
Added: z3/Flon/trunk/tests/test_views.py
==============================================================================
--- (empty file)
+++ z3/Flon/trunk/tests/test_views.py Wed Jul 28 21:31:18 2004
@@ -0,0 +1,126 @@
+# Flon is a package for enabling hand picked Five features in Plone
+# Copyright (C) 2004 Enfold Systems, LLC
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+#
+"""
+$Id: __init__.py,v 1.2 2004/07/14 22:23:16 dreamcatcher Exp $
+"""
+
+import os, sys
+
+if __name__ == '__main__':
+ execfile(os.path.join(sys.path[0], 'framework.py'))
+
+# Load fixture
+from Testing import ZopeTestCase
+from Products.CMFPlone.tests import PloneTestCase
+
+# Install our product
+ZopeTestCase.installProduct('Flon')
+ZopeTestCase.installProduct('Five')
+
+from Products.CMFCore.utils import getToolByName
+from zope.interface import implements, Interface
+from zope.app.component.interface import provideInterface
+from zope.interface import Interface
+from zope.publisher.interfaces.browser import IBrowserRequest
+from zope.app import zapi
+from zope.app.tests import placelesssetup, ztapi
+from zope.app.component.interface import provideInterface
+
+from zope.app.apidoc.viewmodule import ISkinRegistration
+from zope.app.apidoc.viewmodule import ISkinDocumentation, SkinDocumentation
+from zope.app.apidoc.viewmodule import ILayerRegistration
+from zope.app.apidoc.viewmodule import ILayerDocumentation, LayerDocumentation
+
+class IFoo(Interface):
+ pass
+
+class FooView:
+ pass
+
+class ViewsTest(PloneTestCase.PloneTestCase):
+
+ def afterSetUp(self):
+ # XXX There needs to be a way to do this cleanly and
+ # clean on tearDown or maybe move to a test.zcml file?
+ self.qi = getToolByName(self.portal, 'portal_quickinstaller')
+ self.qi.installProduct('Flon')
+ self.it = getToolByName(self.portal, 'portal_interface')
+
+ pres = zapi.getGlobalService('Presentation')
+
+ for index in range(1, 6):
+ pres.defineLayer('layer'+str(index))
+
+ pres.defineSkin('skinA', ['default'], 'doc skin A')
+ pres.defineSkin('skinB', ['layer5', 'layer4', 'default'], 'doc skin B')
+ pres.defineSkin('skinC', ['layer4', 'layer2', 'layer1', 'default'],
+ 'doc skin C')
+
+ provideInterface('IFoo', IFoo)
+ provideInterface('IBrowserRequest', IBrowserRequest)
+ ztapi.browserView(IFoo, 'index.html', FooView, layer='default')
+
+ def test_views(self):
+ view = self.it.restrictedTraverse('@@skin_layer')
+ skins = dict([(s.name, s.layers) for s in view.getSkins(False)])
+ self.failUnless('skinA' in skins, skins)
+ self.failUnless('skinB' in skins, skins)
+ self.failUnless('skinC' in skins, skins)
+ # Sort
+ [v.sort() for k, v in skins.items()]
+ layers = lambda s: [l.name for l in s]
+ self.assertEquals(layers(skins['skinA']), ['default'])
+ self.assertEquals(layers(skins['skinB']), ['layer5', 'layer4', 'default'])
+ self.assertEquals(layers(skins['skinC']), ['layer4', 'layer2',
+ 'layer1', 'default'])
+ # Test view details
+ request = self.it.REQUEST
+ request['iface'] = 'IFoo'
+ request['type'] = 'IBrowserRequest'
+ view = self.it.restrictedTraverse('@@view_details')
+ layer = view.getViewsByLayers()[0]
+ self.assertEquals(layer['name'], 'default')
+ view = layer['views'][0]
+ info = dict(view)
+ self.assertEquals(info['name'], 'index.html')
+ finfo = dict(info['factory'])
+ self.assertEquals(finfo['path'], 'test_views.FooView')
+ self.assertEquals(finfo['template'], None)
+# >>> pprint(view)
+# [('factory',
+# [('path', 'zope.app.apidoc.viewmodule.tests.FooView'),
+# ('referencable', True),
+# ('resource', None),
+# ('template', None),
+# ('url', 'zope/app/apidoc/viewmodule/tests/FooView')]),
+# ('info', ''),
+# ('name', 'index.html'),
+# ('provided', 'zope.interface.Interface'),
+# ('read_perm', None),
+# ('required', 'zope.app.apidoc.viewmodule.tests.IFoo'),
+# ('type', 'zope.publisher.interfaces.browser.IBrowserRequest'),
+# ('write_perm', None)]
+
+def test_suite():
+ import unittest
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(ViewsTest))
+ return suite
+
+if __name__ == '__main__':
+ framework(descriptions=1, verbosity=1)
Modified: z3/Flon/trunk/tools/interface.py
==============================================================================
--- z3/Flon/trunk/tools/interface.py (original)
+++ z3/Flon/trunk/tools/interface.py Wed Jul 28 21:31:18 2004
@@ -20,9 +20,11 @@
"""
from Products.CMFPlone.InterfaceTool import InterfaceTool as BaseTool
-from zope.interface import directlyProvides, directlyProvidedBy
+from Products.Flon.interfaces import IInterfaceTool
+from zope.interface import directlyProvides, directlyProvidedBy, implements
from zope.app.introspector.interfaces import IIntrospector
from zope.app.component.interface import getInterface
+from zope.app.apidoc.viewmodule import ViewModule
class InterfaceTool(BaseTool):
"""An improved interface tool, with support for
@@ -30,6 +32,7 @@
Also allows setting marker interfaces directly on objects.
"""
+ implements(IInterfaceTool)
meta_type = 'Flon Interface Tool'
@@ -63,3 +66,5 @@
if interface in remove:
interface = getInterface(context, interface)
directlyProvides(ob, directlyProvidedBy(ob)-interface)
+
+ getSkins = ViewModule.getSkins.im_func
More information about the z3-checkins
mailing list