示例#1
0
    def test_textarea_center_group(self):
        self._assertFieldInGroup('TextAreaField', 'Person_view', 'center')
        self.assert_('my_description' in [
            f.getId()
            for f in self.portal.Person_view.get_fields_in_group('center')
        ])
        self.portal.person_module.pers.setDescription('<Escape>&\nnewline')
        response = self.publish(
            '/%s/person_module/pers/Person_view' % self.portal.getId(),
            self.auth)
        self.assertEqual(HTTP_OK, response.getStatus())
        content_type = response.getHeader('content-type')
        self.assertTrue(content_type.startswith(self.content_type),
                        content_type)
        content_disposition = response.getHeader('content-disposition')
        self.assertEqual('attachment', content_disposition.split(';')[0])
        body = response.getBody()
        self._validate(body)

        if self.skin == 'ODT':
            # Is it good to do this only for ODT ?
            from Products.ERP5OOo.OOoUtils import OOoParser
            parser = OOoParser()
            parser.openFromString(body)
            content_xml = parser.oo_files['content.xml']
            self.assert_(
                '&lt;Escape&gt;&amp;<text:line-break/>newline' in content_xml)
示例#2
0
  def test_untranslatable_columns(self):
    self.portal.ListBoxZuite_reset()
    self.portal.Localizer = DummyLocalizer()
    message_catalog = self.portal.Localizer.erp5_ui
    # XXX odt style does not seem to display a listbox if it is empty ???
    self.portal.foo_module.newContent(portal_type='Foo')
    message = self.id()
    self.portal.FooModule_viewFooList.listbox.ListBox_setPropertyList(
      field_columns = ['do_not_translate | %s' % message,],
      field_untranslatablecolumns = ['do_not_translate | %s' % message,],
    )
    self.tic()
    self.portal.changeSkin(self.skin)
    response = self.publish(
                   '/%s/foo_module/FooModule_viewFooList?portal_skin='
                   % self.portal.getId(), self.auth)
    self.assertEqual(HTTP_OK, response.getStatus())
    content_type = response.getHeader('content-type')
    self.assertTrue(content_type.startswith(self.content_type), content_type)
    content_disposition = response.getHeader('content-disposition')
    self.assertEqual('attachment', content_disposition.split(';')[0])
    body = response.getBody()
    self._validate(body)

    from Products.ERP5OOo.OOoUtils import OOoParser
    parser = OOoParser()
    parser.openFromString(body)
    content_xml = parser.oo_files['content.xml']
    self.assertTrue(message in content_xml)

    # This untranslatable column have not been translated
    self.assertTrue(message not in message_catalog._translated)
示例#3
0
  def test_untranslatable_columns(self):
    self.portal.ListBoxZuite_reset()
    self.portal.Localizer = DummyLocalizer()
    message_catalog = self.portal.Localizer.erp5_ui
    # XXX odt style does not seem to display a listbox if it is empty ???
    self.portal.foo_module.newContent(portal_type='Foo')
    message = self.id()
    self.portal.FooModule_viewFooList.listbox.ListBox_setPropertyList(
      field_columns = ['do_not_translate | %s' % message,],
      field_untranslatablecolumns = ['do_not_translate | %s' % message,],
    )
    self.tic()
    self.portal.changeSkin(self.skin)
    response = self.publish(
                   '/%s/foo_module/FooModule_viewFooList?portal_skin='
                   % self.portal.getId(), self.auth)
    self.assertEqual(HTTP_OK, response.getStatus())
    content_type = response.getHeader('content-type')
    self.assertTrue(content_type.startswith(self.content_type), content_type)
    content_disposition = response.getHeader('content-disposition')
    self.assertEqual('attachment', content_disposition.split(';')[0])
    body = response.getBody()
    self._validate(body)

    from Products.ERP5OOo.OOoUtils import OOoParser
    parser = OOoParser()
    parser.openFromString(body)
    content_xml = parser.oo_files['content.xml']
    self.assertTrue(message in content_xml)

    # This untranslatable column have not been translated
    self.assertTrue(message not in message_catalog._translated)
def convert(self, filename, data=None):
    from Products.ERP5OOo.OOoUtils import OOoParser
    OOoParser = OOoParser()
    import_file = read(self, filename, data)

    # Extract tables from the speadsheet file
    OOoParser.openFile(import_file)
    filename = OOoParser.getFilename()
    spreadsheets = OOoParser.getSpreadsheetsMapping()

    table_dict = {}
    for table_name, table in spreadsheets.items():
        if not table:
            continue
        # Get the header of the table
        columns_header = table[0]
        # Get the mapping to help us to know the property according a cell index
        property_map = {}
        column_index = 0
        for column in columns_header:
            column_id = getIdFromString(column)
            # The column has no header information
            # The column has a normal header
            property_map[column_index] = column_id
            column_index += 1

        # Construct categories data (with absolut path) from table lines
        object_list = []

        for line in table[1:]:
            object_property_dict = {}

            # Exclude empty lines
            if line.count('') + line.count(None) == len(line):
                continue

            # Analyse every cells of the line
            cell_index = 0
            for cell in line:
                # Ignore empty cells, do the test on the generated id
                # because getIdFromString() is more restrictive
                cell_id = getIdFromString(cell)
                if cell_id not in ('', None):
                    # Get the property corresponding to the cell data
                    property_id = property_map[cell_index]
                    # Convert the value to something like '\xc3\xa9' not '\xc3\xa9'
                    object_property_dict[property_id] = cell.encode('UTF-8')
                cell_index += 1

            if len(object_property_dict) > 0:
                object_list.append(object_property_dict)
        table_dict[table_name.encode('UTF-8')] = object_list

    if len(table_dict.keys()) == 1:
        return object_list
    else:
        return table_dict
示例#5
0
 def test_getSpreadSheetMappingText(self):
     parser = OOoParser()
     parser.openFile(open(makeFilePath('complex_text.ods'), 'rb'))
     mapping = parser.getSpreadsheetsMapping()
     self.assertEquals(['Feuille1'], mapping.keys())
     self.assertEquals(mapping['Feuille1'][0], [' leading space'])
     self.assertEquals(mapping['Feuille1'][1], ['   leading space'])
     self.assertEquals(mapping['Feuille1'][2], ['tab\t'])
     self.assertEquals(mapping['Feuille1'][3], ['New\nLine'])
def convert(self, filename, data=None):
  from Products.ERP5OOo.OOoUtils import OOoParser
  OOoParser = OOoParser()
  import_file = read(self, filename, data)

  # Extract tables from the speadsheet file
  OOoParser.openFile(import_file)
  filename = OOoParser.getFilename()
  spreadsheets = OOoParser.getSpreadsheetsMapping()

  table_dict = {}
  for table_name, table in spreadsheets.items():
    if not table:
      continue
    # Get the header of the table
    columns_header = table[0]
    # Get the mapping to help us to know the property according a cell index
    property_map = {}
    column_index = 0
    for column in columns_header:
      column_id = getIdFromString(column)
      # The column has no header information
      # The column has a normal header
      property_map[column_index] = column_id
      column_index += 1

    # Construct categories data (with absolut path) from table lines
    object_list = []

    for line in table[1:]:
      object_property_dict = {}

      # Exclude empty lines
      if line.count('') + line.count(None) == len(line):
        continue

      # Analyse every cells of the line
      cell_index = 0
      for cell in line:
        # Ignore empty cells, do the test on the generated id 
        # because getIdFromString() is more restrictive
        cell_id = getIdFromString(cell)
        if cell_id not in ('', None):
          # Get the property corresponding to the cell data
          property_id = property_map[cell_index]
          # Convert the value to something like '\xc3\xa9' not '\xc3\xa9'
          object_property_dict[property_id] = cell.encode('UTF-8')
        cell_index += 1

      if len(object_property_dict) > 0:
        object_list.append(object_property_dict)
    table_dict[table_name.encode('UTF-8')] = object_list

  if len(table_dict.keys()) == 1:
    return object_list
  else:
    return table_dict
示例#7
0
 def test_getSpreadSheetMappingText(self):
   parser = OOoParser()
   parser.openFile(open(makeFilePath('complex_text.ods'), 'rb'))
   mapping = parser.getSpreadsheetsMapping()
   self.assertEqual(['Feuille1'], mapping.keys())
   self.assertEqual(mapping['Feuille1'][0], [' leading space'])
   self.assertEqual(mapping['Feuille1'][1], ['   leading space'])
   self.assertEqual(mapping['Feuille1'][2], ['tab\t'])
   self.assertEqual(mapping['Feuille1'][3], ['New\nLine'])
示例#8
0
def getSpreadsheet(file):
    ooo_parser = OOoParser()

    # Extract tables from the speadsheet file
    if file is None:
        return {}
    elif hasattr(file, 'headers'):
        # if the file is not an open office format, try to convert it using oood
        content_type = file.headers.get('Content-Type', '')
        if not (content_type.startswith('application/vnd.sun.xml') or
                content_type.startswith('application/vnd.oasis.opendocument')):

            tmp_ooo = context.newContent(temp_object=True,
                                         portal_type='OOo Document',
                                         id=file.filename)
            tmp_ooo.edit(data=file.read(), content_type=content_type)
            tmp_ooo.convertToBaseFormat()
            ignored, import_file_content = tmp_ooo.convert('ods')
            ooo_parser.openFromString(str(import_file_content))
        else:
            ooo_parser.openFile(file)
    else:
        ooo_parser.openFromString(file)

    return ooo_parser.getSpreadsheetsMapping()
示例#9
0
 def test_getSpreadSheetMappingEmptyCells(self):
   parser = OOoParser()
   parser.openFile(open(makeFilePath('empty_cells.ods'), 'rb'))
   mapping = parser.getSpreadsheetsMapping()
   self.assertEqual(['Feuille1'], mapping.keys())
   self.assertEqual(mapping['Feuille1'],
     [
       ['A1', None, 'C1'],
       [],
       [None, 'B3',],
     ])
示例#10
0
 def test_getSpreadSheetMappingStyle(self):
     parser = OOoParser()
     parser.openFile(
         open(makeFilePath('import_data_list_with_style.ods'), 'rb'))
     mapping = parser.getSpreadsheetsMapping()
     self.assertEquals(['Feuille1'], mapping.keys())
     self.assertEquals(mapping['Feuille1'][1], ['a line with style'])
     self.assertEquals(mapping['Feuille1'][2],
                       ['a line with multiple styles'])
     self.assertEquals(mapping['Feuille1'][3], ['http://www.erp5.org'])
     self.assertEquals(mapping['Feuille1'][4], ['*****@*****.**'])
示例#11
0
 def test_getSpreadSheetMappingEmptyCells(self):
   parser = OOoParser()
   parser.openFile(open(makeFilePath('empty_cells.ods'), 'rb'))
   mapping = parser.getSpreadsheetsMapping()
   self.assertEqual(['Feuille1'], mapping.keys())
   self.assertEqual(mapping['Feuille1'],
     [
       ['A1', None, 'C1'],
       [],
       [None, 'B3',],
     ])
示例#12
0
 def test_getSpreadSheetMapping(self):
   parser = OOoParser()
   parser.openFile(open(makeFilePath('import_data_list.ods'), 'rb'))
   mapping = parser.getSpreadsheetsMapping()
   self.assertEquals(['Person'], mapping.keys())
   person_mapping = mapping['Person']
   self.assertTrue(isinstance(person_mapping, list))
   self.assertTrue(102, len(person_mapping))
   self.assertEquals(person_mapping[0],
      ['Title', 'First Name', 'Last Name', 'Default Email Text'])
   self.assertEquals(person_mapping[1],
      ['John Doe 0', 'John', 'Doe 0', '*****@*****.**'])
示例#13
0
 def test_BigSpreadSheet_can_be_parsed(self, ):
     """Test than OOoimport can parse a file with more than 40000 lines
 """
     parser = OOoParser()
     parser.openFile(open(makeFilePath('import_big_spreadsheet.ods'), 'rb'))
     mapping = parser.getSpreadsheetsMapping()
     not_ok = 1
     for spread, values in mapping.iteritems():
         self.assertEquals(len(values), 41001)
         not_ok = 0
     if not_ok:
         self.fail('Spreadsheet not read!')
示例#14
0
 def test_BigSpreadSheet_can_be_parsed(self,):
   """Test than OOoimport can parse a file with more than 40000 lines
   """
   parser = OOoParser()
   parser.openFile(open(makeFilePath('import_big_spreadsheet.ods'), 'rb'))
   mapping = parser.getSpreadsheetsMapping()
   not_ok = 1
   for spread, values in mapping.iteritems():
     self.assertEqual(len(values), 41001)
     not_ok = 0
   if not_ok:
     self.fail('Spreadsheet not read!')
示例#15
0
 def test_getSpreadSheetMapping(self):
   parser = OOoParser()
   parser.openFile(open(makeFilePath('import_data_list.ods'), 'rb'))
   mapping = parser.getSpreadsheetsMapping()
   self.assertEqual(['Person'], mapping.keys())
   person_mapping = mapping['Person']
   self.assertTrue(isinstance(person_mapping, list))
   self.assertTrue(102, len(person_mapping))
   self.assertEqual(person_mapping[0],
      ['Title', 'First Name', 'Last Name', 'Default Email Text'])
   self.assertEqual(person_mapping[1],
      ['John Doe 0', 'John', 'Doe 0', '*****@*****.**'])
示例#16
0
 def test_getSpreadSheetMappingStyle(self):
   parser = OOoParser()
   parser.openFile(open(makeFilePath('import_data_list_with_style.ods'), 'rb'))
   mapping = parser.getSpreadsheetsMapping()
   self.assertEquals(['Feuille1'], mapping.keys())
   self.assertEquals(mapping['Feuille1'][1],
                     ['a line with style'])
   self.assertEquals(mapping['Feuille1'][2],
                     ['a line with multiple styles'])
   self.assertEquals(mapping['Feuille1'][3],
                     ['http://www.erp5.org'])
   self.assertEquals(mapping['Feuille1'][4],
                     ['*****@*****.**'])
示例#17
0
def getSpreadsheet(file):
  ooo_parser = OOoParser()

  # Extract tables from the speadsheet file
  if file is None:
    return {}
  elif hasattr(file, 'headers'):
    # if the file is not an open office format, try to convert it using oood
    content_type = file.headers.get('Content-Type', '')
    if not (content_type.startswith('application/vnd.sun.xml')
       or content_type.startswith('application/vnd.oasis.opendocument')):

      from Products.ERP5Type.Document import newTempOOoDocument
      tmp_ooo = newTempOOoDocument(context, file.filename)
      tmp_ooo.edit(data=file.read(), content_type=content_type)
      tmp_ooo.convertToBaseFormat()
      ignored, import_file_content = tmp_ooo.convert('ods')
      ooo_parser.openFromString(str(import_file_content))
    else:
      ooo_parser.openFile(file)
  else:
    ooo_parser.openFromString(file)


  return ooo_parser.getSpreadsheetsMapping()
示例#18
0
 def test_getSpreadSheetMappingDataTypes(self):
     parser = OOoParser()
     parser.openFile(
         open(makeFilePath('import_data_list_data_type.ods'), 'rb'))
     mapping = parser.getSpreadsheetsMapping()
     self.assertEqual(['Feuille1'], mapping.keys())
     self.assertEqual(mapping['Feuille1'][0], ['1234.5678'])
     self.assertEqual(mapping['Feuille1'][1], ['1234.5678'])
     self.assertEqual(mapping['Feuille1'][2], ['0.1'])
     self.assertEqual(mapping['Feuille1'][3], ['2008-11-14'])
     self.assertEqual(mapping['Feuille1'][4],
                      ['2008-11-14T10:20:30'])  # supported by DateTime
     self.assertEqual(mapping['Feuille1'][5],
                      ['PT12H34M56S'])  # maybe not good, this is raw format
     self.assertEqual(mapping['Feuille1'][6], ['With note'])
示例#19
0
 def test_getSpreadSheetMappingDataTypes(self):
   parser = OOoParser()
   parser.openFile(open(makeFilePath('import_data_list_data_type.ods'), 'rb'))
   mapping = parser.getSpreadsheetsMapping()
   self.assertEquals(['Feuille1'], mapping.keys())
   self.assertEquals(mapping['Feuille1'][0],
                     ['1234.5678'])
   self.assertEquals(mapping['Feuille1'][1],
                     ['1234.5678'])
   self.assertEquals(mapping['Feuille1'][2],
                     ['0.1'])
   self.assertEquals(mapping['Feuille1'][3],
                     ['2008-11-14'])
   self.assertEquals(mapping['Feuille1'][4],
                     ['2008-11-14T10:20:30']) # supported by DateTime
   self.assertEquals(mapping['Feuille1'][5],
                     ['PT12H34M56S']) # maybe not good, this is raw format
   self.assertEquals(mapping['Feuille1'][6],
                     ['With note'])
示例#20
0
  def test_textarea_center_group(self):
    self._assertFieldInGroup('TextAreaField', 'Person_view', 'center')
    self.assert_('my_description' in [f.getId() for f in
        self.portal.Person_view.get_fields_in_group('center')])
    self.portal.person_module.pers.setDescription('<Escape>&\nnewline')
    response = self.publish(
                   '/%s/person_module/pers/Person_view'
                   % self.portal.getId(), self.auth)
    self.assertEquals(HTTP_OK, response.getStatus())
    content_type = response.getHeader('content-type')
    self.assertTrue(content_type.startswith(self.content_type), content_type)
    content_disposition = response.getHeader('content-disposition')
    self.assertEquals('attachment', content_disposition.split(';')[0])
    body = response.getBody()
    self._validate(body)

    if self.skin == 'ODT':
      # Is it good to do this only for ODT ?
      from Products.ERP5OOo.OOoUtils import OOoParser
      parser = OOoParser()
      parser.openFromString(body)
      content_xml = parser.oo_files['content.xml']
      self.assert_('&lt;Escape&gt;&amp;<text:line-break/>newline' in content_xml)
示例#21
0
    def test_proxy_ooo_chart(self):
      portal = self.getPortal()
      # Does the form exist ?
      self.assertTrue(self.form_id in portal.portal_skins.custom.objectIds())
      getattr(aq_base(portal.portal_skins.custom), self.form_id)
      form = getattr(portal.portal_skins.custom, self.form_id)

      #Proxify the Field my_ooochart
      form.proxifyField({self.ooo_chart_id:'TestOOochart_viewForm.your_ooochart'})
      # Does the field OOoChart exist ?
      ooochart = getattr(form, self.ooo_chart_id)
      self.assertEqual(ooochart.meta_type, 'ProxyField')
      response = self.publish(
                    '/%s/%s/%s?render_format=&display=medium'
                    % (self.portal.getId(), self.form_id, self.ooo_chart_id), self.auth )
      # test render raw
      self.assertEqual(HTTP_OK, response.getStatus())
      content_type = response.getHeader('content-type')

      # test content type : application/vnd.oasis.opendocument.graphics
      self.assertTrue(content_type.startswith(self.content_type), content_type)
      content_disposition = response.getHeader('content-disposition')
      self.assertEqual('attachment', content_disposition.split(';')[0])
      # Test ODG (zip)
      body = response.getBody()
      # Test Validation Relax NG
      self._validate(body)

      from Products.ERP5OOo.OOoUtils import OOoParser
      parser = OOoParser()
      parser.openFromString(body)
      content_xml_view = parser.oo_files['content.xml']

      doc_view = etree.fromstring(content_xml_view)
      xpath = '//@*[name() = "xlink:href"]'
      num_object = doc_view.xpath(xpath)[0][2:]

      content_xml_build = parser.oo_files['%s/content.xml' % num_object]
      doc_build = etree.fromstring(content_xml_build)
      xpath = '//@*[name() = "office:value"]'
      value_list = doc_build.xpath(xpath)
      # Test the data presence in the file XML
      self.assertNotEquals(0, len(value_list))
      # 2 values because there are - 10 document created by a owner
      #                            - 0 Reference count
      self.assertEqual(2, len(value_list))

      # Test the differents render
      # render image
      for image_format in VALID_IMAGE_FORMAT_LIST:
        response = self.publish(
                      '/%s/%s/%s?render_format=%s&display=medium'
                      % (self.portal.getId(), self.form_id, self.ooo_chart_id, image_format), self.auth )
        self.assertEqual(HTTP_OK, response.getStatus(), '%s rendering failed: %s' % (image_format, response.getStatus()))

      # render pdf
      response = self.publish(
                    '/%s/%s/%s?render_format=pdf&display=medium'
                    % (self.portal.getId(), self.form_id, self.ooo_chart_id), self.auth )
      self.assertEqual(HTTP_OK, response.getStatus())


      # Change some params  and restart (circle, bar, ...)
      # chart type : circle
      form.my_ooochart.manage_edit_xmlrpc(dict(chart_type='chart:circle'))
      response = self.publish(
                    '/%s/%s/%s?render_format=&display=medium'
                    % (self.portal.getId(), self.form_id, self.ooo_chart_id), self.auth )
      # Test ODG (zip) with other params
      body = response.getBody()
      # Test Validation Relax NG
      self._validate(body)

      # chart type : line
      form.my_ooochart.manage_edit_xmlrpc(dict(chart_type='chart:line'))
      response = self.publish(
                    '/%s/%s/%s?render_format=&display=medium'
                    % (self.portal.getId(), self.form_id, self.ooo_chart_id), self.auth )
      # Test ODG (zip) with other params
      body = response.getBody()
      # Test Validation Relax NG
      self._validate(body)

      #chart type : scatter
      form.my_ooochart.manage_edit_xmlrpc(dict(chart_type='chart:scatter'))
      response = self.publish(
                    '/%s/%s/%s?render_format=&display=medium'
                    % (self.portal.getId(), self.form_id, self.ooo_chart_id), self.auth )
      # Test ODG (zip) with other params
      body = response.getBody()
      # Test Validation Relax NG
      self._validate(body)
# First retrieve the document
portal = context.getPortalObject()
document_list = portal.document_module.searchFolder(
  reference=reference,
  validation_state="shared",
  sort_on=[('version', 'DESC')],
)
if len(document_list) != 1:
  raise ValueError, "Impossible to find document with reference %s" %(reference)
document = document_list[0].getObject()


# Then parse it
from Products.ERP5OOo.OOoUtils import OOoParser
parser = OOoParser()

def getIDFromString(string=None):
  """
    This function transform a string to a safe and beautiful ID.
    It is used here to create a safe category ID from a string.
    But the code is not really clever...
  """
  if string is None:
    return None
  clean_id = ''
  translation_map = { 'a'  : [u'\xe0', u'\xe3']
                    , 'e'  : [u'\xe9', u'\xe8']
                    , 'i'  : [u'\xed']
                    , 'u'  : [u'\xf9']
                    , '_'  : [' ', '+']
                    , '-'  : ['-', u'\u2013']
示例#23
0
    def test_proxy_ooo_chart(self):
      portal = self.getPortal()
      # Does the form exist ?
      self.assertTrue(self.form_id in portal.portal_skins.custom.objectIds())
      getattr(aq_base(portal.portal_skins.custom), self.form_id)
      form = getattr(portal.portal_skins.custom, self.form_id)

      #Proxify the Field my_ooochart
      form.proxifyField({self.ooo_chart_id:'TestOOochart_viewForm.your_ooochart'})
      # Does the field OOoChart exist ?
      ooochart = getattr(form, self.ooo_chart_id)
      self.assertEqual(ooochart.meta_type, 'ProxyField')
      response = self.publish(
                    '/%s/%s/%s?render_format=&display=medium'
                    % (self.portal.getId(), self.form_id, self.ooo_chart_id), self.auth )
      # test render raw
      self.assertEqual(HTTP_OK, response.getStatus())
      content_type = response.getHeader('content-type')

      # test content type : application/vnd.oasis.opendocument.graphics
      self.assertTrue(content_type.startswith(self.content_type), content_type)
      content_disposition = response.getHeader('content-disposition')
      self.assertEqual('attachment', content_disposition.split(';')[0])
      # Test ODG (zip)
      body = response.getBody()
      # Test Validation Relax NG
      self._validate(body)

      from Products.ERP5OOo.OOoUtils import OOoParser
      parser = OOoParser()
      parser.openFromString(body)
      content_xml_view = parser.oo_files['content.xml']

      doc_view = etree.fromstring(content_xml_view)
      xpath = '//@*[name() = "xlink:href"]'
      num_object = doc_view.xpath(xpath)[0][2:]

      content_xml_build = parser.oo_files['%s/content.xml' % num_object]
      doc_build = etree.fromstring(content_xml_build)
      xpath = '//@*[name() = "office:value"]'
      value_list = doc_build.xpath(xpath)
      # Test the data presence in the file XML
      self.assertNotEquals(0, len(value_list))
      # 2 values because there are - 10 document created by a owner
      #                            - 0 Reference count
      self.assertEqual(2, len(value_list))

      # Test the differents render
      # render image
      for image_format in VALID_IMAGE_FORMAT_LIST:
        response = self.publish(
                      '/%s/%s/%s?render_format=%s&display=medium'
                      % (self.portal.getId(), self.form_id, self.ooo_chart_id, image_format), self.auth )
        self.assertEqual(HTTP_OK, response.getStatus(), '%s rendering failed: %s' % (image_format, response.getStatus()))

      # render pdf
      response = self.publish(
                    '/%s/%s/%s?render_format=pdf&display=medium'
                    % (self.portal.getId(), self.form_id, self.ooo_chart_id), self.auth )
      self.assertEqual(HTTP_OK, response.getStatus())


      # Change some params  and restart (circle, bar, ...)
      # chart type : circle
      form.my_ooochart.manage_edit_xmlrpc(dict(chart_type='chart:circle'))
      response = self.publish(
                    '/%s/%s/%s?render_format=&display=medium'
                    % (self.portal.getId(), self.form_id, self.ooo_chart_id), self.auth )
      # Test ODG (zip) with other params
      body = response.getBody()
      # Test Validation Relax NG
      self._validate(body)

      # chart type : line
      form.my_ooochart.manage_edit_xmlrpc(dict(chart_type='chart:line'))
      response = self.publish(
                    '/%s/%s/%s?render_format=&display=medium'
                    % (self.portal.getId(), self.form_id, self.ooo_chart_id), self.auth )
      # Test ODG (zip) with other params
      body = response.getBody()
      # Test Validation Relax NG
      self._validate(body)

      #chart type : scatter
      form.my_ooochart.manage_edit_xmlrpc(dict(chart_type='chart:scatter'))
      response = self.publish(
                    '/%s/%s/%s?render_format=&display=medium'
                    % (self.portal.getId(), self.form_id, self.ooo_chart_id), self.auth )
      # Test ODG (zip) with other params
      body = response.getBody()
      # Test Validation Relax NG
      self._validate(body)
  
  { 'base_category_id':
       # list of category info
       ( { 'path': 'bc/1',
           'id': '1',
           'title': 'Title 1' },
         { 'path': 'bc/1/2'
           'id': '2',
           'title': 'Title 2' }, ), }

This scripts guarantees that the list of category info is sorted in such a
way that parent always precedes their children.
"""
from Products.ERP5Type.Message import translateString
from Products.ERP5OOo.OOoUtils import OOoParser
parser = OOoParser()
category_list_spreadsheet_mapping = {}
error_list = []

def default_invalid_spreadsheet_error_handler(error_message):
  raise ValueError(error_message)

if invalid_spreadsheet_error_handler is None:
  invalid_spreadsheet_error_handler = default_invalid_spreadsheet_error_handler

property_id_set = context.portal_types.Category.getInstancePropertySet()
property_id_set.update(getattr(context.portal_types, 'Base Category').getInstancePropertySet())

def getIDFromString(string=None):
  """
    This function transform a string to a safe and beautiful ID.
# First retrieve the document
portal = context.getPortalObject()
document_list = portal.document_module.searchFolder(
    reference=reference,
    validation_state="shared",
    sort_on=[('version', 'DESC')],
)
if len(document_list) != 1:
    raise ValueError, "Impossible to find document with reference %s" % (
        reference)
document = document_list[0].getObject()

# Then parse it
from Products.ERP5OOo.OOoUtils import OOoParser
parser = OOoParser()


def getIDFromString(string=None):
    """
    This function transform a string to a safe and beautiful ID.
    It is used here to create a safe category ID from a string.
    But the code is not really clever...
  """
    if string is None:
        return None
    clean_id = ''
    translation_map = {
        'a': [u'\xe0', u'\xe3'],
        'e': [u'\xe9', u'\xe8'],
        'i': [u'\xed'],
        'u': [u'\xf9'],
示例#26
0
  
  { 'base_category_id':
       # list of category info
       ( { 'path': 'bc/1',
           'id': '1',
           'title': 'Title 1' },
         { 'path': 'bc/1/2'
           'id': '2',
           'title': 'Title 2' }, ), }

This scripts guarantees that the list of category info is sorted in such a
way that parent always precedes their children.
"""
from Products.ERP5Type.Message import translateString
from Products.ERP5OOo.OOoUtils import OOoParser
parser = OOoParser()
category_list_spreadsheet_mapping = {}
error_list = []
portal = context.getPortalObject()


def default_invalid_spreadsheet_error_handler(error_message):
    raise ValueError(error_message)


if invalid_spreadsheet_error_handler is None:
    invalid_spreadsheet_error_handler = default_invalid_spreadsheet_error_handler

property_id_set = portal.portal_types.Category.getInstancePropertySet()
property_id_set.update(
    getattr(portal.portal_types, 'Base Category').getInstancePropertySet())
示例#27
0
 def test_openFromString(self):
   parser = OOoParser()
   parser.openFromString(
       open(makeFilePath('import_data_list.ods'), 'rb').read())
   mapping = parser.getSpreadsheetsMapping()
   self.assertEquals(['Person'], mapping.keys())
示例#28
0
 def test_openFromString(self):
     parser = OOoParser()
     parser.openFromString(
         open(makeFilePath('import_data_list.ods'), 'rb').read())
     mapping = parser.getSpreadsheetsMapping()
     self.assertEquals(['Person'], mapping.keys())