Example #1
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)
Example #2
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()
Example #3
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()
Example #4
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)
Example #5
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)
Example #6
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)
Example #7
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)
Example #8
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)
Example #9
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())
Example #10
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())
Example #11
0

# if the file is not an open office format, try to convert it using oood
# FIXME: use portal_transforms
content_type = 'unknown'
if hasattr(import_file, 'headers'):
    content_type = import_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(portal_type='OOo Document',
                                 temp_object=True,
                                 data=import_file.read(),
                                 content_type=content_type)
    tmp_ooo.convertToBaseFormat()
    _, import_file_content = tmp_ooo.convert('ods')
    parser.openFromString(str(import_file_content))
else:
    parser.openFile(import_file)

# Extract tables from the speadsheet file
spreadsheet_list = parser.getSpreadsheetsMapping(no_empty_lines=True)

for table_name in spreadsheet_list.keys():
    sheet = spreadsheet_list[table_name]
    if not sheet:
        continue
    # Get the header of the table
    columns_header = sheet[0]
    # Get the mapping to help us know the property according a cell index
    property_map = {}
    column_index = 0
            string = string.replace(char, safe_char)
    # Exclude all non alphanumeric chars
    for char in string:
        if char.isalnum() or char in translation_map.keys():
            clean_id += char
    # Delete leading and trailing char which are not alpha-numerics
    # This prevent having IDs with starting underscores
    while len(clean_id) > 0 and not clean_id[0].isalnum():
        clean_id = clean_id[1:]
    while len(clean_id) > 0 and not clean_id[-1].isalnum():
        clean_id = clean_id[:-1]

    return clean_id


parser.openFromString(str(document.getData()))

# Extract tables from the speadsheet file
filename = parser.getFilename()
spreadsheet_list = parser.getSpreadsheetsMapping(no_empty_lines=True)

spreadsheet_line_list = []

for table_name in spreadsheet_list.keys():
    if table_name != table:
        continue
    sheet = spreadsheet_list[table_name]
    if not sheet:
        continue
    # Get the header of the table
    columns_header = sheet[0]
  return clean_id

# if the file is not an open office format, try to convert it using oood
# FIXME: use portal_transforms
content_type = 'unknown'
if hasattr(import_file, 'headers'):
  content_type = import_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, "_")
  tmp_ooo.edit(data=import_file.read(),
               content_type=content_type)
  tmp_ooo.convertToBaseFormat()
  ignored, import_file_content = tmp_ooo.convert('ods')
  parser.openFromString(str(import_file_content))
else:
  parser.openFile(import_file)

# Extract tables from the speadsheet file
filename = parser.getFilename()
spreadsheet_list = parser.getSpreadsheetsMapping(no_empty_lines=True)


for table_name in spreadsheet_list.keys():
  sheet = spreadsheet_list[table_name]
  if not sheet:
    continue
  # Get the header of the table
  columns_header = sheet[0]
  # Get the mapping to help us know the property according a cell index
    for char in char_list:
      string = string.replace(char, safe_char)
  # Exclude all non alphanumeric chars
  for char in string:
    if char.isalnum() or char in translation_map.keys():
      clean_id += char
  # Delete leading and trailing char which are not alpha-numerics
  # This prevent having IDs with starting underscores
  while len(clean_id) > 0 and not clean_id[0].isalnum():
    clean_id = clean_id[1:]
  while len(clean_id) > 0 and not clean_id[-1].isalnum():
    clean_id = clean_id[:-1]

  return clean_id

parser.openFromString(str(document.getData()))

# Extract tables from the speadsheet file
filename = parser.getFilename()
spreadsheet_list = parser.getSpreadsheetsMapping(no_empty_lines=True)

spreadsheet_line_list = []

for table_name in spreadsheet_list.keys():
  if table_name != table:
    continue
  sheet = spreadsheet_list[table_name]
  if not sheet:
    continue
  # Get the header of the table
  columns_header = sheet[0]