当前位置: 首页>>代码示例>>Python>>正文


Python OOoParser.openFromString方法代码示例

本文整理汇总了Python中Products.ERP5OOo.OOoUtils.OOoParser.openFromString方法的典型用法代码示例。如果您正苦于以下问题:Python OOoParser.openFromString方法的具体用法?Python OOoParser.openFromString怎么用?Python OOoParser.openFromString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Products.ERP5OOo.OOoUtils.OOoParser的用法示例。


在下文中一共展示了OOoParser.openFromString方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getSpreadsheet

# 需要导入模块: from Products.ERP5OOo.OOoUtils import OOoParser [as 别名]
# 或者: from Products.ERP5OOo.OOoUtils.OOoParser import openFromString [as 别名]
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()
开发者ID:ccwalkerjm,项目名称:erp5,代码行数:27,代码来源:Base_importFile.py

示例2: test_untranslatable_columns

# 需要导入模块: from Products.ERP5OOo.OOoUtils import OOoParser [as 别名]
# 或者: from Products.ERP5OOo.OOoUtils.OOoParser import openFromString [as 别名]
  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)
开发者ID:Verde1705,项目名称:erp5,代码行数:34,代码来源:testOOoStyle.py

示例3: test_textarea_center_group

# 需要导入模块: from Products.ERP5OOo.OOoUtils import OOoParser [as 别名]
# 或者: from Products.ERP5OOo.OOoUtils.OOoParser import openFromString [as 别名]
  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)
开发者ID:joehelmstetler,项目名称:erp5,代码行数:25,代码来源:testOOoStyle.py

示例4: test_proxy_ooo_chart

# 需要导入模块: from Products.ERP5OOo.OOoUtils import OOoParser [as 别名]
# 或者: from Products.ERP5OOo.OOoUtils.OOoParser import openFromString [as 别名]
    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)
开发者ID:Verde1705,项目名称:erp5,代码行数:94,代码来源:testOOoChart.py

示例5: hasattr

# 需要导入模块: from Products.ERP5OOo.OOoUtils import OOoParser [as 别名]
# 或者: from Products.ERP5OOo.OOoUtils.OOoParser import openFromString [as 别名]
  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
开发者ID:ccwalkerjm,项目名称:erp5,代码行数:33,代码来源:Base_getCategoriesSpreadSheetMapping.py

示例6: len

# 需要导入模块: from Products.ERP5OOo.OOoUtils import OOoParser [as 别名]
# 或者: from Products.ERP5OOo.OOoUtils.OOoParser import openFromString [as 别名]
    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]
开发者ID:ccwalkerjm,项目名称:erp5,代码行数:33,代码来源:DocumentConnector_readDocument.py


注:本文中的Products.ERP5OOo.OOoUtils.OOoParser.openFromString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。