def create_brand(self, brand_name): try: brand = Brand.objects.using('default').get(name = brand_name) except Brand.DoesNotExist: brand = Brand(name = brand_name, slug = slugify(brand_name)) brand.save(using='default') return brand
def create_brand(self, brand_name): try: brand = Brand.objects.using('default').get(name=brand_name) except Brand.DoesNotExist: brand = Brand(name=brand_name, slug=slugify(brand_name)) brand.save(using='default') return brand
def get_brand(self, name): try: br = Brand.objects.get(name = name) except Brand.DoesNotExist: br = Brand(name = name, slug = slugify(name)) br.save() return br
def get_other_brand(self, brand): if self._other_brand_cache: return self._other_brand_cache try: self._other_brand_cache = Brand.objects.get(name=brand) return self._other_brand_cache except Brand.DoesNotExist: brand = Brand(name=brand, slug=slugify(brand)) brand.save() self._other_brand_cache = brand return self._other_brand_cache
def get_or_create_brand_mapping(account, theirs, ours): try: b = Brand.objects.using('default').get(name=ours) except Brand.DoesNotExist: try: b = Brand(name=ours,slug=slugify(ours),moderate=True) b.save(using='default') except: b = Brand.objects.using('default').get(name='Unknown') try: brand_mapping = BrandMapping.objects.using('default').get( brand=theirs, account=account, mapped_to=b) return brand_mapping except BrandMapping.DoesNotExist: brand_mapping = BrandMapping(mapped_to=b, brand=theirs, account=account) brand_mapping.save(using='default') return brand_mapping
def get_or_create_brand_mapping(account, theirs, ours): try: b = Brand.objects.using('default').get(name=ours) except Brand.DoesNotExist: try: b = Brand(name=ours, slug=slugify(ours), moderate=True) b.save(using='default') except: b = Brand.objects.using('default').get(name='Unknown') try: brand_mapping = BrandMapping.objects.using('default').get( brand=theirs, account=account, mapped_to=b) return brand_mapping except BrandMapping.DoesNotExist: brand_mapping = BrandMapping(mapped_to=b, brand=theirs, account=account) brand_mapping.save(using='default') return brand_mapping
def parse(self, sync, *args, **kwargs): wb = xlrd.open_workbook( '/home/apps/tinla/feeds/data/holii/Holii_Data.xls') count, heading_map = 0, {} s = wb.sheet_by_index(0) try: get_product_type = ProductType.objects.using('default').get( type='HandBags - US') except ProductType.DoesNotExist: get_product_type = ProductType(type='HandBags US') get_product_type.save(using='default') for col in range(s.ncols): heading_map[s.cell(0, col).value.lower()] = col products = [] for row_num in range(1, s.nrows): row = s.row(row_num) brand = row[heading_map['category 1']].value.strip() parent_category = row[heading_map['category 3']].value.strip() usholii_client = Client.objects.using('default').get( name='US Holii') try: get_parent_category = Category.objects.using('default').get( name=parent_category, client=usholii_client) except Category.DoesNotExist: get_parent_category = Category(name=parent_category, client=usholii_client, slug=slugify(parent_category)) get_parent_category.save(using='default') try: get_feature_group = FeatureGroup.objects.using('default').get( category=get_parent_category, product_type=get_product_type) except FeatureGroup.DoesNotExist: get_feature_group = FeatureGroup(category=get_parent_category, product_type=get_product_type, name=parent_category) print "get_parent_category ", get_parent_category.id, "get_product_type ", get_product_type.id, "parent_category ", parent_category get_feature_group.save(using='default') try: #this is to create a category with parent = none i.e parent itself is added parent_child_map = CategoryGraph.objects.using('default').get( category=get_parent_category, parent=None) except CategoryGraph.DoesNotExist: parent_child_map = CategoryGraph(category=get_parent_category, parent=None) parent_child_map.save(using='default') try: get_brand = Brand.objects.using('default').get(name=brand) except Brand.DoesNotExist: get_brand = Brand(name=brand, slug=slugify(brand)) get_brand.save(using='default') rows_visited = [] for row_num in range(1, s.nrows): if row_num in rows_visited: continue data = dict(cleaned_data=self.get_default_cleaned_data()) product_variants = [] first_row = row_num temp_row = s.row(row_num) for variants in range( row_num, (row_num + int(temp_row[heading_map['variant']].value))): data = dict(cleaned_data=self.get_default_cleaned_data()) row = s.row(variants) if row[heading_map['sku']].ctype in (2, 3): article_id = str(int(row[heading_map['sku']].value)) else: article_id = str(row[heading_map['sku']].value) data['cleaned_data']['sku'] = article_id data['cleaned_data']['article_id'] = article_id data['cleaned_data']['title'] = row[ heading_map['product title']].value data['cleaned_data']['detailed_desc'] = row[ heading_map['product description']].value or '--' data['cleaned_data']['brand'] = Brand.objects.using( 'default').get(name=row[heading_map['category 1']].value) data['cleaned_data']['category'] = Category.objects.using( 'default').get(name=row[heading_map['category 3']].value, client=usholii_client) data['cleaned_data']['model'] = '' usd_list_price = Decimal(str( row[heading_map['usd']].value)).quantize(Decimal('1.'), rounding=ROUND_UP) today = datetime.now().day #considered same offer and list price for US Holii usd_offer_price = usd_list_price data['cleaned_data']['shipping_duration'] = row[ heading_map['shipping duration']].value image_urls = [] stock_status = 'instock' status = 'active' image_path = '/home/apps/tinla/media/holii/images/pd/%s' % ( str(int(row[heading_map['image url']].value))) try: listing = os.listdir(image_path) listing = sorted(listing) for infile in listing: if infile != 'Thumbs.db': image_urls.append( 'http://www.holii.in/media/images/pd/%s/%s' % (str(int(row[heading_map['image url']].value)), infile)) except Exception, e: print e #if not image_urls: stock_status = 'notavailable' status = 'deactive' data['cleaned_data']['stock_status'] = stock_status data['cleaned_data']['status'] = status data['cleaned_data']['image_url'] = image_urls data['cleaned_data'][ 'availability'] = Availability.objects.using( 'default').get(id=1) data['cleaned_data']['product_type'] = 'variant' data['cleaned_data']['sku_type'] = 'HandBags US' data['cleaned_data']['usd'] = usd_list_price if variants == first_row: data['cleaned_data']['is_default_product'] = True else: data['cleaned_data']['is_default_product'] = False data['cleaned_data']['features'] = { 'Style': { 'feature_type': 'fixed', 'type': 'text', 'data': row[heading_map['category 2']].value }, 'Dimensions (L x H x W)': { 'feature_type': 'fixed', 'type': 'text', 'data': str(row[heading_map['dimensions']].value) + ' cms' } } # price_lists = [] # holii_price_list = None # applicable_price_lists = [] # try: # usholii_price_list = PriceList.objects.using('default').get(name='us holii') # except PriceList.DoesNotExist: # holii_price_list = PriceList(name='us holii') # holii_price_list.save(using='default') # applicable_price_lists.append(holii_price_list) # if usd_list_price != 0: # price_lists.append({ # 'price_list':holii_price_list, # 'list_price':usd_list_price, # 'offer_price':usd_offer_price}) data['cleaned_data']['list_price'] = usd_list_price data['cleaned_data']['offer_price'] = usd_offer_price # data['cleaned_data']['usd_list_price'] = usd_list_price # data['cleaned_data']['price_lists'] = price_lists # data['cleaned_data']['applicable_price_lists'] = applicable_price_lists product_variants.append(data) rows_visited.append(variants) products.append(product_variants)
def parse(self, sync, *args, **kwargs): wb = xlrd.open_workbook( '/home/saumil/tinla/feeds/data/fgc/FGC_Data.xls') count, heading_map = 0, {} s = wb.sheet_by_index(0) for col in range(s.ncols): heading_map[s.cell(0, col).value.lower()] = col fgc_client = Client.objects.get(name='Future Gift Cards') # Category try: category = Category.objects.get(name='Gift Vouchers', client=fgc_client) except Category.DoesNotExist: category = Category(name='Gift Vouchers', client=fgc_client, slug=slugify('Gift Vouchers')) category.save() products, product_variants, rows_visited, flag, first_row = [], [], [], 0, 0 for row_num in range(1, s.nrows): row = s.row(row_num) brand = row[heading_map['brand']].value # Brand try: brand = Brand.objects.get(name=brand) brand.description = row[heading_map['brand description']].value brand.save() except Brand.DoesNotExist: brand = Brand( name=brand, description=row[heading_map['brand description']].value, slug=slugify(brand)) brand.save() if row_num in rows_visited: continue product_variants = [] first_row = row_num temp_row = s.row(row_num) for variants in range( row_num, (row_num + int(temp_row[heading_map['variant']].value))): data = dict(cleaned_data=self.get_default_cleaned_data()) row = s.row(variants) if row[heading_map['skuid']].ctype in (2, 3): data['cleaned_data']['sku'] = str( int(row[heading_map['skuid']].value)) else: data['cleaned_data']['sku'] = str( row[heading_map['skuid']].value) data['cleaned_data']['title'] = row[heading_map['title']].value data['cleaned_data']['detailed_desc'] = row[ heading_map['description']].value data['cleaned_data']['brand'] = brand data['cleaned_data']['category'] = category data['cleaned_data']['model'] = '' image_path = 'http://dev.futuregiftcards.com:8000/media/images/pd/%s.jpg' data['cleaned_data']['image_url'] = [ image_path % str(row[heading_map['image name']].value) ] data['cleaned_data']['stock_status'] = 'instock' data['cleaned_data']['status'] = 'active' data['cleaned_data']['list_price'] = Decimal( str(row[heading_map['mrp']].value)) data['cleaned_data']['offer_price'] = Decimal( str(row[heading_map['offer price']].value)) data['cleaned_data']['gift_desc'] = row[ heading_map['terms & conditions']].value data['cleaned_data']['shipping_duration'] = row[ heading_map['delivery time']] data['cleaned_data']['product_type'] = 'variant' data['cleaned_data'][ 'availability'] = Availability.objects.get(id=1) data['cleaned_data']['is_default_product'] = ( variants == first_row) and True or False product_variants.append(data) rows_visited.append(variants) products.append(product_variants) return products
def parse(self, sync, *args, **kwargs): wb = xlrd.open_workbook('/home/apps/tinla/feeds/data/holii/Holii_Data.xls') count,heading_map = 0,{} s=wb.sheet_by_index(0) try: get_product_type = ProductType.objects.get(type = 'HandBags - World') except ProductType.DoesNotExist: get_product_type = ProductType(type = 'HandBags - World') get_product_type.save() for col in range(s.ncols): heading_map[s.cell(0,col).value.lower()] = col products=[] for row_num in range(1,s.nrows): row = s.row(row_num) brand = row[heading_map['category 1']].value.strip() parent_category = row[heading_map['category 3']].value.strip() holii_client = Client.objects.get(name = 'World Holii') try: get_parent_category = Category.objects.get(name=parent_category,client=holii_client) except Category.DoesNotExist: get_parent_category=Category(name = parent_category,client=holii_client,slug=slugify(parent_category)) get_parent_category.save() try: get_feature_group = FeatureGroup.objects.get(category = get_parent_category, product_type = get_product_type) except FeatureGroup.DoesNotExist: get_feature_group = FeatureGroup(category = get_parent_category, product_type = get_product_type, name = parent_category) get_feature_group.save() try: #this is to create a category with parent = none i.e parent itself is added parent_child_map = CategoryGraph.objects.get(category = get_parent_category,parent=None) except CategoryGraph.DoesNotExist: parent_child_map = CategoryGraph(category = get_parent_category,parent=None) parent_child_map.save() try: get_brand = Brand.objects.get(name = brand) except Brand.DoesNotExist: get_brand = Brand(name = brand, slug = slugify(brand)) get_brand.save() rows_visited = [] for row_num in range(1,s.nrows): if row_num in rows_visited: continue data = dict(cleaned_data=self.get_default_cleaned_data()) product_variants=[] first_row = row_num temp_row = s.row(row_num) for variants in range(row_num,(row_num+int(temp_row[heading_map['variant']].value))): data = dict(cleaned_data=self.get_default_cleaned_data()) row = s.row(variants) if row[heading_map['sku']].ctype in (2,3): article_id = str(int(row[heading_map['sku']].value)) else: article_id = str(row[heading_map['sku']].value) data['cleaned_data']['sku'] = article_id data['cleaned_data']['article_id'] = article_id data['cleaned_data']['title'] = row[heading_map['product title']].value data['cleaned_data']['detailed_desc'] = row[heading_map['product description']].value or '--' data['cleaned_data']['brand'] = Brand.objects.get(name = row[heading_map['category 1']].value) data['cleaned_data']['category'] = Category.objects.get(name = row[heading_map['category 3']].value,client=holii_client) data['cleaned_data']['model'] = '' list_price = Decimal(str(row[heading_map['mrp']].value)).quantize(Decimal('1.'), rounding=ROUND_UP) usd_list_price = Decimal(str(row[heading_map['usd']].value)).quantize(Decimal('1.'),rounding=ROUND_UP) offer_price = Decimal(str(row[heading_map['offer price']].value)).quantize(Decimal('1.'),rounding=ROUND_UP) today = datetime.now().day usd_offer_price = usd_list_price data['cleaned_data']['offer_price'] = usd_list_price data['cleaned_data']['shipping_duration']=row[heading_map['shipping duration']].value image_urls = [] stock_status = 'instock' status = 'active' image_path = '/home/apps/tinla/media/holii/images/pd/%s' % (str(int(row[heading_map['image url']].value))) try: listing = os.listdir(image_path) listing = sorted(listing) for infile in listing: if infile != 'Thumbs.db': image_urls.append('http://www.holii.in/media/images/pd/%s/%s' % (str(int(row[heading_map['image url']].value)), infile)) except Exception, e: print e if not image_urls: stock_status = 'notavailable' status = 'deactive' data['cleaned_data']['stock_status'] = stock_status data['cleaned_data']['status'] = status data['cleaned_data']['image_url']= image_urls data['cleaned_data']['availability'] = Availability.objects.get(id=1) data['cleaned_data']['product_type'] = 'variant' data['cleaned_data']['sku_type'] = 'HandBags' if variants == first_row: data['cleaned_data']['is_default_product'] = True else: data['cleaned_data']['is_default_product'] = False data['cleaned_data']['features'] = {'Style' : {'feature_type':'fixed','type':'text','data':row[heading_map['category 2']].value}, 'Dimensions (L x H x W)': {'feature_type':'fixed', 'type':'text', 'data':str(row[heading_map['dimensions']].value)+ ' cms'}} price_lists = [] holii_price_list = None applicable_price_lists = [] try: holii_price_list = PriceList.objects.get(name='world holii') except PriceList.DoesNotExist: holii_price_list = PriceList(name='world holii') holii_price_list.save() applicable_price_lists.append(holii_price_list) if usd_list_price != 0: price_lists.append({ 'price_list':holii_price_list, 'list_price':usd_list_price, 'offer_price':usd_offer_price}) data['cleaned_data']['list_price'] = usd_list_price data['cleaned_data']['usd_list_price'] = usd_list_price data['cleaned_data']['price_lists'] = price_lists data['cleaned_data']['applicable_price_lists'] = applicable_price_lists product_variants.append(data) rows_visited.append(variants) products.append(product_variants)
def parse(self, sync, *args, **kwargs): wb = xlrd.open_workbook("/home/apps/tinla/feeds/data/holii/Holii_Data.xls") count, heading_map = 0, {} s = wb.sheet_by_index(0) try: get_product_type = ProductType.objects.using("default").get(type="HandBags - US") except ProductType.DoesNotExist: get_product_type = ProductType(type="HandBags US") get_product_type.save(using="default") for col in range(s.ncols): heading_map[s.cell(0, col).value.lower()] = col products = [] for row_num in range(1, s.nrows): row = s.row(row_num) brand = row[heading_map["category 1"]].value.strip() parent_category = row[heading_map["category 3"]].value.strip() usholii_client = Client.objects.using("default").get(name="US Holii") try: get_parent_category = Category.objects.using("default").get(name=parent_category, client=usholii_client) except Category.DoesNotExist: get_parent_category = Category( name=parent_category, client=usholii_client, slug=slugify(parent_category) ) get_parent_category.save(using="default") try: get_feature_group = FeatureGroup.objects.using("default").get( category=get_parent_category, product_type=get_product_type ) except FeatureGroup.DoesNotExist: get_feature_group = FeatureGroup( category=get_parent_category, product_type=get_product_type, name=parent_category ) print "get_parent_category ", get_parent_category.id, "get_product_type ", get_product_type.id, "parent_category ", parent_category get_feature_group.save(using="default") try: # this is to create a category with parent = none i.e parent itself is added parent_child_map = CategoryGraph.objects.using("default").get(category=get_parent_category, parent=None) except CategoryGraph.DoesNotExist: parent_child_map = CategoryGraph(category=get_parent_category, parent=None) parent_child_map.save(using="default") try: get_brand = Brand.objects.using("default").get(name=brand) except Brand.DoesNotExist: get_brand = Brand(name=brand, slug=slugify(brand)) get_brand.save(using="default") rows_visited = [] for row_num in range(1, s.nrows): if row_num in rows_visited: continue data = dict(cleaned_data=self.get_default_cleaned_data()) product_variants = [] first_row = row_num temp_row = s.row(row_num) for variants in range(row_num, (row_num + int(temp_row[heading_map["variant"]].value))): data = dict(cleaned_data=self.get_default_cleaned_data()) row = s.row(variants) if row[heading_map["sku"]].ctype in (2, 3): article_id = str(int(row[heading_map["sku"]].value)) else: article_id = str(row[heading_map["sku"]].value) data["cleaned_data"]["sku"] = article_id data["cleaned_data"]["article_id"] = article_id data["cleaned_data"]["title"] = row[heading_map["product title"]].value data["cleaned_data"]["detailed_desc"] = row[heading_map["product description"]].value or "--" data["cleaned_data"]["brand"] = Brand.objects.using("default").get( name=row[heading_map["category 1"]].value ) data["cleaned_data"]["category"] = Category.objects.using("default").get( name=row[heading_map["category 3"]].value, client=usholii_client ) data["cleaned_data"]["model"] = "" usd_list_price = Decimal(str(row[heading_map["usd"]].value)).quantize(Decimal("1."), rounding=ROUND_UP) today = datetime.now().day # considered same offer and list price for US Holii usd_offer_price = usd_list_price data["cleaned_data"]["shipping_duration"] = row[heading_map["shipping duration"]].value image_urls = [] stock_status = "instock" status = "active" image_path = "/home/apps/tinla/media/holii/images/pd/%s" % ( str(int(row[heading_map["image url"]].value)) ) try: listing = os.listdir(image_path) listing = sorted(listing) for infile in listing: if infile != "Thumbs.db": image_urls.append( "http://www.holii.in/media/images/pd/%s/%s" % (str(int(row[heading_map["image url"]].value)), infile) ) except Exception, e: print e # if not image_urls: stock_status = "notavailable" status = "deactive" data["cleaned_data"]["stock_status"] = stock_status data["cleaned_data"]["status"] = status data["cleaned_data"]["image_url"] = image_urls data["cleaned_data"]["availability"] = Availability.objects.using("default").get(id=1) data["cleaned_data"]["product_type"] = "variant" data["cleaned_data"]["sku_type"] = "HandBags US" data["cleaned_data"]["usd"] = usd_list_price if variants == first_row: data["cleaned_data"]["is_default_product"] = True else: data["cleaned_data"]["is_default_product"] = False data["cleaned_data"]["features"] = { "Style": {"feature_type": "fixed", "type": "text", "data": row[heading_map["category 2"]].value}, "Dimensions (L x H x W)": { "feature_type": "fixed", "type": "text", "data": str(row[heading_map["dimensions"]].value) + " cms", }, } # price_lists = [] # holii_price_list = None # applicable_price_lists = [] # try: # usholii_price_list = PriceList.objects.using('default').get(name='us holii') # except PriceList.DoesNotExist: # holii_price_list = PriceList(name='us holii') # holii_price_list.save(using='default') # applicable_price_lists.append(holii_price_list) # if usd_list_price != 0: # price_lists.append({ # 'price_list':holii_price_list, # 'list_price':usd_list_price, # 'offer_price':usd_offer_price}) data["cleaned_data"]["list_price"] = usd_list_price data["cleaned_data"]["offer_price"] = usd_offer_price # data['cleaned_data']['usd_list_price'] = usd_list_price # data['cleaned_data']['price_lists'] = price_lists # data['cleaned_data']['applicable_price_lists'] = applicable_price_lists product_variants.append(data) rows_visited.append(variants) products.append(product_variants)
def parse(self, sync, *args, **kwargs): wb = xlrd.open_workbook('/home/saumil/tinla/feeds/data/fgc/FGC_Data.xls') count,heading_map = 0,{} s = wb.sheet_by_index(0) for col in range(s.ncols): heading_map[s.cell(0,col).value.lower()] = col fgc_client = Client.objects.get(name='Future Gift Cards') # Category try: category = Category.objects.get(name = 'Gift Vouchers', client = fgc_client) except Category.DoesNotExist: category = Category(name = 'Gift Vouchers', client = fgc_client, slug=slugify('Gift Vouchers')) category.save() products, product_variants, rows_visited, flag, first_row = [], [], [], 0, 0 for row_num in range(1,s.nrows): row = s.row(row_num) brand = row[heading_map['brand']].value # Brand try: brand = Brand.objects.get(name = brand) brand.description = row[heading_map['brand description']].value brand.save() except Brand.DoesNotExist: brand = Brand(name = brand, description = row[heading_map['brand description']].value, slug = slugify(brand)) brand.save() if row_num in rows_visited: continue product_variants=[] first_row = row_num temp_row = s.row(row_num) for variants in range(row_num,(row_num+int(temp_row[heading_map['variant']].value))): data = dict(cleaned_data=self.get_default_cleaned_data()) row = s.row(variants) if row[heading_map['skuid']].ctype in (2,3): data['cleaned_data']['sku'] = str(int(row[heading_map['skuid']].value)) else: data['cleaned_data']['sku'] = str(row[heading_map['skuid']].value) data['cleaned_data']['title'] = row[heading_map['title']].value data['cleaned_data']['detailed_desc'] = row[heading_map['description']].value data['cleaned_data']['brand'] = brand data['cleaned_data']['category'] = category data['cleaned_data']['model'] = '' image_path = 'http://dev.futuregiftcards.com:8000/media/images/pd/%s.jpg' data['cleaned_data']['image_url']= [image_path % str(row[heading_map['image name']].value)] data['cleaned_data']['stock_status'] = 'instock' data['cleaned_data']['status'] = 'active' data['cleaned_data']['list_price'] = Decimal(str(row[heading_map['mrp']].value)) data['cleaned_data']['offer_price'] = Decimal(str(row[heading_map['offer price']].value)) data['cleaned_data']['gift_desc'] = row[heading_map['terms & conditions']].value data['cleaned_data']['shipping_duration'] = row[heading_map['delivery time']] data['cleaned_data']['product_type'] = 'variant' data['cleaned_data']['availability'] = Availability.objects.get(id=1) data['cleaned_data']['is_default_product'] = (variants == first_row) and True or False product_variants.append(data) rows_visited.append(variants) products.append(product_variants) return products