Beispiel #1
0
 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
Beispiel #2
0
 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
Beispiel #3
0
 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
Beispiel #4
0
 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
Beispiel #5
0
 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
Beispiel #6
0
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
Beispiel #7
0
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
Beispiel #8
0
    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)
Beispiel #9
0
def filter_items(request, c, items):
    if 'sort' in request.GET:
        request.session['catalog_sort'] = request.GET['sort']
    if 'catalog_sort' in request.session:
        items = items.order_by(request.session['catalog_sort'])
        c['sort'] = request.session['catalog_sort']
    else:
        items = items.order_by('name')
        c['sort'] = 'name'
    
    if 'brand' in request.GET:
        request.session['catalog_brand'] = request.GET['brand']
    if 'catalog_brand' in request.session and request.session['catalog_brand']:
        if Brand.get_by_slug(request.session['catalog_brand']) in c['brands']:
            items = items.filter(brand=Brand.get_by_slug(request.session['catalog_brand']))
            c['brand'] = request.session['catalog_brand']
        else:
            del request.session['catalog_brand']
         
    
    if 'from_price' in request.GET:
        request.session['catalog_from_price'] = request.GET['from_price']
    if 'catalog_from_price' in request.session and request.session['catalog_from_price']:
        items = items.filter(price__gte=int(request.session['catalog_from_price']))
        c['from_price'] = request.session['catalog_from_price']
        
    if 'to_price' in request.GET:
        request.session['catalog_to_price'] = request.GET['to_price']
    if 'catalog_to_price' in request.session and request.session['catalog_to_price']:
        items = items.filter(price__lte=int(request.session['catalog_to_price']))
        c['to_price'] = request.session['catalog_to_price']
        
    if 'season_change' in request.GET:
        request.session['catalog_season'] = request.GET.getlist('season', [])
    if 'catalog_season' in request.session and request.session['catalog_season']:
        items = items.filter(season__in=request.session['catalog_season'])
        c['season'] = request.session['catalog_season']
        
    if 'novelty_sale' in request.GET:
        request.session['catalog_for_sale'] = request.GET.get('for_sale', False)
        request.session['catalog_novelty'] = request.GET.get('novelty', False)
    if 'catalog_for_sale' in request.session and request.session['catalog_for_sale']:
        items = items.exclude(price_old__exact=None)
        c['for_sale'] = True
    if 'catalog_novelty' in request.session and request.session['catalog_novelty']:
        items = items.filter(date__gte=(datetime.datetime.now() - datetime.timedelta(days=7)))
        c['novelty'] = True
    
    if 'color' in request.GET:
        request.session['catalog_color'] = request.GET['color']
    if 'catalog_color' in request.session and request.session['catalog_color']:
        if Color.objects.get(id=int(request.session['catalog_color'])) in c['colors']:
            items = items.filter(color=request.session['catalog_color'])
            c['color'] = int(request.session['catalog_color'])
        else:
            del request.session['catalog_color']
            
        
    if 'material' in request.GET:
        request.session['catalog_material'] = request.GET['material']
    if 'catalog_material' in request.session and request.session['catalog_material']:
        if Material.objects.get(id=int(request.session['catalog_material'])) in c['materials']:
            items = items.filter(material=request.session['catalog_material'])
            c['material'] = int(request.session['catalog_material'])
        else:
            del request.session['catalog_material']
    
    if 'count' in request.GET:
        request.session['catalog_count'] = request.GET['count']
    if 'catalog_count' in request.session:
        c['count'] = request.session['catalog_count']
    else:
        request.session['catalog_count'] = 10
        c['count'] = 10
    
    paginator = Paginator(items, request.session['catalog_count'])
    page = int(request.GET.get('page', '1'))
    try:
        items = paginator.page(page)
    except PageNotAnInteger:
        page = 1
        items = paginator.page(page)
    except EmptyPage:
        page = paginator.num_pages
        items = paginator.page(page)
    c['page'] = page
    c['page_range'] = paginator.page_range
    if len(c['page_range']) > 1:
        c['need_pagination'] = True
    
    c['items'] = items
    return c
Beispiel #10
0
def brand(request, slug):
    c = get_common_context(request)
    c['brand'] = Brand.get_by_slug(slug)
    items = Item.objects.filter(brand=c['brand'])
    return render_to_response('brand.html', filter_items(request, c, items), context_instance=RequestContext(request))
Beispiel #11
0
    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
Beispiel #12
0
    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)
Beispiel #13
0
    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)
Beispiel #14
0
    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