Commit dfeda10a authored by Nicolas Delaby's avatar Nicolas Delaby

add preliminary work to implement render_odt for fields

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@30992 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 135b9b83
......@@ -279,6 +279,10 @@ class Field:
return self.widget.render_odf(self, key, value, REQUEST, render_format,
render_prefix)
security.declareProtected('View', 'render_odt')
def render_odt(self, as_string=False, attr_dict=None):
return self.widget.render_odt(self, as_string, attr_dict=attr_dict)
security.declareProtected('View', 'render_css')
def render_css(self, REQUEST=None):
"""
......
......@@ -167,6 +167,22 @@ class Widget:
"""
return None
def render_odt(self, field, as_string, attr_dict=None):
"""
Return a field value rendered in odt format.
- as_string return value as string or as xml object
- attr_dict can be used for additional attributes (like style).
"""
if attr_dict is None:
attr_dict = {}
text_node = Element('{%s}%s' % (TEXT_URI, 'p'), nsmap=NSMAP)
# get the field value
text_node.text = field.get_value('default').decode('utf-8')
text_node.attrib.update(attr_dict)
if as_string:
return etree.tostring(text_node)
return text_node
def render_odg(self, field, value, as_string=True, attr_dict=None,
REQUEST=None, render_prefix=None):
"""
......@@ -1183,6 +1199,22 @@ class DateTimeWidget(Widget):
def render_pdf(self, field, value, render_prefix=None):
return self.format_value(field, value, mode='pdf')
def render_odt(self, field, as_string, attr_dict=None):
"""
Return a field value rendered in odt format.
- as_string return value as string or as xml object
- attr_dict can be used for additional attributes (like style).
"""
if attr_dict is None:
attr_dict = {}
text_node = Element('{%s}%s' % (TEXT_URI, 'p'), nsmap=NSMAP)
# get the field value
text_node.text = self.format_value(field, field.get_value('default'), mode='pdf').decode('utf-8')
text_node.attrib.update(attr_dict)
if as_string:
return etree.tostring(text_node)
return text_node
DateTimeWidgetInstance = DateTimeWidget()
class LabelWidget(Widget):
......
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