Subversion Repositories SmartDukaan

Rev

Rev 19401 | Rev 19435 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 19401 Rev 19402
Line 2691... Line 2691...
2691
    except:
2691
    except:
2692
        pass
2692
        pass
2693
    return specialOffer
2693
    return specialOffer
2694
 
2694
 
2695
def getBrandSubCategoryInfo(category_id, id_list, type):
2695
def getBrandSubCategoryInfo(category_id, id_list, type):
2696
    
2696
    try:
2697
    id_list_mapping = {}
2697
        id_list_mapping = {}
2698
    if type == "brandInfo":
2698
        if type == "brandInfo":
2699
        brands = [int(brand_id) for brand_id in id_list.split('^')]
2699
            brands = [int(brand_id) for brand_id in id_list.split('^')]
2700
        for brand in brands:
2700
            for brand in brands:
2701
            tm_brand = get_mongo_connection().Catalog.Deals.find_one({'brand_id':brand},{'brand':1})
2701
                tm_brand = get_mongo_connection().Catalog.Deals.find_one({'brand_id':brand},{'brand':1})
2702
            id_list_mapping[brand] = tm_brand.get('brand')
2702
                id_list_mapping[brand] = tm_brand.get('brand')
2703
    elif type == "subCategoryInfo":
2703
        elif type == "subCategoryInfo":
2704
        subCategories = [int(subCategoryId) for subCategoryId in id_list.split('^')]
2704
            subCategories = [int(subCategoryId) for subCategoryId in id_list.split('^')]
2705
        for subCat in subCategories:
2705
            for subCat in subCategories:
2706
            id_list_mapping[subCat] = SUB_CATEGORY_MAP.get(subCat)
2706
                id_list_mapping[subCat] = SUB_CATEGORY_MAP.get(subCat)
2707
    else:
2707
        else:
2708
        return {}
2708
            return {}
2709
    
-
 
2710
    if mc.get("brandSubCategoryInfo") is None:
-
 
2711
        collection =  get_mongo_connection().Catalog.Deals
-
 
2712
        result = collection.aggregate( 
-
 
2713
                [
-
 
2714
                    {'$match':{'category_id':category_id,'showDeal':1}},
-
 
2715
                    {"$group": { "_id": { "subCategoryId": "$subCategoryId", "brand_id": "$brand_id", "brand":"$brand","subCategory":"$subCategory" }, "count": {"$sum": 1} } }
-
 
2716
                ]
-
 
2717
            );
-
 
2718
        #from pprint import pprint
-
 
2719
        #pprint(result)
-
 
2720
        
-
 
2721
        subCategoryMap = {}
-
 
2722
        brandMap = {}
-
 
2723
        
2709
        
2724
        for data in result['result']:
-
 
2725
            result_set = data['_id']
-
 
2726
            count = data['count']
-
 
2727
            subCategoryId = result_set['subCategoryId']
-
 
2728
            brand_id = result_set['brand_id']
2710
        if mc.get("brandSubCategoryInfo") is None:
2729
            subCategory = result_set['subCategory']
2711
            collection =  get_mongo_connection().Catalog.Deals
2730
            brand = result_set['brand']
2712
            result = collection.aggregate( 
2731
             
2713
                    [
2732
            if subCategoryMap.has_key(subCategoryId):
2714
                        {'$match':{'category_id':category_id,'showDeal':1}},
2733
                subCategoryMap.get(subCategoryId).append({'brand_id':brand_id, 'count':count, 'subCategory':subCategory, 'brand':brand})
2715
                        {"$group": { "_id": { "subCategoryId": "$subCategoryId", "brand_id": "$brand_id", "brand":"$brand","subCategory":"$subCategory" }, "count": {"$sum": 1} } }
2734
            else:
2716
                    ]
2735
                subCategoryMap[subCategoryId] = [{'brand_id':brand_id, 'count':count, 'subCategory':subCategory, 'brand':brand}]
-
 
2736
                
2717
                );
2737
            if brandMap.has_key(brand_id):
-
 
2738
                brandMap.get(brand_id).append({'subCategoryId':subCategoryId, 'count':count, 'subCategory':subCategory, 'brand':brand})
-
 
2739
            else:
-
 
2740
                brandMap[brand_id] = [{'subCategoryId':subCategoryId, 'count':count, 'subCategory':subCategory, 'brand':brand}]
-
 
2741
        
-
 
2742
        mc.set("brandSubCategoryInfo",{'subCategoryMap':subCategoryMap, 'brandMap': brandMap}, 600)
-
 
2743
    
-
 
2744
    
-
 
2745
    returnMap = {}    
-
 
2746
    brandSubCategoryInfo = mc.get("brandSubCategoryInfo")
-
 
2747
    if brandSubCategoryInfo is None:
-
 
2748
        return {'idListInfo':id_list_mapping,'result':[]}
-
 
2749
    
-
 
2750
    if type == "subCategoryInfo":
-
 
2751
        if brandSubCategoryInfo.get('subCategoryMap') is None:
-
 
2752
            return {'idListInfo':id_list_mapping,'result':[]}
-
 
2753
        subCategories = [int(subCategoryId) for subCategoryId in id_list.split('^')]
-
 
2754
        subCategoryMap = brandSubCategoryInfo.get('subCategoryMap')
-
 
2755
        for subCategory in subCategories:
-
 
2756
            tempList = subCategoryMap.get(subCategory)
-
 
2757
            print tempList
2718
            #from pprint import pprint
2758
            if tempList is None:
-
 
2759
                continue
-
 
2760
            for v in tempList:
2719
            #pprint(result)
2761
                if returnMap.has_key(v['brand_id']):
-
 
2762
                    existing = returnMap.get(v['brand_id'])
-
 
2763
                    existing['count'] = existing['count'] + v['count'] 
-
 
2764
                else:
-
 
2765
                    returnMap[v['brand_id']] = {'brand_id':v['brand_id'],'brand':v['brand'],'count':v['count']}
-
 
2766
            
2720
            
-
 
2721
            subCategoryMap = {}
-
 
2722
            brandMap = {}
2767
            
2723
            
2768
    elif type == "brandInfo":
2724
            for data in result['result']:
2769
        if brandSubCategoryInfo.get('brandMap') is None:
2725
                result_set = data['_id']
2770
            return {'idListInfo':id_list_mapping,'result':[]}
2726
                count = data['count']
2771
        brands = [int(brand_id) for brand_id in id_list.split('^')]
-
 
2772
        brandMap = brandSubCategoryInfo.get('brandMap')
2727
                subCategoryId = result_set['subCategoryId']
2773
        for brand_id in brands:
2728
                brand_id = result_set['brand_id']
2774
            tempList = brandMap.get(brand_id)
2729
                subCategory = result_set['subCategory']
2775
            print tempList
-
 
2776
            if tempList is None:
2730
                brand = result_set['brand']
2777
                continue
2731
                 
2778
            for v in tempList:
-
 
2779
                if returnMap.has_key(v['subCategoryId']):
2732
                if subCategoryMap.has_key(subCategoryId):
2780
                    existing = returnMap.get(v['subCategoryId'])
2733
                    subCategoryMap.get(subCategoryId).append({'brand_id':brand_id, 'count':count, 'subCategory':subCategory, 'brand':brand})
2781
                    existing['count'] = existing['count'] + v['count'] 
-
 
2782
                else:
2734
                else:
-
 
2735
                    subCategoryMap[subCategoryId] = [{'brand_id':brand_id, 'count':count, 'subCategory':subCategory, 'brand':brand}]
-
 
2736
                    
-
 
2737
                if brandMap.has_key(brand_id):
-
 
2738
                    brandMap.get(brand_id).append({'subCategoryId':subCategoryId, 'count':count, 'subCategory':subCategory, 'brand':brand})
-
 
2739
                else:
-
 
2740
                    brandMap[brand_id] = [{'subCategoryId':subCategoryId, 'count':count, 'subCategory':subCategory, 'brand':brand}]
-
 
2741
            
-
 
2742
            mc.set("brandSubCategoryInfo",{'subCategoryMap':subCategoryMap, 'brandMap': brandMap}, 600)
-
 
2743
        
-
 
2744
        
-
 
2745
        returnMap = {}    
-
 
2746
        brandSubCategoryInfo = mc.get("brandSubCategoryInfo")
-
 
2747
        if brandSubCategoryInfo is None:
-
 
2748
            return {'idListInfo':id_list_mapping,'result':[]}
-
 
2749
        
-
 
2750
        if type == "subCategoryInfo":
-
 
2751
            if brandSubCategoryInfo.get('subCategoryMap') is None:
-
 
2752
                return {'idListInfo':id_list_mapping,'result':[]}
-
 
2753
            subCategories = [int(subCategoryId) for subCategoryId in id_list.split('^')]
-
 
2754
            subCategoryMap = brandSubCategoryInfo.get('subCategoryMap')
-
 
2755
            for subCategory in subCategories:
-
 
2756
                tempList = subCategoryMap.get(subCategory)
-
 
2757
                print tempList
-
 
2758
                if tempList is None:
-
 
2759
                    continue
-
 
2760
                for v in tempList:
-
 
2761
                    if returnMap.has_key(v['brand_id']):
-
 
2762
                        existing = returnMap.get(v['brand_id'])
-
 
2763
                        existing['count'] = existing['count'] + v['count'] 
-
 
2764
                    else:
-
 
2765
                        returnMap[v['brand_id']] = {'brand_id':v['brand_id'],'brand':v['brand'],'count':v['count']}
-
 
2766
                
-
 
2767
                
-
 
2768
        elif type == "brandInfo":
-
 
2769
            if brandSubCategoryInfo.get('brandMap') is None:
-
 
2770
                return {'idListInfo':id_list_mapping,'result':[]}
-
 
2771
            brands = [int(brand_id) for brand_id in id_list.split('^')]
-
 
2772
            brandMap = brandSubCategoryInfo.get('brandMap')
-
 
2773
            for brand_id in brands:
-
 
2774
                tempList = brandMap.get(brand_id)
-
 
2775
                print tempList
-
 
2776
                if tempList is None:
-
 
2777
                    continue
-
 
2778
                for v in tempList:
-
 
2779
                    if returnMap.has_key(v['subCategoryId']):
-
 
2780
                        existing = returnMap.get(v['subCategoryId'])
-
 
2781
                        existing['count'] = existing['count'] + v['count'] 
-
 
2782
                    else:
2783
                    returnMap[v['subCategoryId']] = {'subCategoryId':v['subCategoryId'],'subCategory':v['subCategory'],'count':v['count']}
2783
                        returnMap[v['subCategoryId']] = {'subCategoryId':v['subCategoryId'],'subCategory':v['subCategory'],'count':v['count']}
2784
    
2784
        
2785
    return {'idListInfo':id_list_mapping,'result':returnMap.values()}
2785
        return {'idListInfo':id_list_mapping,'result':returnMap.values()}
-
 
2786
    except:
-
 
2787
        traceback.print_exc()
-
 
2788
        return {}
2786
 
2789
 
2787
            
2790
            
2788
def main():
2791
def main():
2789
    #getDealsForSearchText("20", 'Samsung', 0, 10)
2792
    #getDealsForSearchText("20", 'Samsung', 0, 10)
2790
   
2793