[Erp5-report] r31249 fabien - /erp5/trunk/products/Formulator/Widget.py

nobody at svn.erp5.org nobody at svn.erp5.org
Fri Dec 11 16:54:15 CET 2009


Author: fabien
Date: Fri Dec 11 16:54:15 2009
New Revision: 31249

URL: http://svn.erp5.org?rev=31249&view=rev
Log:
- move render_odg from TextWidget to Widget
- replace \n, \r and \t caracters by ooo corresponding expression 

Modified:
    erp5/trunk/products/Formulator/Widget.py

Modified: erp5/trunk/products/Formulator/Widget.py
URL: http://svn.erp5.org/erp5/trunk/products/Formulator/Widget.py?rev=31249&r1=31248&r2=31249&view=diff
==============================================================================
--- erp5/trunk/products/Formulator/Widget.py [utf8] (original)
+++ erp5/trunk/products/Formulator/Widget.py [utf8] Fri Dec 11 16:54:15 2009
@@ -199,7 +199,47 @@
       object.
       attr_dict can be used for additional parameters (like style).
     """
-    return None
+    if attr_dict is None:
+      attr_dict = {}
+
+    # get the field value
+    value = field.get_value('default')
+    if isinstance(value, (str, unicode)):
+      if isinstance(value, str):
+        value = value.decode('utf-8')
+      value = [value]
+    value = '\n'.join(value)
+    value.replace('\r', '')
+
+    draw_tag_name = '{%s}%s' % (DRAW_URI, 'text-box')
+    draw_node = Element(draw_tag_name, nsmap=NSMAP)
+    draw_node.attrib.update(attr_dict.get(draw_tag_name, {}))
+    text_p_tag_name = '{%s}%s' % (TEXT_URI, local_name)
+    text_p_node = Element(text_p_tag_name, nsmap=NSMAP)
+    text_p_node.attrib.update(attr_dict.get(text_p_tag_name, {}))
+    text_span_tag_name = '{%s}%s' % (TEXT_URI, 'span')
+    text_span_node =  Element(text_span_tag_name, nsmap=NSMAP)
+    text_span_node.attrib.update(attr_dict.get(text_span_tag_name, {}))
+    text_p_node.append(text_span_node)
+    draw_node.append(text_p_node)
+
+    # XXX copy from render_odt, need to be unified
+    def replaceCharsByNode(match_object):
+        #global text_span_node
+        if match_object.group(1) is None:
+            text_span_node.text = match_object.group(2)
+        if match_object.group(1) == '\n':
+            line_break = SubElement(text_span_node, '{%s}%s' % (TEXT_URI, 'line-break'))
+            line_break.tail = match_object.group(2)
+        if match_object.group(1) == '\t':
+            line_break = SubElement(text_span_node, '{%s}%s' % (TEXT_URI, 'tab'))
+            line_break.tail = match_object.group(2)
+    re.sub('([\n\t])?([^\n\t]*)', replaceCharsByNode, value)
+    #text_span_node.text = value
+    if as_string:
+      return etree.tostring(draw_node)
+    return draw_node
+
 
 class TextWidget(Widget):
   """Text widget
@@ -277,33 +317,6 @@
       # except for editor field
       return "<span class='%s'>%s</span>" % (css_class, value)
     return value
-
-  def render_odg(self, field, as_string, local_name, attr_dict=None):
-    """
-      Return a field value rendered in odg format.
-      if as_string is True (default) the returned value is a string (xml
-      reprensation of the node), if it's False, the value returned is the node
-      object.
-      attr_dict can be used for additional parameters (like style).
-    """
-    if attr_dict is None:
-      attr_dict = {}
-    draw_tag_name = '{%s}%s' % (DRAW_URI, 'text-box')
-    draw_node = Element(draw_tag_name, nsmap=NSMAP)
-    draw_node.attrib.update(attr_dict.get(draw_tag_name, {}))
-    text_p_tag_name = '{%s}%s' % (TEXT_URI, local_name)
-    text_p_node = Element(text_p_tag_name, nsmap=NSMAP)
-    text_p_node.attrib.update(attr_dict.get(text_p_tag_name, {}))
-    text_span_tag_name = '{%s}%s' % (TEXT_URI, 'span')
-    text_span_node =  Element(text_span_tag_name, nsmap=NSMAP)
-    text_span_node.attrib.update(attr_dict.get(text_span_tag_name, {}))
-    text_p_node.append(text_span_node)
-    draw_node.append(text_p_node)
-    # get the field value
-    text_span_node.text = field.get_value('default').decode('utf-8')
-    if as_string:
-      return etree.tostring(draw_node)
-    return draw_node
 
 TextWidgetInstance = TextWidget()
 




More information about the Erp5-report mailing list