當前位置: 首頁>>代碼示例>>Python>>正文


Python SpreadsheetImport.mapping方法代碼示例

本文整理匯總了Python中spreadsheetimport.SpreadsheetImport.mapping方法的典型用法代碼示例。如果您正苦於以下問題:Python SpreadsheetImport.mapping方法的具體用法?Python SpreadsheetImport.mapping怎麽用?Python SpreadsheetImport.mapping使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在spreadsheetimport.SpreadsheetImport的用法示例。


在下文中一共展示了SpreadsheetImport.mapping方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testImportSimple

# 需要導入模塊: from spreadsheetimport import SpreadsheetImport [as 別名]
# 或者: from spreadsheetimport.SpreadsheetImport import mapping [as 別名]
    def testImportSimple(self):
        no_signals()
        testimport = SpreadsheetImport(StringIO(csv_file), [self.collection])
        self.assertEqual(0, self.collection.records.count())
        testimport.analyze()

        dc = dict(
            identifier=Field.objects.get(name='identifier', standard__prefix='dc'),
            title=Field.objects.get(name='title', standard__prefix='dc'),
            creator=Field.objects.get(name='creator', standard__prefix='dc'),
            coverage=Field.objects.get(name='coverage', standard__prefix='dc'),
        )

        testimport.mapping = {
            'ID': dc['identifier'],
            'Filename': None,
            'Title': dc['title'],
            'Creator': dc['creator'],
            'Location': dc['coverage'],
        }
        testimport.name_field = 'ID'

        self.assertNotEqual(None, testimport.get_identifier_field())

        testimport.run()

        self.assertEquals(2, self.collection.records.count())

        r1 = self.collection.records.get(name='A001'.lower())
        self.assertEqual('A001', r1.fieldvalue_set.get(field=dc['identifier']).value)
開發者ID:eResearchSandpit,項目名稱:rooibos,代碼行數:32,代碼來源:tests.py

示例2: test_split_values_import

# 需要導入模塊: from spreadsheetimport import SpreadsheetImport [as 別名]
# 或者: from spreadsheetimport.SpreadsheetImport import mapping [as 別名]
 def test_split_values_import(self):
     testimport = SpreadsheetImport(
         StringIO("ID,Split,NoSplit\nA999,a;b,a;b"), [self.collection])
     testimport.analyze()
     dc = dict(
         identifier=Field.objects.get(
             name='identifier', standard__prefix='dc'),
         title=Field.objects.get(name='title', standard__prefix='dc'),
         creator=Field.objects.get(name='creator', standard__prefix='dc'),
     )
     testimport.mapping = {
         'ID': dc['identifier'],
         'Split': dc['title'],
         'NoSplit': dc['creator'],
     }
     testimport.name_field = 'ID'
     testimport.separate_fields = {
         'Split': True,
     }
     testimport.run()
     r = self.collection.records.get(name='A999'.lower())
     self.assertEqual(
         'a',
         r.fieldvalue_set.filter(field=testimport.mapping['Split'])[0].value
     )
     self.assertEqual(
         'b',
         r.fieldvalue_set.filter(field=testimport.mapping['Split'])[1].value
     )
     self.assertEqual(
         'a;b',
         r.fieldvalue_set.filter(
             field=testimport.mapping['NoSplit'])[0].value
     )
開發者ID:hanleybrand,項目名稱:rooibos,代碼行數:36,代碼來源:tests.py


注:本文中的spreadsheetimport.SpreadsheetImport.mapping方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。