Exemple #1
0
    def handle(self, product_class_name, filepath):
        product_class = ProductClass.objects.get(name=product_class_name)

        attribute_codes = []
        with UnicodeCSVReader(filepath) as reader:
            for row in reader:
                if row[1] == 'UPC':
                    attribute_codes = row[9:]
                    continue
                self.create_product(product_class, attribute_codes, row)
Exemple #2
0
 def _import(self, file_path):
     """Imports given file"""
     stats = {'new_items': 0, 'updated_items': 0}
     row_number = 0
     with UnicodeCSVReader(file_path,
                           delimiter=self._delimiter,
                           quotechar='"',
                           escapechar='\\') as reader:
         for row in reader:
             row_number += 1
             self._import_row(row_number, row, stats)
     msg = "New items: %d, updated items: %d" % (stats['new_items'],
                                                 stats['updated_items'])
     self.logger.info(msg)