Commit 4b53a994 authored by Andreas Jung's avatar Andreas Jung

made unittests pass

parent a7ad52c8
...@@ -214,7 +214,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -214,7 +214,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
setCookie("dtpref_rows", rows, path='/', expires=e) setCookie("dtpref_rows", rows, path='/', expires=e)
setCookie("dtpref_cols", cols, path='/', expires=e) setCookie("dtpref_cols", cols, path='/', expires=e)
REQUEST.other.update({"dtpref_cols":cols, "dtpref_rows":rows}) REQUEST.other.update({"dtpref_cols":cols, "dtpref_rows":rows})
return self.manage_main() return self.pt_editForm()
def ZScriptHTML_tryParams(self): def ZScriptHTML_tryParams(self):
"""Parameters to test the script with.""" """Parameters to test the script with."""
...@@ -242,7 +242,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -242,7 +242,7 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
} }
return c return c
security.declareProtected(view_management_screens, 'manage_main', 'read', security.declareProtected(view_management_screens, 'read',
'ZScriptHTML_tryForm') 'ZScriptHTML_tryForm')
def _exec(self, bound_names, args, kw): def _exec(self, bound_names, args, kw):
...@@ -331,10 +331,6 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable, ...@@ -331,10 +331,6 @@ class ZopePageTemplate(Script, PageTemplate, Historical, Cacheable,
security.declareProtected(view_management_screens, 'document_src') security.declareProtected(view_management_screens, 'document_src')
def document_src(self, REQUEST=None, RESPONSE=None): def document_src(self, REQUEST=None, RESPONSE=None):
"""Return expanded document source.""" """Return expanded document source."""
print 'src', self.read()
if RESPONSE is not None: if RESPONSE is not None:
RESPONSE.setHeader('Content-Type', 'text/plain') RESPONSE.setHeader('Content-Type', 'text/plain')
if REQUEST is not None and REQUEST.get('raw'): if REQUEST is not None and REQUEST.get('raw'):
...@@ -399,11 +395,11 @@ InitializeClass(FSZPT) ...@@ -399,11 +395,11 @@ InitializeClass(FSZPT)
ZopePageTemplate.pt_editForm = FSZPT('pt_editForm', os.path.join(package_home(globals()),'pt', 'ptEdit.pt')) ZopePageTemplate.pt_editForm = FSZPT('pt_editForm', os.path.join(package_home(globals()),'pt', 'ptEdit.pt'))
# this is scary, do we need this? # 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')) 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." "Add a Page Template with optional file content."
if file: if file:
...@@ -411,8 +407,23 @@ def manage_addPageTemplate(self, id, title='', file=None, encoding='utf-8', subm ...@@ -411,8 +407,23 @@ def manage_addPageTemplate(self, id, title='', file=None, encoding='utf-8', subm
text = file.read() text = file.read()
encoding = sniffEncoding(text) encoding = sniffEncoding(text)
content_type, dummy = guess_content_type(filename, 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: 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' encoding = 'utf-8'
content_type = 'text/html' content_type = 'text/html'
...@@ -423,7 +434,7 @@ def manage_addPageTemplate(self, id, title='', file=None, encoding='utf-8', subm ...@@ -423,7 +434,7 @@ def manage_addPageTemplate(self, id, title='', file=None, encoding='utf-8', subm
if RESPONSE: if RESPONSE:
if submit == " Add and Edit ": if submit == " Add and Edit ":
RESPONSE.redirect(zpt.absolute_url() + '/manage_main') RESPONSE.redirect(zpt.absolute_url() + '/pt_editForm')
else: else:
RESPONSE.redirect(self.absolute_url() + '/manage_main') RESPONSE.redirect(self.absolute_url() + '/manage_main')
else: else:
......
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
<tr> <tr>
<td align="left" valign="middle" class="form-label">Encoding</td> <td align="left" valign="middle" class="form-label">Encoding</td>
<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> </td>
</tr> </tr>
......
...@@ -12,6 +12,7 @@ import Zope2 ...@@ -12,6 +12,7 @@ import Zope2
import transaction import transaction
from Testing.makerequest import makerequest from Testing.makerequest import makerequest
from Products.PageTemplates.ZopePageTemplate import _default_content_fn
class ZPTRegressions(unittest.TestCase): class ZPTRegressions(unittest.TestCase):
...@@ -34,9 +35,9 @@ class ZPTRegressions(unittest.TestCase): ...@@ -34,9 +35,9 @@ class ZPTRegressions(unittest.TestCase):
def testAddWithoutParams(self): def testAddWithoutParams(self):
pt = self._addPT('pt1') 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.title, '')
self.assertEqual(pt.document_src(), default_text) self.assertEqual(pt.document_src().strip(), default_text.strip())
def testAddWithRequest(self): def testAddWithRequest(self):
"""Test manage_add with file""" """Test manage_add with file"""
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment