Commit 4a436699 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Workarounds for reportlab. We use UTF-8 but reportlab does not support UTF-8 yet.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@1461 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent bc2ddf2b
...@@ -135,9 +135,9 @@ class PDFTemplate(ZopePageTemplate): ...@@ -135,9 +135,9 @@ class PDFTemplate(ZopePageTemplate):
# Proxy method to PageTemplate # Proxy method to PageTemplate
def pt_render(self, source=0, extra_context={}): def pt_render(self, source=0, extra_context={}):
doc_xml = ZopePageTemplate.pt_render(self, source=source, extra_context=extra_context) doc_xml = ZopePageTemplate.pt_render(self, source=source, extra_context=extra_context)
# Unmarshall arguments to __call__ API # Unmarshall arguments to __call__ API
args = extra_context.get('options', None) args = extra_context.get('options', None)
kwargs = extra_context.copy() kwargs = extra_context.copy()
if kwargs.has_key('options'): del kwargs['options'] if kwargs.has_key('options'): del kwargs['options']
if kwargs.has_key('context'): del kwargs['context'] if kwargs.has_key('context'): del kwargs['context']
...@@ -277,22 +277,34 @@ class ERP5ReportTool(ReportTool): ...@@ -277,22 +277,34 @@ class ERP5ReportTool(ReportTool):
context = self context = self
encoding = kwargs.get('encoding') or 'UTF-8' encoding = kwargs.get('encoding') or 'UTF-8'
#LOG('ERP5ReportTool', 0, 'encoding = %r' % encoding)
rhandler = ERP5ResourceHandler(context, getattr(self, 'resourcePath', None)) rhandler = ERP5ResourceHandler(context, getattr(self, 'resourcePath', None))
#template = self._v_templatecache.get(templatename,None) # if zope gives us the xml in unicode
#if not template: # we need to encode it before it can be parsed
if 1: template_xml = getattr(context, templatename)(*args, **kwargs)
template_xml = getattr(context, templatename)(*args, **kwargs) if type(template_xml) is type(u''):
if type(template_xml) is not type(u'a'): template_xml = self._encode(template_xml, encoding)
template_xml = unicode(template_xml,encoding=encoding) if type(document_xml) is type(u''):
template_xml = template_xml.encode('UTF-8') document_xml = self._encode(document_xml, encoding)
template_dom = xml.dom.minidom.parseString(template_xml) #LOG('ERP5ReportTool', 0, 'template_xml = %r, document_xml = %r' % (template_xml, document_xml))
template = TemplateParser(template_dom,encoding,resourceHandler=rhandler)()
#self._v_templatecache[templatename] = template # XXXXX Because reportlab does not support UTF-8, use Latin-1. What a mess.
template_xml = unicode(template_xml,encoding).encode('iso-8859-1')
document_xml = unicode(document_xml,encoding).encode('iso-8859-1')
encoding = 'iso-8859-1'
# create the PDFTemplate from xml
template_dom = xml.dom.minidom.parseString(template_xml)
template_dom.encoding = encoding
template = TemplateParser(template_dom,encoding,resourceHandler=rhandler)()
# create the PDFDocment from xml
document_dom = xml.dom.minidom.parseString(document_xml) document_dom = xml.dom.minidom.parseString(document_xml)
document_dom.encoding = encoding
document = DocumentParser(document_dom,encoding,resourceHandler=rhandler) document = DocumentParser(document_dom,encoding,resourceHandler=rhandler)
# create the PDF itself using the document and the template
buf = StringIO() buf = StringIO()
document(template,buf) document(template,buf)
buf.seek(0) buf.seek(0)
......
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