Commit 0bc1d75e authored by Jérome Perrin's avatar Jérome Perrin

ods_style: respect date order on date time fields

introduce number:date-style for each of the "input_order" supported by
DateTimeField, so that when exported to ODS we have the same input order
as in html.
parent ed0700ec
...@@ -147,17 +147,17 @@ ...@@ -147,17 +147,17 @@
</tal:block> </tal:block>
<tal:block tal:condition="python: field is not None"> <tal:block tal:condition="python: field is not None">
<tal:block tal:condition="python:field.meta_type=='DateTimeField' or (field.meta_type == 'ProxyField' and field.getRecursiveTemplateField().meta_type == 'DateTimeField')"> <tal:block tal:condition="python:field.meta_type=='DateTimeField' or (field.meta_type == 'ProxyField' and field.getRecursiveTemplateField().meta_type == 'DateTimeField')">
<tal:block tal:condition="python:field.get_value('date_only')"> <tal:block tal:condition="python:field.get_value('date_only')" tal:define="input_order python:field.get_value('input_order')">
<table:table-cell tal:attributes="office:date-value python: context.ERP5Site_formatDateForODF(value); <table:table-cell tal:attributes="office:date-value python: context.ERP5Site_formatDateForODF(value);
table:style-name string:${style_prefix}date;" table:style-name string:${style_prefix}date_${input_order};"
table:style-name="date" table:style-name="date"
office:value-type="date"> office:value-type="date">
<text:p tal:content="python: field.render_pdf(value)"/> <text:p tal:content="python: field.render_pdf(value)"/>
</table:table-cell> </table:table-cell>
</tal:block> </tal:block>
<tal:block tal:condition="python:not field.get_value('date_only')"> <tal:block tal:condition="python:not field.get_value('date_only')" tal:define="input_order python:field.get_value('input_order')">
<table:table-cell tal:attributes="office:date-value python: context.ERP5Site_formatDateForODF(value); <table:table-cell tal:attributes="office:date-value python: context.ERP5Site_formatDateForODF(value);
table:style-name string:${style_prefix}date_with_time;" table:style-name string:${style_prefix}date_with_time_${input_order};"
table:style-name="date_with_time" table:style-name="date_with_time"
office:value-type="date"> office:value-type="date">
<text:p tal:content="python: field.render_pdf(value)"/> <text:p tal:content="python: field.render_pdf(value)"/>
......
...@@ -102,43 +102,86 @@ ...@@ -102,43 +102,86 @@
<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: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>
<number:date-style style:name="date_style" number:automatic-order="true"> <number:date-style style:name="date_style_ymd">
<number:year number:style="long"/>
<number:text>/</number:text>
<number:month number:style="long"/>
<number:text>/</number:text>
<number:day number:style="long"/>
</number:date-style>
<number:date-style style:name="date_style_dmy">
<number:day number:style="long"/> <number:day number:style="long"/>
<number:text>/</number:text> <number:text>/</number:text>
<number:month number:style="long"/> <number:month number:style="long"/>
<number:text>/</number:text> <number:text>/</number:text>
<number:year number:style="long"/> <number:year number:style="long"/>
</number:date-style> </number:date-style>
<style:style style:name="date" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="date_style"> <number:date-style style:name="date_style_mdy">
<style:table-cell-properties fo:border-bottom="none" fo:border-left="0.002cm solid #000000" fo:border-right="0.002cm solid #000000" fo:border-top="none"/> <number:month number:style="long"/>
</style:style> <number:text>/</number:text>
<style:style style:name="with_border_date" style:family="table-cell" style:parent-style-name="date" style:data-style-name="date_style">
<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_with_time_style" number:automatic-order="true">
<number:day number:style="long"/> <number:day number:style="long"/>
<number:text>/</number:text> <number:text>/</number:text>
<number:year number:style="long"/>
</number:date-style>
<number:date-style style:name="date_with_time_style_ymd">
<number:year number:style="long"/>
<number:text>/</number:text>
<number:month number:style="long"/>
<number:text>/</number:text>
<number:day number:style="long"/>
<number:text> </number:text>
<number:hours number:style="long"/>
<number:text>:</number:text>
<number:minutes number:style="long"/>
</number:date-style>
<number:date-style style:name="date_with_time_style_mdy">
<number:month number:style="long"/> <number:month number:style="long"/>
<number:text>/</number:text> <number:text>/</number:text>
<number:day number:style="long"/>
<number:text>/</number:text>
<number:year number:style="long"/> <number:year number:style="long"/>
<number:text> </number:text> <number:text> </number:text>
<number:hours number:style="long"/> <number:hours number:style="long"/>
<number:text>:</number:text> <number:text>:</number:text>
<number:minutes number:style="long"/> <number:minutes number:style="long"/>
</number:date-style>
<number:date-style style:name="date_with_time_style_dmy">
<number:day number:style="long"/>
<number:text>/</number:text>
<number:month number:style="long"/>
<number:text>/</number:text>
<number:year number:style="long"/>
<number:text> </number:text>
<number:hours number:style="long"/>
<number:text>:</number:text> <number:text>:</number:text>
<number:seconds number:style="long"/> <number:minutes number:style="long"/>
</number:date-style> </number:date-style>
<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:style style:name="stat-date_with_time" style:family="table-cell" style:parent-style-name="stat-date">
<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:table-cell-properties fo:border="0.002cm solid #000000"/>
</style:style> </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-name="date_style_with_time"> <style:style style:name="date_with_time" style:family="table-cell" style:parent-style-name="date">
<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:table-cell-properties style:vertical-align='middle' style:repeat-content='false' style:text-align-source='fix' fo:border-left='0.002cm solid #000000' fo:border-right='0.002cm solid #000000'/>
</style:style> </style:style>
<style:style style:name="with_border_figure" style:family="table-cell" style:parent-style-name="figure"> <tal:block tal:repeat="with_time_suffix python: ('', '_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'/> <tal:block tal:repeat="style_prefix_name python: here.Base_getODSSupportedStylePrefixList() + ('with_border_', )">
<tal:block tal:repeat="input_order python: ('ymd', 'dmy', 'mdy')">
<style:style
tal:attributes="style:name string:${style_prefix_name}date${with_time_suffix}_${input_order};
style:data-style-name string:date${with_time_suffix}_style_${input_order};
style:parent-style-name string:${style_prefix_name}date${with_time_suffix}"
style:name="date_with_time"
style:family="table-cell"
style:parent-style-name="date_with_time"
style:data-style-name="date_with_time_style_ymd">
<style:table-cell-properties tal:condition="python: style_prefix_name == ''" style:vertical-align='middle' style:repeat-content='false' style:text-align-source='fix' fo:border-left='0.002cm solid #000000' fo:border-right='0.002cm solid #000000' />
<style:table-cell-properties tal:condition="python: style_prefix_name == 'stat-'" fo:border='0.002cm solid #000000' />
<style:table-cell-properties tal:condition="python: style_prefix_name == 'with_border_'" 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>
</tal:block>
</tal:block>
</tal:block>
<tal:block tal:repeat="precision python: range(0,here.Base_getODSMaximumSupportedPrecision())"> <tal:block tal:repeat="precision python: range(0,here.Base_getODSMaximumSupportedPrecision())">
<tal:block tal:define="figure_data_precision_style_name string:figure_data_precision_${precision}"> <tal:block tal:define="figure_data_precision_style_name string:figure_data_precision_${precision}">
......
...@@ -33,6 +33,7 @@ from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase ...@@ -33,6 +33,7 @@ from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.utils import DummyLocalizer from Products.ERP5Type.tests.utils import DummyLocalizer
from Products.ERP5Form.Selection import Selection from Products.ERP5Form.Selection import Selection
from Testing import ZopeTestCase from Testing import ZopeTestCase
from DateTime import DateTime
from Products.ERP5OOo.tests.utils import Validator from Products.ERP5OOo.tests.utils import Validator
import httplib import httplib
import lxml.html import lxml.html
...@@ -497,6 +498,86 @@ class TestOOoStyle(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -497,6 +498,86 @@ class TestOOoStyle(ERP5TypeTestCase, ZopeTestCase.Functional):
self.assertEqual(get_percentage_listbox_field_value(tree), '432.100%') self.assertEqual(get_percentage_listbox_field_value(tree), '432.100%')
self.assertEqual(get_figure_listbox_field_value(tree), '6.540') self.assertEqual(get_figure_listbox_field_value(tree), '6.540')
def test_date_time_field(self):
foo = self.portal.foo_module.newContent(
portal_type='Foo',
start_date=DateTime("2001/02/03 04:05"),
)
foo.newContent(
portal_type='Foo Line',
start_date=DateTime("2005/04/03 02:01"),
)
response = self.publish(
'%s/Foo_viewDateTimeField' % 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_date_time_field_value(tree):
if self.skin == 'ODT':
return tree.xpath(
'normalize-space(//tr/td/*[normalize-space(.)="Start Date"]/../following-sibling::td)')
elif self.skin == 'ODS':
return tree.xpath(
'normalize-space(//tr/td/*/*[normalize-space(.)="Start Date"]/../../following-sibling::td)')
def get_date_time_listbox_field_value(tree):
if self.skin == 'ODT':
return tree.xpath('normalize-space((//table[2]//tr//td)[3])')
elif self.skin == 'ODS':
return tree.xpath('normalize-space(//table//tr[7]/td)')
def get_date_time_listbox_stat_value(tree):
if self.skin == 'ODT':
return tree.xpath('normalize-space((//table[2]//tr//td)[4])')
elif self.skin == 'ODS':
return tree.xpath('normalize-space(//table//tr[8]/td)')
response = self.publish(
'%s/Foo_viewDateTimeField?format=html&input_order=ymd&date_only:int=1' % foo.getPath(), basic=self.auth)
tree = lxml.html.fromstring(response.getBody())
self.assertEqual(get_date_time_field_value(tree), '2001/02/03')
self.assertEqual(get_date_time_listbox_field_value(tree), '2005/04/03')
self.assertEqual(get_date_time_listbox_stat_value(tree), '2009/08/07')
response = self.publish(
'%s/Foo_viewDateTimeField?format=html&input_order=dmy&date_only:int=1' % foo.getPath(), basic=self.auth)
tree = lxml.html.fromstring(response.getBody())
self.assertEqual(get_date_time_field_value(tree), '03/02/2001')
self.assertEqual(get_date_time_listbox_field_value(tree), '03/04/2005')
self.assertEqual(get_date_time_listbox_stat_value(tree), '07/08/2009')
response = self.publish(
'%s/Foo_viewDateTimeField?format=html&input_order=mdy&date_only:int=1' % foo.getPath(), basic=self.auth)
tree = lxml.html.fromstring(response.getBody())
self.assertEqual(get_date_time_field_value(tree), '02/03/2001')
self.assertEqual(get_date_time_listbox_field_value(tree), '04/03/2005')
self.assertEqual(get_date_time_listbox_stat_value(tree), '08/07/2009')
response = self.publish(
'%s/Foo_viewDateTimeField?format=html&input_order=ymd' % foo.getPath(), basic=self.auth)
tree = lxml.html.fromstring(response.getBody())
self.assertEqual(get_date_time_field_value(tree), '2001/02/03 04:05')
self.assertEqual(get_date_time_listbox_field_value(tree), '2005/04/03 02:01')
self.assertEqual(get_date_time_listbox_stat_value(tree), '2009/08/07 06:05')
response = self.publish(
'%s/Foo_viewDateTimeField?format=html&input_order=dmy' % foo.getPath(), basic=self.auth)
tree = lxml.html.fromstring(response.getBody())
self.assertEqual(get_date_time_field_value(tree), '03/02/2001 04:05')
self.assertEqual(get_date_time_listbox_field_value(tree), '03/04/2005 02:01')
self.assertEqual(get_date_time_listbox_stat_value(tree), '07/08/2009 06:05')
response = self.publish(
'%s/Foo_viewDateTimeField?format=html&input_order=mdy' % foo.getPath(), basic=self.auth)
tree = lxml.html.fromstring(response.getBody())
self.assertEqual(get_date_time_field_value(tree), '02/03/2001 04:05')
self.assertEqual(get_date_time_listbox_field_value(tree), '04/03/2005 02:01')
self.assertEqual(get_date_time_listbox_stat_value(tree), '08/07/2009 06:05')
def test_textarea_center_group(self): def test_textarea_center_group(self):
self._assertFieldInGroup('TextAreaField', 'Person_view', 'center') self._assertFieldInGroup('TextAreaField', 'Person_view', 'center')
self.assertIn('my_description', [f.getId() for f in 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