[z3-checkins] r5538 - z3/Five/branch/dreamcatcher-cmf-compat-branch
dreamcatcher at codespeak.net
dreamcatcher at codespeak.net
Mon Jul 12 16:49:47 MEST 2004
Author: dreamcatcher
Date: Mon Jul 12 16:49:46 2004
New Revision: 5538
Added:
z3/Five/branch/dreamcatcher-cmf-compat-branch/traversal.py (contents, props changed)
Modified:
z3/Five/branch/dreamcatcher-cmf-compat-branch/browserconfigure.py
z3/Five/branch/dreamcatcher-cmf-compat-branch/configure.zcml
z3/Five/branch/dreamcatcher-cmf-compat-branch/fiveconfigure.py
z3/Five/branch/dreamcatcher-cmf-compat-branch/fivedirectives.py
z3/Five/branch/dreamcatcher-cmf-compat-branch/meta.zcml
Log:
Some changes to get Plone's main_template to render at all.
Modified: z3/Five/branch/dreamcatcher-cmf-compat-branch/browserconfigure.py
==============================================================================
--- z3/Five/branch/dreamcatcher-cmf-compat-branch/browserconfigure.py (original)
+++ z3/Five/branch/dreamcatcher-cmf-compat-branch/browserconfigure.py Mon Jul 12 16:49:46 2004
@@ -29,6 +29,7 @@
from api import BrowserView
from metaclass import makeClass
from security import getSecurityInfo, protectClass, initializeClass
+from ComputedAttribute import ComputedAttribute
def page(_context, name, permission, for_,
layer='default', template=None, class_=None,
@@ -94,7 +95,7 @@
# some security declarations on it so we really shouldn't
# modify the original. So, instead we make a new class
# with just one base class -- the original
- new_class = makeClass(class_.__name__, (class_), cdict)
+ new_class = makeClass(class_.__name__, (class_,), cdict)
else:
# template
@@ -159,19 +160,59 @@
class ViewMixinForTemplates(BrowserView):
+ def getId(self):
+ """Return our __name__ or the template id
+ """
+ return getattr(self, '__name__', self.index.getId())
+
# short cut to get to macros more easily
def __getitem__(self, name):
return self.index.macros[name]
+ def _macros(self):
+ """ """
+ return self.index.macros
+
+ macros = ComputedAttribute(_macros)
+
# make the template publishable
def __call__(self, *args, **kw):
return self.index(self, *args, **kw)
+class ClassicPTFile(ViewPageTemplateFile):
+
+ def getId(self):
+ """Return the template id.
+
+ In our case, we just return the file basename for
+ backward compatibility.
+ """
+ fname = os.path.basename(self.pt_source_file())
+ return os.path.splitext(fname)[0]
+
+ def title_or_id(self):
+ """Return the template title or id.
+
+ In our case, we just return the id
+ backward compatibility.
+ """
+ return self.getId()
+
+ def pt_getContext(self, instance, request, **kw):
+ ns = super(ClassicPTFile, self).pt_getContext(instance, request, **kw)
+ # Alias here for backwards compat with Zope2 apps that
+ # haven't converted to using 'context'. We may wrapp 'here' with
+ # a proxy that raises a DeprecationWarning on access.
+ # We may also do the same for 'views'.
+ ns['here'] = instance.context
+ ns['test'] = lambda x, y, z: x and y or z
+ return ns
+
def makeClassForTemplate(src, template=None, used_for=None, bases=(), cdict=None):
# XXX needs to deal with security from the bases?
if cdict is None:
cdict = {}
- cdict.update({'index': ViewPageTemplateFile(src, template)})
+ cdict.update({'index': ClassicPTFile(src, template)})
bases += (ViewMixinForTemplates,)
class_ = makeClass("SimpleViewClass from %s" % src, bases, cdict)
Modified: z3/Five/branch/dreamcatcher-cmf-compat-branch/configure.zcml
==============================================================================
--- z3/Five/branch/dreamcatcher-cmf-compat-branch/configure.zcml (original)
+++ z3/Five/branch/dreamcatcher-cmf-compat-branch/configure.zcml Mon Jul 12 16:49:46 2004
@@ -9,7 +9,7 @@
<!-- do 'traditional' traversing by default; needed by ZPT -->
<adapter
for="*"
- factory="zope.app.traversing.adapters.DefaultTraversable"
+ factory=".traversal.ViewTraversable"
provides="zope.app.traversing.interfaces.ITraversable" />
<!-- make Zope 2's REQUEST implement the right thing -->
Modified: z3/Five/branch/dreamcatcher-cmf-compat-branch/fiveconfigure.py
==============================================================================
--- z3/Five/branch/dreamcatcher-cmf-compat-branch/fiveconfigure.py (original)
+++ z3/Five/branch/dreamcatcher-cmf-compat-branch/fiveconfigure.py Mon Jul 12 16:49:46 2004
@@ -13,9 +13,11 @@
$Id$
"""
import os
+import glob
from zope.interface import classImplements
from zope.configuration import xmlconfig
from zope.app.component.interface import provideInterface
+from browserconfigure import page
from viewable import Viewable
@@ -64,14 +66,35 @@
interface)
)
-def classViewable(class_):
- if hasattr(class_, '__bobo_traverse__'):
+def classViewable(class_, force=False):
+ if hasattr(class_, '__bobo_traverse__') and not force:
raise TypeError("__bobo_traverse already__ exists on %s" % class_)
setattr(class_, '__bobo_traverse__', Viewable.__bobo_traverse__)
-def viewable(_context, class_):
+def viewable(_context, class_, force=False):
_context.action(
discriminator = (class_,),
callable = classViewable,
- args = (class_,)
+ args = (class_, force)
)
+
+def skinDirectory(_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/branch/dreamcatcher-cmf-compat-branch/fivedirectives.py
==============================================================================
--- z3/Five/branch/dreamcatcher-cmf-compat-branch/fivedirectives.py (original)
+++ z3/Five/branch/dreamcatcher-cmf-compat-branch/fivedirectives.py Mon Jul 12 16:49:46 2004
@@ -11,7 +11,8 @@
$Id$
"""
from zope.interface import Interface
-from zope.configuration.fields import GlobalObject, Tokens
+from zope.configuration.fields import GlobalObject, Tokens, Bool
+from zope.schema import TextLine
class IImplementsDirective(Interface):
"""State that a class implements something.
@@ -35,3 +36,28 @@
required=True
)
+ force = Bool(
+ title=u"Force",
+ description=u"Force making the class viewable",
+ required=False,
+ default=False)
+
+class ISkinDirectoryDirective(Interface):
+ """Register each file in a skin directory as a 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/branch/dreamcatcher-cmf-compat-branch/meta.zcml
==============================================================================
--- z3/Five/branch/dreamcatcher-cmf-compat-branch/meta.zcml (original)
+++ z3/Five/branch/dreamcatcher-cmf-compat-branch/meta.zcml Mon Jul 12 16:49:46 2004
@@ -68,28 +68,34 @@
</meta:complexDirective>
<meta:directive
- name="layer"
- schema="zope.app.component.metadirectives.ILayerDirective"
- handler="zope.app.component.metaconfigure.layer"
- />
-
- <meta:directive
- name="skin"
- schema="zope.app.component.metadirectives.ISkinDirective"
- handler="zope.app.component.metaconfigure.skin"
- />
-
- <meta:directive
- name="defaultSkin"
- schema="zope.app.component.metadirectives.IDefaultSkinDirective"
- handler="zope.app.component.metaconfigure.defaultSkin"
- />
+ name="view"
+ schema="zope.app.component.metadirectives.IViewDirective"
+ handler="zope.app.component.metaconfigure.view"
+ />
</meta:directives>
<meta:directives namespace="http://namespaces.zope.org/browser">
<meta:directive
+ name="layer"
+ schema="zope.app.publisher.browser.metadirectives.ILayerDirective"
+ handler="zope.app.publisher.browser.metaconfigure.layer"
+ />
+
+ <meta:directive
+ name="skin"
+ schema="zope.app.publisher.browser.metadirectives.ISkinDirective"
+ handler="zope.app.publisher.browser.metaconfigure.skin"
+ />
+
+ <meta:directive
+ name="defaultSkin"
+ schema="zope.app.publisher.browser.metadirectives.IDefaultSkinDirective"
+ handler="zope.app.publisher.browser.metaconfigure.defaultSkin"
+ />
+
+ <meta:directive
name="page"
schema="zope.app.publisher.browser.metadirectives.IPageDirective"
handler=".browserconfigure.page"
@@ -108,6 +114,19 @@
</meta:complexDirective>
+ <meta:complexDirective
+ name="editform"
+ schema="zope.app.form.browser.metadirectives.IEditFormDirective"
+ handler="zope.app.form.browser.metaconfigure.EditFormDirective"
+ >
+
+ <meta:subdirective
+ name="widget"
+ schema="zope.app.form.browser.metadirectives.IWidgetSubdirective"
+ />
+
+ </meta:complexDirective>
+
</meta:directives>
<meta:directives namespace="http://namespaces.zope.org/five">
@@ -115,28 +134,34 @@
<!-- specific to Five -->
<meta:directive
- name="loadProducts"
- schema="zope.interface.Interface"
- handler=".fiveconfigure.loadProducts"
- />
+ name="loadProducts"
+ schema="zope.interface.Interface"
+ handler=".fiveconfigure.loadProducts"
+ />
+
+ <meta:directive
+ name="loadProductsOverrides"
+ schema="zope.interface.Interface"
+ handler=".fiveconfigure.loadProductsOverrides"
+ />
<meta:directive
- name="loadProductsOverrides"
- schema="zope.interface.Interface"
- handler=".fiveconfigure.loadProductsOverrides"
- />
+ name="implements"
+ schema=".fivedirectives.IImplementsDirective"
+ handler=".fiveconfigure.implements"
+ />
<meta:directive
- name="implements"
- schema=".fivedirectives.IImplementsDirective"
- handler=".fiveconfigure.implements"
- />
+ name="viewable"
+ schema=".fivedirectives.IViewableDirective"
+ handler=".fiveconfigure.viewable"
+ />
<meta:directive
- name="viewable"
- schema=".fivedirectives.IViewableDirective"
- handler=".fiveconfigure.viewable"
- />
+ name="skinDirectory"
+ schema=".fivedirectives.ISkinDirectoryDirective"
+ handler=".fiveconfigure.skinDirectory"
+ />
</meta:directives>
Added: z3/Five/branch/dreamcatcher-cmf-compat-branch/traversal.py
==============================================================================
--- (empty file)
+++ z3/Five/branch/dreamcatcher-cmf-compat-branch/traversal.py Mon Jul 12 16:49:46 2004
@@ -0,0 +1,36 @@
+##############################################################################
+#
+# Copyright (c) 2004 Five Contributors. All rights reserved.
+#
+# This software is distributed under the terms of the Zope Public
+# License (ZPL) v2.1. See COPYING.txt for more information.
+#
+##############################################################################
+"""Provide basic traversal functionality
+
+$Id: browser.py 5259 2004-06-23 15:59:52Z philikon $
+"""
+
+from types import FunctionType
+from zope.exceptions import NotFoundError
+from zope.app.traversing.adapters import DefaultTraversable
+from zope.component import getView
+from zope.component import getView, ComponentLookupError
+
+class ViewTraversable(DefaultTraversable):
+
+ def traverse(self, name, furtherPath):
+ context = self._subject
+ request = getattr(context, 'REQUEST', None)
+ if request is not None:
+ try:
+ return getView(context, name, request).__of__(context)
+ except ComponentLookupError:
+ pass
+ try:
+ subob = super(ViewTraversable, self).traverse(name, furtherPath)
+ if subob is not None:
+ return subob
+ except (NotFoundError, KeyError):
+ pass
+ raise NotFoundError(context, name)
More information about the z3-checkins
mailing list