Commit b9448fa1 authored by Jérome Perrin's avatar Jérome Perrin

ods_style: render all fields with style_macros/macro/cell_value

Instead of duplicating the code for the case where a field value is
rendered from a group (left, right etc) of the form and when the field
value is rendered from a listbox editable field, reuse the macro also
for fields from the form groups.

Because fields from the form groups have top and bottom border, we
introduce a new style prefix for these fields: "with_border_".

Implementation note: We don't declare this new field in
Base_getODSSupportedStylePrefixList, because we need to define the cell
properties each time, so defining this dynamically is not really
interesting.
parent a00c4dae
...@@ -57,41 +57,10 @@ ...@@ -57,41 +57,10 @@
</tal:block> </tal:block>
<!-- field value --> <!-- field value -->
<tal:block tal:define="item_list python:field.has_value('items') and field.get_value('items') or None" <tal:block tal:define="value python: field.get_value('default'); style_prefix string:with_border_">
tal:condition="python: field.get_value('title')"> <tal:block metal:use-macro="here/field_ods_macro/macros/cell_value" />
<!-- if the group bottom there isn't a title -->
<table:table-cell table:number-rows-spanned='1'
table:style-name='report-content-heading2-with-lines'
tal:attributes="table:number-columns-spanned python:group == 'bottom' and column_len or max(column_len-1, 1)"
office:value-type='string'
tal:define="value python: field.get_value('default')">
<tal:block tal:condition="python: same_type(value, []) or same_type(value, ())">
<tal:block tal:repeat="item value">
<text:p tal:condition="not:item_list" tal:content="item"></text:p>
<text:p tal:condition="item_list" tal:on-error="item" tal:content="python: [i[0] for i in item_list if i[1] == item][0]"></text:p>
</tal:block>
</tal:block>
<tal:block tal:condition="python: (not (same_type(value, []) or same_type(value, ()))) and value is not None">
<tal:block tal:condition="python:field_meta_type == 'DateTimeField'">
<text:p tal:content="python: field.render_pdf(value)"/>
</tal:block>
<tal:block tal:condition="python: field_meta_type != 'DateTimeField'">
<text:p tal:condition="not: item_list" tal:content="value"></text:p>
<tal:block tal:condition="python: value != ''">
<tal:block tal:condition="item_list">
<tal:block tal:define="displayed_value_list python: [str(i[0]).replace('&amp;', '') for i in item_list if i[1] == value]">
<text:p tal:condition="displayed_value_list" tal:content="python: displayed_value_list[0]" />
<text:p tal:condition="not: displayed_value_list" tal:content="python: value" />
</tal:block>
</tal:block>
</tal:block>
<tal:block tal:condition="python: value is None">
<text:p table:style="Default" tal:content="python: ' '" />
</tal:block>
</tal:block>
</tal:block>
</table:table-cell>
</tal:block> </tal:block>
</table:table-row> </table:table-row>
</tal:block> </tal:block>
...@@ -105,7 +74,7 @@ ...@@ -105,7 +74,7 @@
<tal:block tal:define="is_list python:same_type(value, []) or same_type(value, ()); <tal:block tal:define="is_list python:same_type(value, []) or same_type(value, ());
is_float python: isinstance(value, modules['six'].integer_types + (float, ));"> is_float python: isinstance(value, modules['six'].integer_types + (float, ));">
<tal:block tal:condition="python: is_list"> <tal:block tal:condition="python: is_list">
<table:table-cell tal:attributes="table:style-name python:is_float and 'figure' or 'text'"> <table:table-cell tal:attributes="table:style-name string:${style_prefix}text">
<tal:block tal:condition="python: field is None" tal:repeat="item value"> <tal:block tal:condition="python: field is None" tal:repeat="item value">
<text:p tal:content="item"/> <text:p tal:content="item"/>
</tal:block> </tal:block>
......
...@@ -94,12 +94,31 @@ ...@@ -94,12 +94,31 @@
<style:table-cell-properties style:vertical-align='middle' style:repeat-content='false' style:text-align-source='fix' fo:border='none'/> <style:table-cell-properties style:vertical-align='middle' style:repeat-content='false' style:text-align-source='fix' fo:border='none'/>
<style:paragraph-properties fo:text-align='center' fo:margin-left='0cm'/> <style:paragraph-properties fo:text-align='center' fo:margin-left='0cm'/>
</style:style> </style:style>
<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>
<number:date-style style:name="date_style" number:automatic-order="true"> <number:date-style style:name="date_style" number:automatic-order="true">
<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>
<style:style style:name="date" style:family="table-cell" style:parent-style-name="Default" style:data-style-name="date_style">
<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"/>
</style:style>
<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:text>/</number:text>
<number:month number:style="long"/>
<number:text>/</number:text>
<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>
...@@ -107,9 +126,17 @@ ...@@ -107,9 +126,17 @@
<number:text>:</number:text> <number:text>:</number:text>
<number:seconds number:style="long"/> <number:seconds 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_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: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 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: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: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>
<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}">
<number:number-style style:name="figure_data_precision_X" tal:attributes="style:name figure_data_precision_style_name"> <number:number-style style:name="figure_data_precision_X" tal:attributes="style:name figure_data_precision_style_name">
...@@ -118,6 +145,18 @@ ...@@ -118,6 +145,18 @@
<tal:block tal:repeat="style_prefix_name python: here.Base_getODSSupportedStylePrefixList()"> <tal:block tal:repeat="style_prefix_name python: here.Base_getODSSupportedStylePrefixList()">
<style:style style:name="figure_X" style:family="table-cell" style:parent-style-name="figure" style:data-style-name="figure_data_precision_X" tal:attributes="style:name string:${style_prefix_name}figure_${precision}; style:data-style-name figure_data_precision_style_name ; style:parent-style-name string:${style_prefix_name}figure"/> <style:style style:name="figure_X" style:family="table-cell" style:parent-style-name="figure" style:data-style-name="figure_data_precision_X" tal:attributes="style:name string:${style_prefix_name}figure_${precision}; style:data-style-name figure_data_precision_style_name ; style:parent-style-name string:${style_prefix_name}figure"/>
</tal:block> </tal:block>
<style:style
style:name="with_border_figure_X"
style:family="table-cell"
style:parent-style-name="figure_X"
style:data-style-name="figure_data_precision_style_name"
tal:attributes="style:name string:with_border_figure_${precision};
style:data-style-name figure_data_precision_style_name;
style:parent-style-name string:figure_${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> </tal:block>
</tal:block> </tal:block>
</office:automatic-styles> </office:automatic-styles>
......
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