Esempio n. 1
0
    def write_data(self, book):
        new_models = [model for model in self.models if model is not None]
        batch_size = self.keywords.get(params.BATCH_SIZE, None)
        initializers = self.keywords.get(params.INITIALIZERS, None)
        if initializers is None:
            initializers = [None] * len(new_models)
        mapdicts = self.keywords.get(params.MAPDICTS, None)
        if mapdicts is None:
            mapdicts = [None] * len(new_models)
        for sheet in book:
            if len(sheet.colnames) == 0:
                sheet.name_columns_by_row(0)
        colnames_array = [sheet.colnames for sheet in book]
        scattered = zip(new_models, colnames_array, mapdicts, initializers)

        importer = DjangoModelImporter()
        for each_model in scattered:
            adapter = DjangoModelImportAdapter(each_model[0])
            adapter.set_column_names(each_model[1])
            adapter.set_column_name_mapping_dict(each_model[2])
            adapter.set_row_initializer(each_model[3])
            importer.append(adapter)
        to_store = OrderedDict()
        for sheet_name in book.sheet_names():
            # due book.to_dict() brings in column_names
            # which corrupts the data
            to_store[sheet_name] = book[sheet_name].array
        save_data(importer,
                  to_store,
                  file_type=DB_DJANGO,
                  batch_size=batch_size)
Esempio n. 2
0
    def write_data(self, book):
        new_models = [model for model in self.models if model is not None]
        batch_size = self.keywords.get(params.BATCH_SIZE, None)
        initializers = self.keywords.get(params.INITIALIZERS, None)
        if initializers is None:
            initializers = [None] * len(new_models)
        mapdicts = self.keywords.get(params.MAPDICTS, None)
        if mapdicts is None:
            mapdicts = [None] * len(new_models)
        for sheet in book:
            if len(sheet.colnames) == 0:
                sheet.name_columns_by_row(0)
        colnames_array = [sheet.colnames for sheet in book]
        scattered = zip(new_models, colnames_array, mapdicts, initializers)

        importer = DjangoModelImporter()
        for each_model in scattered:
            adapter = DjangoModelImportAdapter(each_model[0])
            adapter.set_column_names(each_model[1])
            adapter.set_column_name_mapping_dict(each_model[2])
            adapter.set_row_initializer(each_model[3])
            importer.append(adapter)
        to_store = OrderedDict()
        for sheet_name in book.sheet_names():
            # due book.to_dict() brings in column_names
            # which corrupts the data
            to_store[sheet_name] = book[sheet_name].array
        save_data(importer, to_store, file_type=DB_DJANGO,
                  batch_size=batch_size)
Esempio n. 3
0
 def write_data(self, sheet):
     headers = sheet.colnames
     if len(headers) == 0:
         headers = sheet.rownames
     importer = DjangoModelImporter()
     adapter = DjangoModelImportAdapter(self.model)
     adapter.set_column_names(headers)
     adapter.set_column_name_mapping_dict(self.keywords.get(params.MAPDICT, None))
     adapter.set_row_initializer(self.keywords.get(params.INITIALIZER, None))
     importer.append(adapter)
     save_data(importer, {adapter.get_name(): sheet.array}, file_type=DB_DJANGO, **self.keywords)
Esempio n. 4
0
 def write_data(self, sheet):
     headers = sheet.colnames
     if len(headers) == 0:
         headers = sheet.rownames
     importer = DjangoModelImporter()
     adapter = DjangoModelImportAdapter(self.model)
     adapter.set_column_names(headers)
     adapter.set_column_name_mapping_dict(
         self.keywords.get(params.MAPDICT, None))
     adapter.set_row_initializer(self.keywords.get(params.INITIALIZER,
                                                   None))
     importer.append(adapter)
     save_data(importer, {adapter.get_name(): sheet.array},
               file_type=DB_DJANGO)