Commit 580166e0 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Support the latest version of CMFReportTool.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@714 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1ff3a968
...@@ -38,6 +38,7 @@ from Products.ERP5Type import PropertySheet ...@@ -38,6 +38,7 @@ from Products.ERP5Type import PropertySheet
from urllib import quote from urllib import quote
from Globals import InitializeClass, PersistentMapping, DTMLFile, get_request from Globals import InitializeClass, PersistentMapping, DTMLFile, get_request
from AccessControl import Unauthorized, getSecurityManager, ClassSecurityInfo from AccessControl import Unauthorized, getSecurityManager, ClassSecurityInfo
import urllib2
from Products.ERP5Type.Utils import UpperCase from Products.ERP5Type.Utils import UpperCase
...@@ -174,7 +175,14 @@ registerFileExtension('print', FSPDFTemplate) ...@@ -174,7 +175,14 @@ registerFileExtension('print', FSPDFTemplate)
registerMetaType('ERP5 PDF Template', FSPDFTemplate) registerMetaType('ERP5 PDF Template', FSPDFTemplate)
# Dynamic Patch # Dynamic Patch
from Products.CMFReportTool.ReportTool import ReportTool, ZODBResourceHandler from Products.CMFReportTool.ReportTool import ReportTool
try:
from Products.CMFReportTool.ReportTool import ZODBResourceHandler
HAS_ZODB_RESOURCE_HANDLER=1
except ImportError:
from Products.CMFReportTool.ReportTool import ZODBHandler, ResourceHandler
HAS_ZODB_RESOURCE_HANDLER=0
from Products.CMFReportTool.RenderPDF.Parser import TemplateParser,DocumentParser from Products.CMFReportTool.RenderPDF.Parser import TemplateParser,DocumentParser
from Products.PageTemplates.Expressions import restrictedTraverse from Products.PageTemplates.Expressions import restrictedTraverse
from StringIO import StringIO from StringIO import StringIO
...@@ -182,7 +190,8 @@ import xml.dom.minidom ...@@ -182,7 +190,8 @@ import xml.dom.minidom
import urllib,os.path import urllib,os.path
class ERP5ResourceHandler(ZODBResourceHandler): if HAS_ZODB_RESOURCE_HANDLER:
class ERP5ResourceHandler(ZODBResourceHandler):
''' Wrapper for ZODB Resources and files''' ''' Wrapper for ZODB Resources and files'''
def handleZODB(self,path): def handleZODB(self,path):
...@@ -201,6 +210,31 @@ class ERP5ResourceHandler(ZODBResourceHandler): ...@@ -201,6 +210,31 @@ class ERP5ResourceHandler(ZODBResourceHandler):
obj = obj.data obj = obj.data
return StringIO(str(obj)) return StringIO(str(obj))
else:
class ERP5ResourceHandler(ResourceHandler):
''' Wrapper for ZODB Resources and files'''
def __init__(self, context=None, resource_path=None):
zodbhandler = ERP5ZODBHandler(context)
self.opener = urllib2.build_opener(zodbhandler)
class ERP5ZODBHandler(ZODBHandler):
def zodb_open(self, req):
path = req.get_selector()
path = path.split('/')
obj = restrictedTraverse(self.context,path,getSecurityManager())
# check type and e.g. call object if script ...
## for OFS.Image-like objects
if hasattr(obj,'_original'):
obj = obj.self._original._data()
elif hasattr(obj,'_data'):
obj = obj._data
elif hasattr(obj,'data'):
obj = obj.data
return StringIO(str(obj))
class ERP5ReportTool(ReportTool): class ERP5ReportTool(ReportTool):
...@@ -212,7 +246,7 @@ class ERP5ReportTool(ReportTool): ...@@ -212,7 +246,7 @@ class ERP5ReportTool(ReportTool):
context = kwargs.get('context') or self context = kwargs.get('context') or self
encoding = kwargs.get('encoding') or 'iso-8859-1' encoding = kwargs.get('encoding') or 'iso-8859-1'
rhandler = ERP5ResourceHandler(context,self.resourcePath) rhandler = ERP5ResourceHandler(context, getattr(self, 'resourcePath', None))
#template = self._v_templatecache.get(templatename,None) #template = self._v_templatecache.get(templatename,None)
#if not template: #if not template:
...@@ -220,7 +254,7 @@ class ERP5ReportTool(ReportTool): ...@@ -220,7 +254,7 @@ class ERP5ReportTool(ReportTool):
template_xml = getattr(context, templatename)(*args, **kwargs) template_xml = getattr(context, templatename)(*args, **kwargs)
template_dom = xml.dom.minidom.parseString(template_xml) template_dom = xml.dom.minidom.parseString(template_xml)
template = TemplateParser(template_dom,encoding,resourceHandler=rhandler)() template = TemplateParser(template_dom,encoding,resourceHandler=rhandler)()
self._v_templatecache[templatename] = template #self._v_templatecache[templatename] = template
document_dom = xml.dom.minidom.parseString(document_xml) document_dom = xml.dom.minidom.parseString(document_xml)
document = DocumentParser(document_dom,encoding,resourceHandler=rhandler) document = DocumentParser(document_dom,encoding,resourceHandler=rhandler)
......
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