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


Python OOoUtils.OOoParser类代码示例

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


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

示例1: test_untranslatable_columns

  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,代码行数:32,代码来源:testOOoStyle.py

示例2: convert

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
开发者ID:MarkTang,项目名称:erp5,代码行数:57,代码来源:extension.erp5.ConfigurationTemplate_readOOoCalcFile.py

示例3: test_getSpreadSheetMappingText

 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'])
开发者ID:Verde1705,项目名称:erp5,代码行数:9,代码来源:testOOoParser.py

示例4: test_getSpreadSheetMappingEmptyCells

 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',],
     ])
开发者ID:Verde1705,项目名称:erp5,代码行数:11,代码来源:testOOoParser.py

示例5: getSpreadsheet

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,代码行数:25,代码来源:Base_importFile.py

示例6: test_textarea_center_group

  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,代码行数:23,代码来源:testOOoStyle.py

示例7: test_proxy_ooo_chart

    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,代码行数:92,代码来源:testOOoChart.py

示例8: OOoParser

  
  { '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.
开发者ID:ccwalkerjm,项目名称:erp5,代码行数:30,代码来源:Base_getCategoriesSpreadSheetMapping.py

示例9: len

# 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']
开发者ID:ccwalkerjm,项目名称:erp5,代码行数:31,代码来源:DocumentConnector_readDocument.py


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