[Zope-Checkins] SVN: Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/ made unittests pass

Andreas Jung andreas at andreas-jung.com
Sun Dec 11 09:46:00 EST 2005


Log message for revision 40706:
  made unittests pass
  

Changed:
  U   Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/ZopePageTemplate.py
  U   Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/pt/ptEdit.pt
  U   Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py

-=-
Modified: Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/ZopePageTemplate.py
===================================================================
--- Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/ZopePageTemplate.py	2005-12-11 13:56:10 UTC (rev 40705)
+++ Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/ZopePageTemplate.py	2005-12-11 14:46:00 UTC (rev 40706)
@@ -214,7 +214,7 @@
         setCookie("dtpref_rows", rows, path='/', expires=e)
         setCookie("dtpref_cols", cols, path='/', expires=e)
         REQUEST.other.update({"dtpref_cols":cols, "dtpref_rows":rows})
-        return self.manage_main()
+        return self.pt_editForm()
 
     def ZScriptHTML_tryParams(self):
         """Parameters to test the script with."""
@@ -242,7 +242,7 @@
              }
         return c
 
-    security.declareProtected(view_management_screens, 'manage_main', 'read',
+    security.declareProtected(view_management_screens, 'read',
       'ZScriptHTML_tryForm')
 
     def _exec(self, bound_names, args, kw):
@@ -331,10 +331,6 @@
     security.declareProtected(view_management_screens, 'document_src')
     def document_src(self, REQUEST=None, RESPONSE=None):
         """Return expanded document source."""
-
-        print 'src', self.read()
-
-
         if RESPONSE is not None:
             RESPONSE.setHeader('Content-Type', 'text/plain')
         if REQUEST is not None and REQUEST.get('raw'):
@@ -399,11 +395,11 @@
 
 ZopePageTemplate.pt_editForm = FSZPT('pt_editForm', os.path.join(package_home(globals()),'pt', 'ptEdit.pt'))
 # this is scary, do we need this?
-ZopePageTemplate.manage = ZopePageTemplate.manage_main = ZopePageTemplate.pt_editForm
+ZopePageTemplate.manage = ZopePageTemplate.pt_editForm
 
 manage_addPageTemplateForm= FSZPT('manage_addPageTemplateForm', os.path.join(package_home(globals()), 'pt', 'ptAdd.pt'))
 
-def manage_addPageTemplate(self, id, title='', file=None, encoding='utf-8', submit=None, RESPONSE=None):
+def manage_addPageTemplate(self, id, title='', text=None, file=None, encoding='utf-8', submit=None, REQUEST=None, RESPONSE=None):
     "Add a Page Template with optional file content."
 
     if file:
@@ -411,8 +407,23 @@
         text = file.read()
         encoding = sniffEncoding(text)
         content_type, dummy = guess_content_type(filename, text) 
+    elif REQUEST and REQUEST.has_key('file'):
+        f = REQUEST['file']
+        filename = f.filename
+        text = f.read()
+        encoding = sniffEncoding(text)
+        headers = getattr(f, 'headers')
+        if headers.has_key('content_type'):
+            content_type = headers['content_type']
+        else:
+            content_type, dummy = guess_content_type(filename, text) 
+    
     else:
-        text = open(_default_content_fn).read()
+        if hasattr(text, 'read'):  # assume file
+            text= text.read()
+        if text is None:
+            text = ''
+        text = text or open(_default_content_fn).read()
         encoding = 'utf-8'
         content_type = 'text/html'
 
@@ -423,7 +434,7 @@
 
     if RESPONSE:    
         if submit == " Add and Edit ":
-            RESPONSE.redirect(zpt.absolute_url() + '/manage_main')
+            RESPONSE.redirect(zpt.absolute_url() + '/pt_editForm')
         else:
             RESPONSE.redirect(self.absolute_url() + '/manage_main')
     else:        

Modified: Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/pt/ptEdit.pt
===================================================================
--- Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/pt/ptEdit.pt	2005-12-11 13:56:10 UTC (rev 40705)
+++ Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/pt/ptEdit.pt	2005-12-11 14:46:00 UTC (rev 40706)
@@ -53,7 +53,7 @@
   <tr> 
     <td align="left" valign="middle" class="form-label">Encoding</td>
     <td>
-      <input type="text" readonly name="encoding" tal:attributes="value context/pt_encoding"/>
+      <input type="text" readonly name="encoding" tal:attributes="value context/pt_encoding" style="background-color: #bbbbbb; "/>
     </td>
   </tr>
 

Modified: Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py
===================================================================
--- Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py	2005-12-11 13:56:10 UTC (rev 40705)
+++ Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/tests/testZopePageTemplate.py	2005-12-11 14:46:00 UTC (rev 40706)
@@ -12,6 +12,7 @@
 import transaction
 
 from Testing.makerequest import makerequest
+from Products.PageTemplates.ZopePageTemplate import _default_content_fn
 
 class ZPTRegressions(unittest.TestCase):
 
@@ -34,9 +35,9 @@
 
     def testAddWithoutParams(self):
         pt = self._addPT('pt1')
-        default_text = open(pt._default_content_fn).read()
+        default_text = open(_default_content_fn).read()
         self.assertEqual(pt.title, '')
-        self.assertEqual(pt.document_src(), default_text)
+        self.assertEqual(pt.document_src().strip(), default_text.strip())
 
     def testAddWithRequest(self):
         """Test manage_add with file"""



More information about the Zope-Checkins mailing list