Log message for revision 66158: try and improve the UI of the view listing a bit by mangling file names a bit and displaying a table.
Changed: U Products.Five/branches/philikon-local-components/component/browser.py U Products.Five/branches/philikon-local-components/component/templateviews.pt U Products.Five/branches/philikon-local-components/component/tests.py -=- Modified: Products.Five/branches/philikon-local-components/component/browser.py =================================================================== --- Products.Five/branches/philikon-local-components/component/browser.py 2006-03-24 22:29:19 UTC (rev 66157) +++ Products.Five/branches/philikon-local-components/component/browser.py 2006-03-25 11:04:50 UTC (rev 66158) @@ -26,6 +26,7 @@ import zope.interface import zope.component +import zope.dottedname.resolve from zope.component.globalregistry import base from zope.component.persistentregistry import PersistentComponents from zope.publisher.interfaces.browser import IBrowserRequest @@ -72,6 +73,48 @@ self.context.setSiteManage(None) +def mangleAbsoluteFilename(filename): + """ + Mangle an absolute filename when the file happens to be in a + package. The mangled name will then be of the form:: + + <dotted package name>/<base filename>. + + For example, let's take Five's configure.zcml as an example. We + assemble it in an OS-independent way so this test works on all + platforms: + + >>> def filesystemPath(*elements): + ... return os.path.sep.join(elements) + + We see that the filename is now mangled: + + >>> mangleAbsoluteFilename(filesystemPath( + ... '', 'path', 'to', 'Products', 'Five', 'configure.zcml')) + 'Products.Five/configure.zcml' + + The name of a file that's not in a package is returned unchanged: + + >>> not_in_a_package = filesystemPath('', 'path', 'to', 'configure.zcml') + >>> mangleAbsoluteFilename(not_in_a_package) == not_in_a_package + True + """ + if not os.path.isabs(filename): + raise ValueError("Can only determine package for absolute filenames") + dir, basename = os.path.split(filename) + pieces = dir.split(os.path.sep) + if pieces[0] == '': + pieces = pieces[1:] + while pieces: + try: + zope.dottedname.resolve.resolve('.'.join(pieces)) + break + except ImportError: + pieces = pieces[1:] + if not pieces: + return filename + return '.'.join(pieces) + '/' + basename + class CustomizationView(BrowserView): def templateViewRegistrations(self): @@ -86,6 +129,18 @@ factory.__name__.startswith('SimpleViewClass'): yield reg + def templateViewRegInfo(self): + def regkey(reg): + return reg.name + for reg in sorted(self.templateViewRegistrations(), key=regkey): + yield { + 'viewname': reg.name, + 'for': reg.required[0].__identifier__, + 'type': reg.required[1].__identifier__, + 'zptfile': mangleAbsoluteFilename(reg.factory.index.filename), + 'zcmlfile': mangleAbsoluteFilename(reg.info.file) + } + def templateFromViewname(self, viewname): view = zope.component.getMultiAdapter((self.context, self.request), name=viewname) Modified: Products.Five/branches/philikon-local-components/component/templateviews.pt =================================================================== --- Products.Five/branches/philikon-local-components/component/templateviews.pt 2006-03-24 22:29:19 UTC (rev 66157) +++ Products.Five/branches/philikon-local-components/component/templateviews.pt 2006-03-25 11:04:50 UTC (rev 66158) @@ -6,16 +6,26 @@ <p i18n:translate="">Template-based (global) browser views available for this component:</p> - <ul> - <li tal:repeat="reg view/templateViewRegistrations"> - <a href="" - tal:attributes="href string:@@customizetemplate.html?viewname=${reg/name}" - tal:content="reg/name"> - </a><br /> - Template file: <code tal:content="reg/factory/index/filename">filename</code>.<br /> - Registered in: <code tal:content="reg/info/file">filename</code>.<br /> - </li> - </ul> + <table> + <tr> + <th></th> + <th>Name of View</th> + <th>Registration Info</th> + </tr> + <tr tal:repeat="info view/templateViewRegInfo"> + <td><img src="misc_/PageTemplates/zpt.gif" + tal:attributes="src string:${context/@@absolute_url}/misc_/PageTemplates/zpt.gif" /></td> + <td> + <a href="" + tal:attributes="href string:@@customizetemplate.html?viewname=${info/viewname}" + tal:content="info/viewname"> + </a> + </td> + <td><code tal:content="info/zptfile">zptfile</code><br /> + <code tal:content="info/for">for</code><br /> + <code tal:content="info/zcmlfile">zcmlfile</code></td> + </tr> + </table> </div> </body> Modified: Products.Five/branches/philikon-local-components/component/tests.py =================================================================== --- Products.Five/branches/philikon-local-components/component/tests.py 2006-03-24 22:29:19 UTC (rev 66157) +++ Products.Five/branches/philikon-local-components/component/tests.py 2006-03-25 11:04:50 UTC (rev 66158) @@ -16,14 +16,15 @@ $Id$ """ import unittest -from zope.testing.doctestunit import DocFileSuite +from zope.testing.doctestunit import DocFileSuite, DocTestSuite __docformat__ = "reStructuredText" def test_suite(): return unittest.TestSuite([ DocFileSuite('component.txt', package="Products.Five.component"), - DocFileSuite('zpt.txt', package="Products.Five.component") + DocFileSuite('zpt.txt', package="Products.Five.component"), + DocTestSuite('Products.Five.component.browser') ]) if __name__ == '__main__': _______________________________________________ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins