[Erp5-report] r31042 nicolas - /erp5/trunk/products/ERP5OOo/FormPrintout.py

nobody at svn.erp5.org nobody at svn.erp5.org
Thu Dec 3 16:39:17 CET 2009


Author: nicolas
Date: Thu Dec  3 16:39:17 2009
New Revision: 31042

URL: http://svn.erp5.org?rev=31042&view=rev
Log:
Support replacement of fields inside ODT documents

Modified:
    erp5/trunk/products/ERP5OOo/FormPrintout.py

Modified: erp5/trunk/products/ERP5OOo/FormPrintout.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5OOo/FormPrintout.py?rev=31042&r1=31041&r2=31042&view=diff
==============================================================================
--- erp5/trunk/products/ERP5OOo/FormPrintout.py [utf8] (original)
+++ erp5/trunk/products/ERP5OOo/FormPrintout.py [utf8] Thu Dec  3 16:39:17 2009
@@ -953,6 +953,7 @@
     """replace nodes (e.g. paragraphs) via ODF reference"""
     element_tree = self._replaceNodeViaRangeReference(element_tree=element_tree, field=field)
     element_tree = self._replaceNodeViaPointReference(element_tree=element_tree, field=field)
+    self._replaceNodeViaFormName(element_tree, field)
     return element_tree
 
   def _renderField(self, field):
@@ -1026,6 +1027,19 @@
                                element_tree=element_tree)
     return element_tree
 
+  def _replaceNodeViaFormName(self, element_tree, field, iteration_index=0):
+    """
+    Used to replace field in ODT document like checkboxes
+    """
+    field_id = field.id
+    reference_xpath = '//*[@form:name = "%s"]' % field_id
+    reference_list = element_tree.xpath(reference_xpath, namespaces=element_tree.nsmap)
+    for target_node in reference_list:
+      attr_dict = {}
+      attr_dict.update(target_node.attrib)
+      new_node = field.render_odt(attr_dict=attr_dict)
+      target_node.getparent().replace(target_node, new_node)
+
 class ODGStrategy(ODFStrategy):
   """ODGStrategy create a ODG Document from a form and a ODG template"""
 




More information about the Erp5-report mailing list