def _product(self, item): try: product = Product.objects.get(wholesale_legacy_id=int(item['id']), is_visible=True) except Product.DoesNotExist: product = Product() except Product.MultipleObjectsReturned: print item['id'] for p in Product.objects.filter(wholesale_legacy_id=int(item['id'])): print p.id, p.title, p.code, p.sku print '-----' raise quantity = int(item.get('qtyi', 0)) if quantity < 0: quantity = 0 weight = int(item.get('weight', 0)) if weight < 0: weight = 0 product.sku = item['article'] product.weight = weight product.quantity = quantity product.code = item['link'] product.title = item['name'] product.description = item['descr'] product.is_visible = bool(int(item['pub'])) product.wholesale_legacy_id = item['id'] product.created = TIMEZONE.localize(datetime.datetime.fromtimestamp(int(item['dt']))) size = None try: size = SIZE_RE.findall(u' '.join([item['name'], item.get('alt', ''), item['descr']]))[0] except IndexError: try: size = SIZE2_RE.findall(u' '.join([item['name'], item.get('alt', ''), item['descr']]))[0] except IndexError: pass if size: product.size = u'×'.join([str(x) for x in size]) return product
def _product(self, item): try: product = Product.objects.get(id=int(item['id'])) except Product.DoesNotExist: product = Product(id=int(item['id'])) quantity = int(item.get('qtyi', 0)) if quantity < 0: quantity = 0 weight = int(item.get('weight', 0)) if weight < 0: weight = 0 product.sku = item['article'] product.weight = weight product.quantity = quantity product.code = item['link'] product.title = item['name'] product.description = item['descr'] product.is_visible = bool(int(item['pub'])) product.is_wholesale = False product.created = TIMEZONE.localize(datetime.datetime.fromtimestamp(int(item['dt']))) size = None try: size = SIZE_RE.findall(u' '.join([item['name'], item.get('alt', ''), item['descr']]))[0] except IndexError: try: size = SIZE2_RE.findall(u' '.join([item['name'], item.get('alt', ''), item['descr']]))[0] except IndexError: pass if size: product.size = u'×'.join([str(x) for x in size]) return product