[z3-checkins] r8255 - in z3/Five/trunk: . tests/products/FiveTest
regebro at codespeak.net
regebro at codespeak.net
Thu Jan 13 15:05:46 MET 2005
Author: regebro
Date: Thu Jan 13 15:05:46 2005
New Revision: 8255
Modified:
z3/Five/trunk/browserconfigure.py
z3/Five/trunk/fiveconfigure.py
z3/Five/trunk/fivedirectives.py
z3/Five/trunk/meta.zcml
z3/Five/trunk/monkey.py
z3/Five/trunk/tests/products/FiveTest/configure.zcml
Log:
merge -r7839:7840 svn+ssh://codespeak.net/svn/z3/Five/branch/regebro-layer_from_directory
Modified: z3/Five/trunk/browserconfigure.py
==============================================================================
--- z3/Five/trunk/browserconfigure.py (original)
+++ z3/Five/trunk/browserconfigure.py Thu Jan 13 15:05:46 2005
@@ -21,6 +21,7 @@
from zope.component.servicenames import Presentation
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.app.pagetemplate.viewpagetemplatefile import ViewPageTemplateFile
+from zope.app.pagetemplate.viewpagetemplatefile import ViewMapper
from zope.app.publisher.browser.viewmeta import pages as zope_app_pages
from zope.app.component.metaconfigure import handler
from zope.app.component.interface import provideInterface
@@ -32,6 +33,15 @@
from metaclass import makeClass
from security import getSecurityInfo, protectClass, protectName, initializeClass
+class FivePageTemplateFile(ViewPageTemplateFile):
+
+ def pt_getContext(self, instance, request, **_kw):
+ # instance is a View component
+ namespace = super(FivePageTemplateFile, self).pt_getContext(instance, request, **_kw)
+ namespace['here'] = namespace['context']
+ return namespace
+
+
def page(_context, name, permission, for_,
layer='default', template=None, class_=None,
attribute='__call__', menu=None, title=None,
@@ -310,6 +320,8 @@
# short cut to get to macros more easily
def __getitem__(self, name):
+ if name == 'macros':
+ return self.index.macros
return self.index.macros[name]
# make the template publishable
@@ -321,7 +333,7 @@
# XXX needs to deal with security from the bases?
if cdict is None:
cdict = {}
- cdict.update({'index': ViewPageTemplateFile(src, template)})
+ cdict.update({'index': FivePageTemplateFile(src, template)})
bases += (ViewMixinForTemplates,)
class_ = makeClass("SimpleViewClass from %s" % src, bases, cdict)
Modified: z3/Five/trunk/fiveconfigure.py
==============================================================================
--- z3/Five/trunk/fiveconfigure.py (original)
+++ z3/Five/trunk/fiveconfigure.py Thu Jan 13 15:05:46 2005
@@ -14,6 +14,7 @@
"""
import os
+import glob
import warnings
from zope.interface import classImplements
from zope.configuration import xmlconfig
@@ -21,6 +22,7 @@
from viewable import Viewable
from traversable import Traversable
from bridge import fromZ2Interface
+from browserconfigure import page
def findProducts():
import Products
@@ -173,3 +175,24 @@
_context.action(
discriminator = (zope2,),
)
+
+def pagesFromDirectory(_context, directory, module, for_=None,
+ layer='default', permission='zope.Public'):
+
+ if isinstance(module, basestring):
+ module = _context.resolve(module)
+
+ _prefix = os.path.dirname(module.__file__)
+ directory = os.path.join(_prefix, directory)
+
+ if not os.path.isdir(directory):
+ raise ConfigurationError(
+ "Directory %s does not exist" % directory
+ )
+
+ for fname in glob.glob(os.path.join(directory, '*.pt')):
+ name = os.path.splitext(os.path.basename(fname))[0]
+ page(_context, name=name, permission=permission,
+ layer=layer, for_=for_, template=fname)
+
+
Modified: z3/Five/trunk/fivedirectives.py
==============================================================================
--- z3/Five/trunk/fivedirectives.py (original)
+++ z3/Five/trunk/fivedirectives.py Thu Jan 13 15:05:46 2005
@@ -11,7 +11,9 @@
$Id$
"""
from zope.interface import Interface
+from zope.app.publisher.browser.metadirectives import IBasicResourceInformation
from zope.configuration.fields import GlobalObject, Tokens, PythonIdentifier
+from zope.schema import TextLine
class IImplementsDirective(Interface):
"""State that a class implements something.
@@ -77,3 +79,23 @@
u"name as the source interface.",
required=False
)
+
+class IPagesFromDirectoryDirective(IBasicResourceInformation):
+ """Register each file in a skin directory as a page resource
+ """
+
+ for_ = GlobalObject(
+ title=u"The interface this view is for.",
+ required=False
+ )
+
+ module = GlobalObject(
+ title=u"Module",
+ required=True
+ )
+
+ directory = TextLine(
+ title=u"Directory",
+ description=u"The directory containing the resource data.",
+ required=True
+ )
Modified: z3/Five/trunk/meta.zcml
==============================================================================
--- z3/Five/trunk/meta.zcml (original)
+++ z3/Five/trunk/meta.zcml Thu Jan 13 15:05:46 2005
@@ -207,6 +207,12 @@
handler=".eventconfigure.sendEvents"
/>
+ <meta:directive
+ name="pagesFromDirectory"
+ schema=".fivedirectives.IPagesFromDirectoryDirective"
+ handler=".fiveconfigure.pagesFromDirectory"
+ />
+
<!-- viewable is deprecated, use traversable instead -->
<meta:directive
Modified: z3/Five/trunk/monkey.py
==============================================================================
--- z3/Five/trunk/monkey.py (original)
+++ z3/Five/trunk/monkey.py Thu Jan 13 15:05:46 2005
@@ -30,6 +30,19 @@
HTTPRequest.setPresentationSkin = setPresentationSkin
HTTPRequest.debug = DebugFlags()
+ from RestrictedPython.Utilities import test
+ from zope.tales.pythonexpr import PythonExpr
+
+ def __call__(self, econtext):
+ __traceback_info__ = self.text
+ builtins = __builtins__.copy()
+ builtins['test'] = test
+
+ vars = self._bind_used_names(econtext, builtins)
+ return eval(self._code, vars)
+
+ PythonExpr.__call__ = __call__
+
class DebugFlags(object):
"""Debugging flags."""
Modified: z3/Five/trunk/tests/products/FiveTest/configure.zcml
==============================================================================
--- z3/Five/trunk/tests/products/FiveTest/configure.zcml (original)
+++ z3/Five/trunk/tests/products/FiveTest/configure.zcml Thu Jan 13 15:05:46 2005
@@ -36,6 +36,14 @@
<five:defaultViewable class=".simplecontent.CallableSimpleContent" />
+ <!-- five:pagesFromDirectory loads all .pt files in a directory as pages.
+ This is mainly used to load Zope2 skin templates so they can be used
+ in five skins and layers. -->
+ <five:pagesFromDirectory
+ module="Products.FiveTest"
+ directory="."
+ />
+
<browser:defaultView
for=".interfaces.ICallableSimpleContent"
name="__call__"
@@ -340,9 +348,9 @@
class=".simplecontent.SimpleContent"
/>
- <subscriber
+ <subscriber
factory=".subscriber.objectEventSubscriber"
- for="zope.app.event.interfaces.IObjectEvent"
+ for="zope.app.event.interfaces.IObjectEvent"
/>
<subscriber
More information about the z3-checkins
mailing list