Log message for revision 65708:
  Use the template's original file name for the new object.  This is to avoid
  potential clashes (currently, Five is a bit stupid about view vs. object
  look-up).
  

Changed:
  U   Products.Five/branches/philikon-local-components/component/browser.py
  U   Products.Five/branches/philikon-local-components/component/component.txt
  U   
Products.Five/branches/philikon-local-components/component/customizetemplate.pt

-=-
Modified: Products.Five/branches/philikon-local-components/component/browser.py
===================================================================
--- Products.Five/branches/philikon-local-components/component/browser.py       
2006-03-02 00:35:40 UTC (rev 65707)
+++ Products.Five/branches/philikon-local-components/component/browser.py       
2006-03-02 00:59:09 UTC (rev 65708)
@@ -15,6 +15,8 @@
 
 $Id$
 """
+import os.path
+
 from Acquisition import aq_parent, aq_acquire, aq_inner
 from Products.Five.browser import BrowserView
 from Products.Five.component import enableSite, disableSite
@@ -78,14 +80,12 @@
                    factory.__name__.startswith('SimpleViewClass'):
                 yield reg
 
-    def templateSource(self, viewname):
+    def templateFromViewname(self, viewname):
         view = getMultiAdapter((self.context, self.request),
                                name=viewname)
-        return view.index.read()
+        return view.index
 
     def doCustomizeTemplate(self, viewname):
-        src = self.templateSource(viewname)
-
         # find the nearest site
         site = self.context
         while site is not None and not IObjectManagerSite.providedBy(site):
@@ -93,9 +93,14 @@
         if site is None:
             raise TypeError("No site found")  #TODO find right exception
 
-        id = str(viewname)  #XXX this could barf
-        viewzpt = ZopePageTemplate(id, src)
-        site._setObject(id, viewzpt) #XXXthere could be a naming conflict
+        # we're using the original filename of the template, not the
+        # view name to avoid potential conflicts and/or confusion in
+        # URLs
+        template = self.templateFromViewname(viewname)
+        zpt_id = os.path.basename(template.filename)
+
+        viewzpt = ZopePageTemplate(zpt_id, template.read())
+        site._setObject(zpt_id, viewzpt) #XXXthere could be a naming conflict
         components = site.getSiteManager()
 
         # find out the view registration object so we can get at the
@@ -107,12 +112,16 @@
         view_factory = ZPTViewFactory(viewzpt, viewname)
         components.registerAdapter(view_factory, required=reg.required,
                                    provided=reg.provided, name=viewname) #XXX 
info?
+
+        viewzpt = getattr(site, zpt_id)
         return viewzpt
 
     def customizeTemplate(self, viewname):
         viewzpt = self.doCustomizeTemplate(viewname)
+        viewzpt = aq_inner(viewzpt)
         #TODO use @@absolute_url view
-        self.request.RESPONSE.redirect(viewzpt.absolute_url() + 
"/manage_workspace")
+        url = viewzpt.absolute_url() + "/manage_workspace"
+        self.request.RESPONSE.redirect(url)
 
 class ZPTViewFactory(object):
 

Modified: 
Products.Five/branches/philikon-local-components/component/component.txt
===================================================================
--- Products.Five/branches/philikon-local-components/component/component.txt    
2006-03-02 00:35:40 UTC (rev 65707)
+++ Products.Five/branches/philikon-local-components/component/component.txt    
2006-03-02 00:59:09 UTC (rev 65708)
@@ -88,7 +88,12 @@
   >>> view = zope.component.getMultiAdapter((item, request),
   ...                                       name=u"customizetemplate.html")
   >>> view = view.__of__(item)
-  >>> print view.templateSource(u'customizetemplate.html') #doctest: +ELLIPSIS
+  >>> template = view.templateFromViewname(u'customizetemplate.html')
+  >>> import os.path
+  >>> os.path.basename(template.filename)
+  'customizetemplate.pt'
+
+  >>> print template.read() #doctest: +ELLIPSIS
   <html metal:use-macro="context/@@standard_macros/view"
         i18n:domain="zope">
   ...
@@ -104,7 +109,7 @@
 (perhaps later we'd like to have the option to pick which of the sites
 above us should be targeted)
 
-  >>> zpt = getattr(site, 'customizetemplate.html')
+  >>> zpt = getattr(site, 'customizetemplate.pt')
   >>> print zpt.read() #doctest: +ELLIPSIS
   <html metal:use-macro="context/@@standard_macros/view"
         i18n:domain="zope">
@@ -144,7 +149,7 @@
   context:   <SimpleContent at item>
   container: <SimpleContent at item>
   root:      <Application at >
-  template:  <ZopePageTemplate at customizetemplate.html>
+  template:  <ZopePageTemplate at customizetemplate.pt>
   request:   <zope.publisher.browser.TestRequest instance URL=http://127.0.0.1>
   view:      <Products.Five.metaclass.SimpleViewClass from 
.../Five/component/customizetemplate.pt object at ...>
   modules:   <Products.PageTemplates.ZRPythonExpr._SecureModuleImporter 
instance at ...>

Modified: 
Products.Five/branches/philikon-local-components/component/customizetemplate.pt
===================================================================
--- 
Products.Five/branches/philikon-local-components/component/customizetemplate.pt 
    2006-03-02 00:35:40 UTC (rev 65707)
+++ 
Products.Five/branches/philikon-local-components/component/customizetemplate.pt 
    2006-03-02 00:59:09 UTC (rev 65708)
@@ -6,7 +6,7 @@
   <p i18n:translate="">This is the source of the
   <code tal:content="request/form/viewname">viewname</code>:</p>
 
-  <pre tal:content="python:view.templateSource(request.form['viewname'])">
+  <pre 
tal:content="python:view.templateFromViewname(request.form['viewname']).read()">
     template source
   </pre>
 

_______________________________________________
Zope-Checkins maillist  -  Zope-Checkins@zope.org
http://mail.zope.org/mailman/listinfo/zope-checkins

Reply via email to