[Zope-Checkins]
SVN: Products.Five/branches/philikon-local-components/component/
Use Products.PageTemplates.ZopePageTemplate instead of
zope.app.zptpage.ZPTPage
Philipp von Weitershausen
philikon at philikon.de
Wed Mar 1 17:18:16 EST 2006
Log message for revision 65682:
Use Products.PageTemplates.ZopePageTemplate instead of zope.app.zptpage.ZPTPage
because the things we put in an ObjectManager really need to be SimpleItems (grrr).
Slightly refactored the view factory (local function instead of class).
Also introduced a root object in the doctest because ZopePageTemplate needs to
be able to call self.getPhysicalRoot() (which is implicitly acquired).
Changed:
U Products.Five/branches/philikon-local-components/component/browser.py
U Products.Five/branches/philikon-local-components/component/component.txt
-=-
Modified: Products.Five/branches/philikon-local-components/component/browser.py
===================================================================
--- Products.Five/branches/philikon-local-components/component/browser.py 2006-03-01 21:13:20 UTC (rev 65681)
+++ Products.Five/branches/philikon-local-components/component/browser.py 2006-03-01 22:18:14 UTC (rev 65682)
@@ -15,10 +15,12 @@
$Id$
"""
-from Acquisition import aq_parent
+from Acquisition import aq_parent, aq_acquire, aq_inner
from Products.Five.browser import BrowserView
from Products.Five.component import enableSite, disableSite
from Products.Five.component.interfaces import IObjectManagerSite
+from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate
+from Products.PageTemplates.Expressions import SecureModuleImporter
from zope.interface import providedBy
from zope.component import getMultiAdapter
@@ -26,7 +28,6 @@
from zope.component.persistentregistry import PersistentComponents
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.app.component.hooks import clearSite
-from zope.app.zptpage import ZPTPage
from zope.app.apidoc.presentation import getViews, getViewInfoDictionary
class ComponentsView(BrowserView):
@@ -92,9 +93,9 @@
if site is None:
raise TypeError("No site found") #TODO find right exception
- zpt = ZPTPage()
- zpt.source = unicode(src)
- site._setObject(viewname, zpt) #XXX there could be a naming conflict
+ id = str(viewname) #XXX this could barf
+ viewzpt = ZopePageTemplate(id, src)
+ site._setObject(id, viewzpt) #XXXthere could be a naming conflict
components = site.getSiteManager()
# find out the view registration object so we can get at the
@@ -103,31 +104,50 @@
if reg.name == viewname:
break
- components.registerAdapter(ZPTViewFactory(zpt), required=reg.required,
+ components.registerAdapter(viewFactory(viewzpt), required=reg.required,
provided=reg.provided, name=viewname) #XXX info?
- return zpt
+ return viewzpt
def customizeTemplate(self, viewname):
- zpt = self.doCustomizeTemplate(viewname)
+ viewzpt = self.doCustomizeTemplate(viewname)
#TODO use @@absolute_url view
- self.request.RESPONSE.redirect(zpt.absolute_url() + "/manage_workspace")
+ self.request.RESPONSE.redirect(viewzpt.absolute_url() + "/manage_workspace")
-class ZPTViewFactory(object):
+def viewFactory(viewzpt):
+ def view(context, request):
+ return ZPTView(viewzpt, context, request)
+ return view
- def __init__(self, zptpage):
- self.zptpage = zptpage
+class ZPTView(BrowserView):
- def __call__(self, context, request):
- return ZPTView(self.zptpage, context, request)
-
-class ZPTView(object):
-
- def __init__(self, zptpage, context, request):
- self.zptpage = zptpage
+ def __init__(self, viewzpt, context, request):
+ self.viewzpt = viewzpt
self.context = context
self.request = request
- def __call__(self, **kw):
- namespace = self.zptpage.pt_getContext(self.context, self.request, **kw)
- namespace['view'] = self #XXX get the "real" view class
- return self.zptpage.pt_render(namespace)
+# def _zptNamespace(self):
+# root = aq_acquire(self.context, 'getPhysicalRoot')()
+# here = aq_inner(self.context)
+# view = self #XXX get the "real" view class
+# return {
+# 'template': self.viewzpt,
+# 'nothing': None,
+# 'request': request,
+# 'here': here,
+# 'context': here,
+# 'container': here,
+# 'view': view,
+# 'root': root,
+# 'modules': SecureModuleImporter,
+# }
+
+ def __call__(self, *args, **kwargs):
+ view = self #XXX get the "real" view class
+
+ namespace = self.viewzpt.pt_getContext()
+ if not kwargs.has_key('args'):
+ kwargs['args'] = args
+ namespace['options'] = kwargs
+ namespace['view'] = view
+
+ return self.viewzpt.pt_render(namespace)
Modified: Products.Five/branches/philikon-local-components/component/component.txt
===================================================================
--- Products.Five/branches/philikon-local-components/component/component.txt 2006-03-01 21:13:20 UTC (rev 65681)
+++ Products.Five/branches/philikon-local-components/component/component.txt 2006-03-01 22:18:14 UTC (rev 65682)
@@ -1,12 +1,22 @@
(Local) components in Five
==========================
+Setup
+-----
+
+We need to load some important ZCML:
+
>>> from Products.Five import zcml
>>> import Products.Five.component
>>> zcml.load_config('meta.zcml', Products.Five)
>>> zcml.load_config('permissions.zcml', Products.Five)
>>> zcml.load_config('configure.zcml', Products.Five.component)
+We should also create a root object:
+
+ >>> from OFS.Application import Application
+ >>> root = Application()
+
Turning ObjectManagers into a site
----------------------------------
@@ -15,6 +25,11 @@
>>> from OFS.ObjectManager import ObjectManager
>>> site = ObjectManager()
+We need to add it to the root:
+
+ >>> id = root._setObject('site', site)
+ >>> site = root.site
+
Make this a real site by using a view that a) sets
``IObjectManagerSite``, b) sets a traversal hook and c) sets a
component registration
@@ -100,11 +115,12 @@
template and look up the view. For that to work, we also need to make
the site the current site:
- >>> zpt.source = u'doctest\n'
+ >>> zpt.pt_edit('doctest\n', content_type=None)
>>> from zope.app.component.hooks import setSite
>>> setSite(site)
>>> view = zope.component.getMultiAdapter((item, request),
... name=u"customizetemplate.html")
+ >>> view = view.__of__(item)
>>> print view()
doctest
<BLANKLINE>
More information about the Zope-Checkins
mailing list