本文整理汇总了Python中Products.PageTemplates.ZopePageTemplate.ZopePageTemplate.pt_upload方法的典型用法代码示例。如果您正苦于以下问题:Python ZopePageTemplate.pt_upload方法的具体用法?Python ZopePageTemplate.pt_upload怎么用?Python ZopePageTemplate.pt_upload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Products.PageTemplates.ZopePageTemplate.ZopePageTemplate
的用法示例。
在下文中一共展示了ZopePageTemplate.pt_upload方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: pt_upload
# 需要导入模块: from Products.PageTemplates.ZopePageTemplate import ZopePageTemplate [as 别名]
# 或者: from Products.PageTemplates.ZopePageTemplate.ZopePageTemplate import pt_upload [as 别名]
def pt_upload(self, REQUEST, file=''):
"""Replace the document with the text in file."""
if SUPPORTS_WEBDAV_LOCKS and self.wl_isLocked():
raise ResourceLockedError, "File is locked via WebDAV"
if type(file) is not StringType:
if not file: raise ValueError, 'File not specified'
file = file.read()
if file.startswith("PK") : # FIXME: this condition is probably not enough
# this is a OOo zip file, extract the content
builder = OOoBuilder(file)
attached_files_list = [n for n in builder.getNameList()
if n.startswith(self._OLE_directory_prefix)
or n.startswith('Pictures')
or n == 'META-INF/manifest.xml' ]
# destroy a possibly pre-existing OLE document set
if self.OLE_documents_zipstring:
self.OLE_documents_zipstring = None
# create a zip archive and store it
if attached_files_list:
memory_file = StringIO()
try:
zf = ZipFile(memory_file, mode='w', compression=ZIP_DEFLATED)
except RuntimeError:
zf = ZipFile(memory_file, mode='w')
for attached_file in attached_files_list:
zf.writestr(attached_file, builder.extract(attached_file) )
zf.close()
memory_file.seek(0)
self.OLE_documents_zipstring = memory_file.read()
self.content_type = builder.getMimeType()
file = builder.prepareContentXml(self.ooo_xml_file_id)
return ZopePageTemplate.pt_upload(self, REQUEST, file)