[Zope-Checkins]
SVN: Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/
- fixed PageTemplateFile implementation
Andreas Jung
andreas at andreas-jung.com
Fri Dec 16 05:14:40 EST 2005
Log message for revision 40802:
- fixed PageTemplateFile implementation
- fixed manage_addPageTemplate()
- made all unittests pass
Changed:
U Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/PageTemplateFile.py
U Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/ZopePageTemplate.py
-=-
Modified: Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/PageTemplateFile.py
===================================================================
--- Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/PageTemplateFile.py 2005-12-15 23:44:52 UTC (rev 40801)
+++ Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/PageTemplateFile.py 2005-12-16 10:14:39 UTC (rev 40802)
@@ -16,33 +16,26 @@
from Globals import package_home, InitializeClass
from App.config import getConfiguration
from ZopePageTemplate import ZopePageTemplate
+from zope.app.content_types import guess_content_type
-# XXX: this needs some more work..this class is *not* used by the
-# ZopePageTemplate implementation but most likely only for class
-# using PTs for edit/add forms etc. Also the tests don't pass
+from OFS.SimpleItem import SimpleItem
+from zope.pagetemplate.pagetemplatefile import PageTemplateFile as PTF
-class PageTemplateFile(ZopePageTemplate):
+class PageTemplateFile(SimpleItem, PTF):
+
def __init__(self, filename, _prefix=None, **kw):
- self.ZBindings_edit(self._default_bindings)
- if _prefix is None:
- _prefix = getConfiguration().softwarehome
- elif not isinstance(_prefix, str):
- _prefix = package_home(_prefix)
- name = kw.get('__name__')
+ name = None
+ if kw.has_key('__name__'):
+ name = kw['__name__']
+ del kw['__name__']
+
+ PTF.__init__(self, filename, _prefix, **kw)
+
basepath, ext = os.path.splitext(filename)
if name:
- self._need__name__ = 0
- self.__name__ = name
+ self.id = self.__name__ = name
else:
- self.__name__ = os.path.basename(basepath)
- if not ext:
- # XXX This is pretty bogus, but can't be removed since
- # it's been released this way.
- filename = filename + '.zpt'
- self.filename = os.path.join(_prefix, filename)
+ self.id = self.__name__ = os.path.basename(basepath)
- ZopePageTemplate.__init__(self, os.path.basename(self.filename), open(self.filename).read(), 'text/html')
-
-
InitializeClass(PageTemplateFile)
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-15 23:44:52 UTC (rev 40801)
+++ Zope/branches/ajung-zpt-integration/lib/python/Products/PageTemplates/ZopePageTemplate.py 2005-12-16 10:14:39 UTC (rev 40802)
@@ -399,31 +399,36 @@
manage_addPageTemplateForm= FSZPT('manage_addPageTemplateForm', os.path.join(package_home(globals()), 'pt', 'ptAdd.pt'))
-def manage_addPageTemplate(self, id, title='', text=None, file=None, encoding='utf-8', submit=None, REQUEST=None, RESPONSE=None):
+def manage_addPageTemplate(self, id, title='', text=None, encoding='utf-8', submit=None, REQUEST=None, RESPONSE=None):
"Add a Page Template with optional file content."
- if file:
+ filename = ''
+ content_type = 'text/html'
+
+ if REQUEST and REQUEST.has_key('file'):
+ file = REQUEST['file']
filename = file.filename
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'):
+ headers = getattr(file, 'headers', None)
+ if headers and headers.has_key('content_type'):
content_type = headers['content_type']
else:
content_type, dummy = guess_content_type(filename, text)
-
+ encoding = sniffEncoding(text)
+
else:
- if hasattr(text, 'read'): # assume file
- text= text.read()
- if text is None:
- text = ''
- text = text or open(_default_content_fn).read()
+
+ if hasattr(text, 'read'):
+ filename = getattr(text, 'filename', '')
+ headers = getattr(text, 'headers', None)
+ text = text.read()
+ if headers and headers.has_key('content_type'):
+ content_type = headers['content_type']
+ else:
+ content_type, dummy = guess_content_type(filename, text)
+
+ if not text:
+ text = open(_default_content_fn).read()
encoding = 'utf-8'
content_type = 'text/html'
More information about the Zope-Checkins
mailing list