Commit 9f5b4f8f authored by Jérome Perrin's avatar Jérome Perrin

ods_style: repair support of percentage float fields after libreoffice7

With libreoffice5, float fields with input style 12.3% were correctly
rendered as percentages without the need of an explicit
number:percentage-style style, but with libreoffice7 it seems required,
without this, a value of 2.05 is rendered as "2" instead of the expected
"205%"
parent b9448fa1
......@@ -101,10 +101,12 @@
<tal:block tal:condition="python: field is not None">
<tal:block tal:condition="python:field.meta_type in ['FloatField','IntegerField'] or (field.meta_type == 'ProxyField' and field.getRecursiveTemplateField().meta_type in ['FloatField','IntegerField'])">
<tal:block tal:define="precision python: (field.meta_type == 'FloatField' or (field.meta_type == 'ProxyField' and field.getRecursiveTemplateField().meta_type == 'FloatField')) and field.get_value('precision') or 0;
figure_style_name string:${style_prefix}figure_${precision};
input_style python: (field.meta_type == 'FloatField' or (field.meta_type == 'ProxyField' and field.getRecursiveTemplateField().meta_type == 'FloatField')) and field.get_value('input_style') or ''">
input_style python: (field.meta_type == 'FloatField' or (field.meta_type == 'ProxyField' and field.getRecursiveTemplateField().meta_type == 'FloatField')) and field.get_value('input_style') or '';
percentage_or_figure python: ('%' in input_style) and 'percentage' or 'figure';
style_name string:${style_prefix}${percentage_or_figure}_${precision};
">
<table:table-cell tal:attributes="office:value value;
table:style-name figure_style_name;
table:style-name style_name;
office:value-type python: ('%' in input_style) and 'percentage' or 'float'"
table:style-name="figure">
<text:p tal:content="python: field.render_pdf(value)" />
......
......@@ -98,6 +98,9 @@
<style:style style:name="with_border_text" style:family="table-cell" style:parent-style-name="Default">
<style:table-cell-properties fo:border-left='none' fo:border-bottom='0.002cm solid #000000' fo:border-right='0.002cm solid #000000' fo:border-top='0.002cm solid #000000'/>
</style:style>
<style:style style:name="with_border_figure" style:family="table-cell" style:parent-style-name="figure">
<style:table-cell-properties fo:border-left='none' fo:border-bottom='0.002cm solid #000000' fo:border-right='0.002cm solid #000000' fo:border-top='0.002cm solid #000000'/>
</style:style>
<number:date-style style:name="date_style" number:automatic-order="true">
<number:day number:style="long"/>
......@@ -129,7 +132,7 @@
<style:style style:name="date_with_time" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="date_with_time_style">
<style:table-cell-properties style:vertical-align='middle' style:repeat-content='false' style:text-align-source='fix' fo:border-right='0.002cm solid #000000' />
</style:style>
<style:style style:name="with_border_date_with_time" style:family="table-cell" style:parent-style-name="date_with_time" style:data-style-namexxx="date_style">
<style:style style:name="with_border_date_with_time" style:family="table-cell" style:parent-style-name="date_with_time" style:data-style-name="date_style_with_time">
<style:table-cell-properties fo:border-left='none' fo:border-bottom='0.002cm solid #000000' fo:border-right='0.002cm solid #000000' fo:border-top='0.002cm solid #000000'/>
</style:style>
......@@ -157,6 +160,31 @@
</style:style>
</tal:block>
<tal:block tal:define="percentage_data_precision_style_name string:percentage_data_precision_${precision}">
<number:percentage-style style:name="percentage_data_precision_X" tal:attributes="style:name percentage_data_precision_style_name">
<number:number number:decimal-places="X" number:min-integer-digits="1" tal:attributes="number:decimal-places precision"/>
<number:text>%</number:text>
</number:percentage-style>
<tal:block tal:repeat="style_prefix_name python: here.Base_getODSSupportedStylePrefixList()">
<style:style
style:name="percentage_X"
style:family="table-cell"
style:parent-style-name="figure"
style:data-style-name="percentage_data_precision_X"
tal:attributes="style:name string:${style_prefix_name}percentage_${precision};
style:data-style-name percentage_data_precision_style_name;
style:parent-style-name string:${style_prefix_name}figure"/>
</tal:block>
<style:style
style:name="with_border_percentage_X"
style:family="table-cell"
style:parent-style-name="percentage_X"
style:data-style-name="percentage_data_precision_style_name"
tal:attributes="style:name string:with_border_percentage_${precision};
style:data-style-name percentage_data_precision_style_name;
style:parent-style-name string:percentage_${precision}">
<style:table-cell-properties fo:border-left='none' fo:border-bottom='0.002cm solid #000000' fo:border-right='0.002cm solid #000000' fo:border-top='0.002cm solid #000000'/>
</style:style>
</tal:block>
</tal:block>
</office:automatic-styles>
......
......@@ -433,6 +433,70 @@ class TestOOoStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
self.assertEqual('attachment', content_disposition.split(';')[0])
self._validate(response.getBody())
def test_float_field(self):
foo = self.portal.foo_module.newContent(
portal_type='Foo',
delivery_ratio=1.234,
quantity=4.56,
)
foo.newContent(
portal_type='Foo Line',
delivery_ratio=4.321,
quantity=6.54,
)
response = self.publish(
'%s/Foo_viewFloatField' % foo.getPath(), basic=self.auth)
self.assertEqual(HTTP_OK, response.getStatus())
content_type = response.getHeader('content-type')
self.assertTrue(content_type.startswith(self.content_type), content_type)
content_disposition = response.getHeader('content-disposition')
self.assertEqual('attachment', content_disposition.split(';')[0])
self._validate(response.getBody())
def get_figure_field_value(tree):
if self.skin == 'ODT':
return tree.xpath(
'normalize-space(//tr/td/*[normalize-space(.)="Quantity"]/../following-sibling::td)')
elif self.skin == 'ODS':
return tree.xpath(
'normalize-space(//tr/td/*/*[normalize-space(.)="Quantity"]/../../following-sibling::td)')
def get_percentage_field_value(tree):
if self.skin == 'ODT':
return tree.xpath(
'normalize-space(//tr/td/*[normalize-space(.)="Delivery Ratio"]/../following-sibling::td)')
elif self.skin == 'ODS':
return tree.xpath(
'normalize-space(//tr/td/*/*[normalize-space(.)="Delivery Ratio"]/../../following-sibling::td)')
def get_figure_listbox_field_value(tree):
if self.skin == 'ODT':
return tree.xpath('normalize-space(//table[3]/tbody/tr[1]/td[1])')
elif self.skin == 'ODS':
return tree.xpath('normalize-space(//table//tr[13]/td[1])')
def get_percentage_listbox_field_value(tree):
if self.skin == 'ODT':
return tree.xpath('normalize-space(//table[3]/tbody/tr[1]/td[2])')
elif self.skin == 'ODS':
return tree.xpath('normalize-space(//table//tr[13]/td[2])')
response = self.publish(
'%s/Foo_viewFloatField?format=html&precision:int=2' % foo.getPath(), basic=self.auth)
tree = lxml.html.fromstring(response.getBody())
self.assertEqual(get_percentage_field_value(tree), '123.40%')
self.assertEqual(get_figure_field_value(tree), '4.56')
self.assertEqual(get_percentage_listbox_field_value(tree), '432.10%')
self.assertEqual(get_figure_listbox_field_value(tree), '6.54')
response = self.publish(
'%s/Foo_viewFloatField?format=html&precision:int=3' % foo.getPath(), basic=self.auth)
tree = lxml.html.fromstring(response.getBody())
self.assertEqual(get_percentage_field_value(tree), '123.400%')
self.assertEqual(get_figure_field_value(tree), '4.560')
self.assertEqual(get_percentage_listbox_field_value(tree), '432.100%')
self.assertEqual(get_figure_listbox_field_value(tree), '6.540')
def test_textarea_center_group(self):
self._assertFieldInGroup('TextAreaField', 'Person_view', 'center')
self.assertIn('my_description', [f.getId() for f in
......
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