Commit 1e82948c authored by Jérome Perrin's avatar Jérome Perrin

odt_style: Fix hierarchy of ReportSection(title=)

When using report sections with title, this is supposed to create outline
in PDF, but this seem to became broken somewhere in the last 10 years.

This repair by using text:h instead of text:p and by setting
text:outline-level
parent 1dcdeece
...@@ -159,10 +159,10 @@ ...@@ -159,10 +159,10 @@
render_prefix=render_prefix)"> render_prefix=render_prefix)">
<tal:block metal:define-macro="render_report_section"> <tal:block metal:define-macro="render_report_section">
<tal:block tal:condition="report_item/getTitle"> <tal:block tal:condition="report_item/getTitle">
<text:p <text:h
tal:content="report_item/getTitle" tal:content="report_item/getTitle"
tal:attributes="text:style-name string:Heading_20_${report_item/getLevel}" tal:attributes="text:style-name string:Heading_20_${report_item/getLevel}; text:outline-level report_item/getLevel"
>report item title</text:p><text:p/> >report item title</text:h><text:p/>
</tal:block> </tal:block>
<tal:block tal:condition="report_item/getFormId"> <tal:block tal:condition="report_item/getFormId">
......
from Products.ERP5Form.Report import ReportSection
return [
ReportSection(title='1. First', level=1),
ReportSection(title='1.1 First / First', level=2),
ReportSection(title='1.2 First / Second', level=2),
ReportSection(title='1.2.1 First / Second / First', level=3),
ReportSection(title='2. Second', level=1),
]
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>FooModule_getHierarchyTestReportSectionList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ERP5 Report" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>FooModule_viewHierarchyTestReport</string> </value>
</item>
<item>
<key> <string>action_title</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>edit_order</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>enctype</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>group_list</string> </key>
<value>
<list>
<string>left</string>
<string>right</string>
<string>center</string>
<string>bottom</string>
<string>hidden</string>
</list>
</value>
</item>
<item>
<key> <string>groups</string> </key>
<value>
<dictionary>
<item>
<key> <string>bottom</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>center</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>hidden</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>left</string> </key>
<value>
<list/>
</value>
</item>
<item>
<key> <string>right</string> </key>
<value>
<list/>
</value>
</item>
</dictionary>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>FooModule_viewHierarchyTestReport</string> </value>
</item>
<item>
<key> <string>method</string> </key>
<value> <string>POST</string> </value>
</item>
<item>
<key> <string>name</string> </key>
<value> <string>FooModule_viewHierarchyTestReport</string> </value>
</item>
<item>
<key> <string>pt</string> </key>
<value> <string>report_view</string> </value>
</item>
<item>
<key> <string>report_method</string> </key>
<value> <string>FooModule_getHierarchyTestReportSectionList</string> </value>
</item>
<item>
<key> <string>row_length</string> </key>
<value> <int>4</int> </value>
</item>
<item>
<key> <string>stored_encoding</string> </key>
<value> <string>UTF-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Hierarchy Test</string> </value>
</item>
<item>
<key> <string>unicode_mode</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>update_action</string> </key>
<value> <string></string> </value>
</item>
<item>
<key> <string>update_action_title</string> </key>
<value> <string></string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
# #
############################################################################## ##############################################################################
import io
import unittest import unittest
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.utils import DummyLocalizer from Products.ERP5Type.tests.utils import DummyLocalizer
...@@ -34,6 +35,8 @@ from Products.ERP5Form.Selection import Selection ...@@ -34,6 +35,8 @@ from Products.ERP5Form.Selection import Selection
from Testing import ZopeTestCase from Testing import ZopeTestCase
from Products.ERP5OOo.tests.utils import Validator from Products.ERP5OOo.tests.utils import Validator
import httplib import httplib
import lxml.html
import PyPDF2
HTTP_OK = httplib.OK HTTP_OK = httplib.OK
...@@ -265,6 +268,57 @@ class TestOOoStyle(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -265,6 +268,57 @@ class TestOOoStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
self.assertEqual('attachment', content_disposition.split(';')[0]) self.assertEqual('attachment', content_disposition.split(';')[0])
self._validate(response.getBody()) self._validate(response.getBody())
def test_report_view_report_section_title(self):
response = self.publish(
'/%s/foo_module/FooModule_viewHierarchyTestReport'
% self.portal.getId(), self.auth)
self.assertEqual(HTTP_OK, response.getStatus())
content_type = response.getHeader('content-type')
self.assertTrue(content_type.startswith(self.content_type), content_type)
self._validate(response.getBody())
# check the hierarchy is properly kept ...
if self.skin == 'ODT':
# ... in pdf
response = self.publish(
'/%s/foo_module/FooModule_viewHierarchyTestReport?format=pdf'
% self.portal.getId(), self.auth)
pdf = PyPDF2.PdfFileReader(io.BytesIO(response.getBody()))
def getOutlineTitles(outlines):
for outline in outlines:
if isinstance(outline, list):
yield list(getOutlineTitles(outline))
else:
yield outline['/Title']
self.assertEqual(
list(getOutlineTitles(pdf.getOutlines())),
[
"1. First",
[
"1.1 First / First",
"1.2 First / Second",
["1.2.1 First / Second / First"],
],
"2. Second",
],
)
# ..and in html
response = self.publish(
'/%s/foo_module/FooModule_viewHierarchyTestReport?format=html'
% self.portal.getId(), self.auth)
tree = lxml.html.fromstring(response.getBody())
self.assertEqual(
[node.text for node in tree.findall('.//h1')],
['1. First', '2. Second'])
self.assertEqual(
[node.text for node in tree.findall('.//h2')],
['1.1 First / First', '1.2 First / Second'])
self.assertEqual(
[node.text for node in tree.findall('.//h3')],
['1.2.1 First / Second / First'])
def test_form_view_encoding(self): def test_form_view_encoding(self):
self.portal.person_module.pers.setFirstName('Jérome') self.portal.person_module.pers.setFirstName('Jérome')
response = self.publish('/%s/person_module/pers/Person_view' response = self.publish('/%s/person_module/pers/Person_view'
......
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