Commit 7eb0973d authored by Nicolas Delaby's avatar Nicolas Delaby

Implement render_odt_view. eg. The read-only renderer for ooo

  * all widget.render_odt are renamed to widget.render_odt_view
  * field.render_odt call widget.render_odt or widget.render_odt_view
    according request parameter (editable_mode) or field configuration.
  * Backward compatibility is kept: widget.render_odt fallback to widget.render_odt_view
  * CheckBoxField now implement both editable modes
Reviewed by Romain


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@32789 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 51a43113
...@@ -204,6 +204,20 @@ class Field: ...@@ -204,6 +204,20 @@ class Field:
return self.widget.render(self, key, value, REQUEST, return self.widget.render(self, key, value, REQUEST,
render_prefix=render_prefix) render_prefix=render_prefix)
security.declarePrivate('_render_helper')
def _render_odt_helper(self, key, value, as_string, ooo_builder,
REQUEST, render_prefix, attr_dict, local_name):
value = self._get_default(key, value, REQUEST)
__traceback_info__ = ('key=%s value=%r' % (key, value))
if not self.get_value('editable', REQUEST=REQUEST):
return self.widget.render_odt_view(self, value, as_string, ooo_builder,
REQUEST, render_prefix, attr_dict,
local_name)
else:
return self.widget.render_odt(self, value, as_string, ooo_builder,
REQUEST, render_prefix, attr_dict,
local_name)
security.declarePrivate('_get_default') security.declarePrivate('_get_default')
def _get_default(self, key, value, REQUEST): def _get_default(self, key, value, REQUEST):
if value is not None: if value is not None:
...@@ -286,11 +300,19 @@ class Field: ...@@ -286,11 +300,19 @@ class Field:
def render_odt(self, key=None, value=None, as_string=True, ooo_builder=None, def render_odt(self, key=None, value=None, as_string=True, ooo_builder=None,
REQUEST=None, render_prefix=None, attr_dict=None, local_name='p', REQUEST=None, render_prefix=None, attr_dict=None, local_name='p',
key_prefix=None): key_prefix=None):
widget_key = self.generate_field_key(key=key, key_prefix=key_prefix) field_key = self.generate_field_key(key=key, key_prefix=key_prefix)
value = self._get_default(widget_key, value, REQUEST) return self._render_odt_helper(field_key, value, as_string,
return self.widget.render_odt(self, value, as_string, ooo_builder, ooo_builder, REQUEST, render_prefix,
REQUEST, render_prefix, attr_dict, attr_dict, local_name)
local_name)
security.declareProtected('View', 'render_odt_view')
def render_odt_view(self, value=None, as_string=True, ooo_builder=None,
REQUEST=None, render_prefix=None, attr_dict=None, local_name='p'):
"""Call read-only renderer
"""
return self.widget.render_odt_view(self, value, as_string, ooo_builder,
REQUEST, render_prefix, attr_dict,
local_name)
security.declareProtected('View', 'render_odg') security.declareProtected('View', 'render_odg')
def render_odg(self, key=None, value=None, as_string=True, ooo_builder=None, def render_odg(self, key=None, value=None, as_string=True, ooo_builder=None,
......
...@@ -175,9 +175,18 @@ class Widget: ...@@ -175,9 +175,18 @@ class Widget:
return None return None
def render_odt(self, field, value, as_string, ooo_builder, REQUEST, def render_odt(self, field, value, as_string, ooo_builder, REQUEST,
render_prefix, attr_dict, local_name): render_prefix, attr_dict, local_name):
"""This render dedicated to render fields inside OOo document
(eg. editable mode)
""" """
Return a field value rendered in odt format. # XXX By default fallback to render_odt_view
return self.render_odt_view(field, value, as_string, ooo_builder, REQUEST,
render_prefix, attr_dict, local_name)
def render_odt_view(self, field, value, as_string, ooo_builder, REQUEST,
render_prefix, attr_dict, local_name):
"""
Return a field value rendered in odt format as read-only mode.
- as_string return value as string or as xml object - as_string return value as string or as xml object
- attr_dict can be used for additional attributes (like style). - attr_dict can be used for additional attributes (like style).
- ooo_builder wrapper of ODF zipped archive usefull to insert images - ooo_builder wrapper of ODF zipped archive usefull to insert images
...@@ -234,7 +243,7 @@ class Widget: ...@@ -234,7 +243,7 @@ class Widget:
draw_node.append(text_p_node) draw_node.append(text_p_node)
draw_frame_node.append(draw_node) draw_frame_node.append(draw_node)
# XXX copy from render_odt, need to be unified # XXX copy from render_odt_view, need to be unified
def replaceCharsByNode(match_object): def replaceCharsByNode(match_object):
#global text_span_node #global text_span_node
if match_object.group(1) is None: if match_object.group(1) is None:
...@@ -416,7 +425,7 @@ class CheckBoxWidget(Widget): ...@@ -416,7 +425,7 @@ class CheckBoxWidget(Widget):
""" """
<form:checkbox form:name="is_accepted" <form:checkbox form:name="is_accepted"
form:control-implementation="ooo:com.sun.star.form.component.CheckBox" form:control-implementation="ooo:com.sun.star.form.component.CheckBox"
checkbox form:current-state="checked" form:current-state="checked"
form:id="control1" form:id="control1"
form:image-position="center"> form:image-position="center">
<form:properties> <form:properties>
...@@ -448,6 +457,24 @@ class CheckBoxWidget(Widget): ...@@ -448,6 +457,24 @@ class CheckBoxWidget(Widget):
return etree.tostring(form_node) return etree.tostring(form_node)
return form_node return form_node
def render_odt_view(self, field, value, as_string, ooo_builder, REQUEST,
render_prefix, attr_dict, local_name):
"""
"""
if attr_dict is None:
attr_dict = {}
if isinstance(value, int):
value = str(value)
if isinstance(value, str):
#required by lxml
value = value.decode('utf-8')
text_node = Element('{%s}%s' % (TEXT_URI, local_name), nsmap=NSMAP)
text_node.text = value
text_node.attrib.update(attr_dict)
if as_string:
return etree.tostring(text_node)
return text_node
CheckBoxWidgetInstance = CheckBoxWidget() CheckBoxWidgetInstance = CheckBoxWidget()
class TextAreaWidget(Widget): class TextAreaWidget(Widget):
...@@ -495,7 +522,7 @@ class TextAreaWidget(Widget): ...@@ -495,7 +522,7 @@ class TextAreaWidget(Widget):
return '' return ''
return value return value
def render_odt(self, field, value, as_string, ooo_builder, REQUEST, def render_odt_view(self, field, value, as_string, ooo_builder, REQUEST,
render_prefix, attr_dict, local_name): render_prefix, attr_dict, local_name):
if attr_dict is None: if attr_dict is None:
attr_dict = {} attr_dict = {}
...@@ -562,14 +589,14 @@ class LinesTextAreaWidget(TextAreaWidget): ...@@ -562,14 +589,14 @@ class LinesTextAreaWidget(TextAreaWidget):
value = [value] value = [value]
return string.join(value, field.get_value('view_separator')) return string.join(value, field.get_value('view_separator'))
def render_odt(self, field, value, as_string, ooo_builder, REQUEST, def render_odt_view(self, field, value, as_string, ooo_builder, REQUEST,
render_prefix, attr_dict, local_name): render_prefix, attr_dict, local_name):
if value is None: if value is None:
value = [''] value = ['']
elif isinstance(value, (str, unicode)): elif isinstance(value, (str, unicode)):
value = [value] value = [value]
value = '\n'.join(value) value = '\n'.join(value)
return TextAreaWidget.render_odt(self, field, value, as_string, return TextAreaWidget.render_odt_view(self, field, value, as_string,
ooo_builder, REQUEST, render_prefix, ooo_builder, REQUEST, render_prefix,
attr_dict, local_name) attr_dict, local_name)
...@@ -1329,7 +1356,7 @@ class DateTimeWidget(Widget): ...@@ -1329,7 +1356,7 @@ class DateTimeWidget(Widget):
def render_pdf(self, field, value, render_prefix=None): def render_pdf(self, field, value, render_prefix=None):
return self.format_value(field, value, mode='pdf') return self.format_value(field, value, mode='pdf')
def render_odt(self, field, value, as_string, ooo_builder, REQUEST, def render_odt_view(self, field, value, as_string, ooo_builder, REQUEST,
render_prefix, attr_dict, local_name): render_prefix, attr_dict, local_name):
""" """
Return a field value rendered in odt format. Return a field value rendered in odt format.
...@@ -1661,7 +1688,7 @@ class FloatWidget(TextWidget): ...@@ -1661,7 +1688,7 @@ class FloatWidget(TextWidget):
'format': format, 'format': format,
'type': 'float'} 'type': 'float'}
def render_odt(self, field, value, as_string, ooo_builder, REQUEST, def render_odt_view(self, field, value, as_string, ooo_builder, REQUEST,
render_prefix, attr_dict, local_name): render_prefix, attr_dict, local_name):
if attr_dict is None: if attr_dict is None:
attr_dict = {} attr_dict = {}
......
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