Commit a78abf72 authored by Nicolas Delaby's avatar Nicolas Delaby

Add render_odf Method on widget for OLE inclusion

Add scatter type graph

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20302 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 2e7bc6d9
......@@ -119,6 +119,7 @@ class OOoChartWidget(Widget.Widget):
items=[('bar', 'chart:bar'),
('circle', 'chart:circle'),
('line', 'chart:line'),
('scatter', 'chart:scatter'),
],
size=0)
property_names.append('chart_type')
......@@ -192,24 +193,24 @@ class OOoChartWidget(Widget.Widget):
property_names.append('grid_size')
user_data_title = fields.StringField('user_data_title',
title="User Column ID For X-axis",
title="Overide Labelled Column ID",
description=(
"Column ID choose by user to define the X-axes."),
"Column Id choose by user to define the label."),
required=0)
property_names.append('user_data_title')
user_column_id_list = fields.ListTextAreaField('user_column_id_list',
title="User Column ID List",
title="Overide Column Ids",
description=(
"A list of columns ID choose by user to draw the graph."),
"A list of column Ids choose by user to draw the graph."),
default=[],
required=0)
property_names.append('user_column_id_list')
chart_stacked = fields.CheckBoxField('chart_stacked',
title='Stacked Bars',
description=('stacked bars or not'),
title='Stacked Data',
description=('stacked data or not'),
default=0,
required=0)
property_names.append('chart_stacked')
......@@ -305,7 +306,7 @@ class OOoChartWidget(Widget.Widget):
#data-label-number="none" value percentage
data_label_number = fields.ListField('data_label_number',
title='Data-Label-Number',
title='Data Label Number',
description=(''),
default='none',
items=[('none', 'none'),
......@@ -330,6 +331,47 @@ class OOoChartWidget(Widget.Widget):
required=0)
property_names.append('data_label_symbol')
def getArgumentDict(self, field, REQUEST):
""" Build argument Dict """
def stringBoolean(value):
return str(bool(value)).lower()
extra_argument_dict = dict(
chart_form_id = field.get_value('form_id'),
chart_field_id = field.get_value('field_id'),
chart_title = field.get_value('title'),
chart_type = field.get_value('chart_type'),
colour_column_dict = dict(field.get_value('colour_column_list')),
user_column_id_dict = dict(field.get_value('user_column_id_list')),
user_data_title= field.get_value('user_data_title'),
chart_position = field.get_value('chart_position'),
chart_legend = stringBoolean(field.get_value('chart_legend')),
chart_title_or_no = stringBoolean(field.get_value('chart_title_or_no')),
grid_graph = stringBoolean(field.get_value('grid_graph')),
grid_size=field.get_value('grid_size'),
chart_three_dimensional = stringBoolean(field.get_value('chart_three_dimensional')),
deep = stringBoolean(field.get_value('deep')),
chart_stacked = stringBoolean(field.get_value('chart_stacked')),
sector_pie_offset = field.get_value('sector_pie_offset'),
interpolation = field.get_value('interpolation'),
symbol_type = field.get_value('symbol_type'),
lines_used = field.get_value('lines_used'),
connect_bars = stringBoolean(field.get_value('connect_bars')),
series_source = field.get_value('series_source'),
regression_type = field.get_value('regression_type'),
data_label_number = field.get_value('data_label_number'),
data_label_text = stringBoolean(field.get_value('data_label_text')),
data_label_symbol = stringBoolean(field.get_value('data_label_symbol')),
position_legend=field.get_value('position_legend'),
)
for k, v in extra_argument_dict.items():
if REQUEST.get(k) is None:
REQUEST.form[k] = v
return extra_argument_dict
def render_view(self, field, value, key=None, REQUEST=None, render_format='html'):
"""
Render a Chart in read-only.
......@@ -337,6 +379,20 @@ class OOoChartWidget(Widget.Widget):
if REQUEST is None: REQUEST=get_request()
return self.render(field, key, value, REQUEST, render_format=render_format)
def render_odf(self, field, key, value, REQUEST, render_format='ooo'):
"""
Render a Chart for ODT Style.
"""
form = field.aq_parent
here = getattr(form, 'aq_parent', REQUEST)
extra_context = self.getArgumentDict(field, here.REQUEST)
content = '''
<office:include style="inline-graphic" path="%s/ERP5Site_buildChart" xlink:type="simple" xlink:actuate="onLoad" xlink:show="embed"/>
''' % here.getPath()
return content
def render(self, field, key, value, REQUEST, render_format='html'):
"""
......@@ -360,18 +416,14 @@ class OOoChartWidget(Widget.Widget):
here = getattr(form, 'aq_parent', REQUEST)
# Update the render format based on REQUEST parameters
render_format = getattr(REQUEST, 'render_format', render_format)
UrlIconOOo='%s/misc_/ERP5OOo/OOo.png' % here.ERP5Site_getAbsoluteUrl()
UrlIconPdf='%s/misc_/ERP5Form/PDF.png' % here.ERP5Site_getAbsoluteUrl()
if render_format == 'html':
field_absolute_url = '%s/%s/%s' % (here.absolute_url(),
form.getId(),
field.getId())
css_class = field.get_value('css_class')
format = field.get_value('image_format')
if format == '':
format='png'
format = field.get_value('image_format') or 'png'
display = field.get_value('image_display')
if format in STANDARD_IMAGE_FORMAT_LIST:
main_content = '''<div class="OOoChartContent">
......@@ -383,62 +435,30 @@ class OOoChartWidget(Widget.Widget):
title,
alternate_name)
return main_content
if format == 'raw':
elif format == 'raw':
main_content = '''<div class="OOoChartContent">
<a href="%s?render_format=&display=%s"><img src="%s" alt="OOo"/></a></div>
''' % (field_absolute_url,
display,
UrlIconOOo)
return main_content
if format == 'pdf':
elif format == 'pdf':
main_content = '''<div class="OOoChartContent">
<a href="%s?render_format=pdf&display=%s"><img src="%s" alt="PDF" /></a>
</div>''' % (field_absolute_url,
display,
UrlIconPdf)
return main_content
else:
raise NotImplementedError, 'Format: %s not handled' % format
def stringBoolean(value):
return str(bool(value)).lower()
#Build the parameters
extra_argument_dict = dict(
chart_form_id = field.get_value('form_id'),
chart_field_id = field.get_value('field_id'),
chart_title = field.get_value('title'),
chart_type = field.get_value('chart_type'),
colour_column_dict = dict(field.get_value('colour_column_list')),
user_column_id_dict = dict(field.get_value('user_column_id_list')),
user_data_title= field.get_value('user_data_title'),
chart_position = field.get_value('chart_position'),
chart_legend = stringBoolean(field.get_value('chart_legend')),
chart_title_or_no = stringBoolean(field.get_value('chart_title_or_no')),
grid_graph = stringBoolean(field.get_value('grid_graph')),
grid_size=field.get_value('grid_size'),
chart_three_dimensional = stringBoolean(field.get_value('chart_three_dimensional')),
deep = stringBoolean(field.get_value('deep')),
chart_stacked = stringBoolean(field.get_value('chart_stacked')),
sector_pie_offset = field.get_value('sector_pie_offset'),
interpolation = field.get_value('interpolation'),
symbol_type = field.get_value('symbol_type'),
lines_used = field.get_value('lines_used'),
connect_bars = stringBoolean(field.get_value('connect_bars')),
series_source = field.get_value('series_source'),
regression_type = field.get_value('regression_type'),
data_label_number = field.get_value('data_label_number'),
data_label_text = stringBoolean(field.get_value('data_label_text')),
data_label_symbol = stringBoolean(field.get_value('data_label_symbol')),
position_legend=field.get_value('position_legend'),
)
for k, v in extra_argument_dict.items():
if REQUEST.get(k) is None:
REQUEST.form[k] = v
extra_context = self.getArgumentDict(field, REQUEST)
method_id = field.get_value('ooo_template')
# Find the page template
ooo_template = getattr(here, method_id)
# Render the chart
return ooo_template(format=render_format)
......@@ -456,7 +476,5 @@ OOoChartValidatorInstance = OOoChartValidator()
class OOoChart(ZMIField):
meta_type = "OOoChart"
widget = OOoChartWidgetInstance
validator = OOoChartValidatorInstance
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