Пример #1
0
    def render_book_to_stream(self,
                              file_stream,
                              book,
                              inits=None,
                              mapdicts=None,
                              **keywords):
        session, tables = file_stream
        thebook = book
        initializers = inits
        colnames_array = common.get_book_headers_in_array(book)
        if initializers is None:
            initializers = [None] * len(tables)
        if mapdicts is None:
            mapdicts = [None] * len(tables)
        scattered = zip(tables, colnames_array, mapdicts, initializers)

        importer = sql.SQLTableImporter(session)
        for each_table in scattered:
            adapter = sql.SQLTableImportAdapter(each_table[0])
            adapter.column_names = each_table[1]
            adapter.column_name_mapping_dict = each_table[2]
            adapter.row_initializer = each_table[3]
            importer.append(adapter)
        to_store = OrderedDict()
        for sheet in thebook:
            # due book.to_dict() brings in column_names
            # which corrupts the data
            to_store[sheet.name] = sheet.get_internal_array()
        save_data(importer, to_store, file_type=self._file_type, **keywords)
Пример #2
0
    def render_book_to_stream(self, file_stream, book,
                              inits=None, mapdicts=None, **keywords):
        session, tables = file_stream
        thebook = book
        initializers = inits
        colnames_array = common.get_book_headers_in_array(book)
        if initializers is None:
            initializers = [None] * len(tables)
        if mapdicts is None:
            mapdicts = [None] * len(tables)
        scattered = zip(tables, colnames_array, mapdicts, initializers)

        importer = sql.SQLTableImporter(session)
        for each_table in scattered:
            adapter = sql.SQLTableImportAdapter(each_table[0])
            adapter.column_names = each_table[1]
            adapter.column_name_mapping_dict = each_table[2]
            adapter.row_initializer = each_table[3]
            importer.append(adapter)
        to_store = OrderedDict()
        for sheet in thebook:
            # due book.to_dict() brings in column_names
            # which corrupts the data
            to_store[sheet.name] = sheet.get_internal_array()
        save_data(importer, to_store, file_type=self._file_type, **keywords)
Пример #3
0
    def render_book_to_stream(self,
                              models,
                              book,
                              inits=None,
                              mapdicts=None,
                              batch_size=None,
                              **keywords):
        colnames_array = common.get_book_headers_in_array(book)
        new_models = [model for model in models if model is not None]
        initializers = inits
        if initializers is None:
            initializers = [None] * len(new_models)
        if mapdicts is None:
            mapdicts = [None] * len(new_models)
        scattered = zip(new_models, colnames_array, mapdicts, initializers)

        importer = django.DjangoModelImporter()
        for each_model in scattered:
            adapter = django.DjangoModelImportAdapter(each_model[0])
            adapter.column_names = each_model[1]
            adapter.column_name_mapping_dict = each_model[2]
            adapter.row_initializer = each_model[3]
            importer.append(adapter)
        to_store = OrderedDict()
        for sheet in book:
            # due book.to_dict() brings in column_names
            # which corrupts the data
            to_store[sheet.name] = sheet.get_internal_array()
        save_data(importer,
                  to_store,
                  file_type=self._file_type,
                  batch_size=batch_size,
                  **keywords)
Пример #4
0
    def render_book_to_stream(self, models, book,
                              inits=None, mapdicts=None,
                              batch_size=None, **keywords):
        colnames_array = common.get_book_headers_in_array(book)
        new_models = [model for model in models if model is not None]
        initializers = inits
        if initializers is None:
            initializers = [None] * len(new_models)
        if mapdicts is None:
            mapdicts = [None] * len(new_models)
        scattered = zip(new_models, colnames_array, mapdicts, initializers)

        importer = django.DjangoModelImporter()
        for each_model in scattered:
            adapter = django.DjangoModelImportAdapter(each_model[0])
            adapter.column_names = each_model[1]
            adapter.column_name_mapping_dict = each_model[2]
            adapter.row_initializer = each_model[3]
            importer.append(adapter)
        to_store = OrderedDict()
        for sheet in book:
            # due book.to_dict() brings in column_names
            # which corrupts the data
            to_store[sheet.name] = sheet.get_internal_array()
        save_data(importer, to_store, file_type=self._file_type,
                  batch_size=batch_size, **keywords)
Пример #5
0
def test_get_book_headers_in_array():
    data = iter([["a", "b", "c"], [1, 2, 3]])
    book_stream = BookStream({"test": data})
    colnames_array = get_book_headers_in_array(book_stream)
    eq_(colnames_array, [["a", "b", "c"]])
Пример #6
0
def test_get_book_headers_in_array():
    data = iter([['a', 'b', 'c'], [1, 2, 3]])
    book_stream = BookStream({'test': data})
    colnames_array = get_book_headers_in_array(book_stream)
    eq_(colnames_array, [['a', 'b', 'c']])