[Erp5-report] r26582 - in /erp5/trunk/products/ERP5OOo: ./ tests/ tests/test_document/

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Apr 22 12:03:14 CEST 2009


Author: tatuya
Date: Wed Apr 22 12:03:13 2009
New Revision: 26582

URL: http://svn.erp5.org?rev=26582&view=rev
Log:
Append a class; named 'PrintoutStyleCell' to enable setting
a style-name of a table cell explicitly.


Modified:
    erp5/trunk/products/ERP5OOo/FormPrintout.py
    erp5/trunk/products/ERP5OOo/__init__.py
    erp5/trunk/products/ERP5OOo/tests/testFormPrintout.py
    erp5/trunk/products/ERP5OOo/tests/test_document/Foo_001.odt

Modified: erp5/trunk/products/ERP5OOo/FormPrintout.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5OOo/FormPrintout.py?rev=26582&r1=26581&r2=26582&view=diff
==============================================================================
--- erp5/trunk/products/ERP5OOo/FormPrintout.py [utf8] (original)
+++ erp5/trunk/products/ERP5OOo/FormPrintout.py [utf8] Wed Apr 22 12:03:13 2009
@@ -777,6 +777,11 @@
       column.remove(child)
     if first_child is not None:
       column.append(first_child)
+      # explicit table contents style setting
+      if isinstance(value, PrintoutStyleCell) and value.getStyleName() is not None:
+        style_attribute, original_style = self._getStyleAttributeTuple(first_child)
+        if style_attribute is not None:
+          first_child.set(style_attribute, value.getStyleName())
     if column_value != '':
       value_attribute = self._getColumnValueAttribute(column)
       if value_attribute is not None:
@@ -805,17 +810,17 @@
     column_children = column.getchildren()
     for child in column_children:
       # clear data except style
-      style_attribute_tuple = self._getStyleAttributeTuple(child)
+      style_attribute, style_value = self._getStyleAttributeTuple(child)
       child.clear()
-      if style_attribute_tuple is not None:
-        child.set(style_attribute_tuple[0], style_attribute_tuple[1])
+      if style_attribute is not None:
+        child.set(style_attribute, style_value)
 
   def _getStyleAttributeTuple(self, element):
     attrib = element.attrib
     for key in attrib.keys():
       if key.endswith('style-name'):
         return (key, attrib[key])
-    return None
+    return (None, '')
   
   def _getColumnValueAttribute(self, column):
     attrib = column.attrib
@@ -861,3 +866,28 @@
 class ODTStrategy(ODFStrategy):
   """ODTStrategy create a ODT Document from a form and a ODT template"""
   pass
+
+class PrintoutStyleCell:
+  """setting a style name of a table-content explicitly
+  
+  Note: experimentally implementation
+  """
+  value = None
+  style_name = None
+  
+  def __init__(self, value=None, style_name=None):
+    self.value = value
+    self.style_name = style_name
+
+  def __call__(self):
+    return self
+
+  def __str__(self):
+    if self.value is None:  return ''
+    elif isinstance(self.value, unicode) or isinstance(self.value, str):
+      return self.value
+    return str(self.value)
+
+  def getStyleName(self):
+    return self.style_name
+

Modified: erp5/trunk/products/ERP5OOo/__init__.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5OOo/__init__.py?rev=26582&r1=26581&r2=26582&view=diff
==============================================================================
--- erp5/trunk/products/ERP5OOo/__init__.py [utf8] (original)
+++ erp5/trunk/products/ERP5OOo/__init__.py [utf8] Wed Apr 22 12:03:13 2009
@@ -43,6 +43,8 @@
 ModuleSecurityInfo('Products.ERP5OOo.OOoUtils').declarePublic('OOoParser',)
 ModuleSecurityInfo('Products.ERP5OOo.OOoUtils').declarePublic('newOOoParser',)
 
+ModuleSecurityInfo('Products.ERP5OOo.FormPrintout').declarePublic('PrintoutStyleCell',)
+
 # Define object classes and tools
 from OOoTemplate import OOoTemplate
 from FormPrintout import FormPrintout

Modified: erp5/trunk/products/ERP5OOo/tests/testFormPrintout.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5OOo/tests/testFormPrintout.py?rev=26582&r1=26581&r2=26582&view=diff
==============================================================================
--- erp5/trunk/products/ERP5OOo/tests/testFormPrintout.py [utf8] (original)
+++ erp5/trunk/products/ERP5OOo/tests/testFormPrintout.py [utf8] Wed Apr 22 12:03:13 2009
@@ -578,6 +578,76 @@
     # no rows
     self.assertEqual(len(odf_table_rows), 0)
     self._validate(odf_document)
+
+  def test_02_Table_09_Explicit_Table_Content_Style(self, run=run_all_test):
+    if not run: return
+    # test target
+    test1 = self.portal.foo_module.test1
+    foo_printout = test1.Foo_viewAsPrintout
+    foo_form = test1.Foo_view
+    listbox = foo_form.listbox
+    request = self.app.REQUEST 
+    request['here'] = test1
+
+    foo_form.manage_renameObject('listbox', 'listbox2', REQUEST=request)
+    listbox2 = foo_form.listbox2
+    test1.foo_1.setTitle('foo_title_9')
+    createZODBPythonScript(
+          self.portal.portal_skins.custom,
+          'TestFoo_getFooWithStyleList',
+          '*args,**kw',
+r"""
+from Products.ERP5OOo.FormPrintout import PrintoutStyleCell
+from Products.PythonScripts.standard import Object
+foo_list = context.objectValues(portal_type='Foo Line')
+foo_with_style_list = []
+for foo in foo_list:
+  o = Object(uid='new_',
+             id=foo.getId(),
+             title=foo.getTitle(),
+             quantity=PrintoutStyleCell(foo.getQuantity(), 'table-content-big') # explicit style 
+             )
+  foo_with_style_list.append(o)
+return foo_with_style_list
+"""
+      )  
+    message = listbox2.ListBox_setPropertyList(
+      field_list_method = 'TestFoo_getFooWithStyleList',
+      field_stat_method = 'portal_catalog',
+      field_stat_columns = 'quantity | Foo_statQuantity',
+      field_columns = 'id|ID\ntitle|Title\nquantity|Quantity',)
+    self.failUnless('Set Successfully' in message)
+    listboxline_list = listbox2.get_value('default', render_format = 'list',
+                                         REQUEST = request)
+    self.assertEqual(len(listboxline_list), 4)
+    self.assertTrue(listboxline_list[1].getColumnProperty('title') == "foo_title_9")
+
+    odf_document = foo_printout.index_html(REQUEST=request)
+
+    self.assertTrue(odf_document is not None)
+    test_output = open("/tmp/test_02_09_Table.odf", "w")
+    test_output.write(odf_document)    
+    builder = OOoBuilder(odf_document)
+    content_xml = builder.extract("content.xml") 
+
+    self.assertTrue(content_xml.find("foo_title_9") > 0)
+
+    content = etree.XML(content_xml)
+    table_row_xpath = '//table:table[@table:name="listbox2"]/table:table-row'
+    odf_table_rows = content.xpath(table_row_xpath, namespaces=content.nsmap)
+    self.assertEqual(len(odf_table_rows), 3)
+    # to test explicit style name
+    first_row = odf_table_rows[0]
+    first_row_columns = first_row.getchildren()
+    quantity_column = first_row_columns[2]
+    quantity_paragraph = quantity_column.getchildren()[0]
+    style_name_attrib = "{%s}style-name" % content.nsmap['text']
+    self.assertTrue(quantity_paragraph.attrib.has_key(style_name_attrib))
+    self.assertEqual(quantity_paragraph.attrib[style_name_attrib], 'table-content-big')
+    self._validate(odf_document)
+
+    # put back the field name
+    foo_form.manage_renameObject('listbox2', 'listbox', REQUEST=request)
     
   def _test_03_Frame(self, run=run_all_test):
     """
@@ -589,6 +659,7 @@
     """
     Iteration using ERP5Report ReportSection test
     """
+    if not run: return 
     custom = self.portal.portal_skins.custom
     erp5form = custom.manage_addProduct['ERP5Form']
     erp5form.addERP5Report(id='FooReport_view', title='Foo Report')

Modified: erp5/trunk/products/ERP5OOo/tests/test_document/Foo_001.odt
URL: http://svn.erp5.org/erp5/trunk/products/ERP5OOo/tests/test_document/Foo_001.odt?rev=26582&r1=26581&r2=26582&view=diff
==============================================================================
Binary files - no diff available.




More information about the Erp5-report mailing list