Subversion Repositories SmartDukaan

Rev

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

Rev 19390 Rev 19397
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
    
-
 
2697
    id_list_mapping = {}
-
 
2698
    if type == "subCategoryInfo":
-
 
2699
        brands = [int(brand_id) for brand_id in id_list.split('^')]
-
 
2700
        for brand in brands:
-
 
2701
            tm_brand = get_mongo_connection().Catalog.Deals.find_one({'brand_id':brand},{'brand':1})
-
 
2702
            id_list_mapping[brand_id] = tm_brand.get('brand')
-
 
2703
    elif type == "brandInfo":
-
 
2704
        subCategories = [int(subCategoryId) for subCategoryId in id_list.split('^')]
-
 
2705
        for subCat in subCategories:
-
 
2706
            id_list_mapping[subCat] = SUB_CATEGORY_MAP.get(subCat)
-
 
2707
    else:
-
 
2708
        return {}
-
 
2709
    
2696
    if mc.get("brandSubCategoryInfo") is None:
2710
    if mc.get("brandSubCategoryInfo") is None:
2697
        collection =  get_mongo_connection().Catalog.Deals
2711
        collection =  get_mongo_connection().Catalog.Deals
2698
        result = collection.aggregate( 
2712
        result = collection.aggregate( 
2699
                [
2713
                [
2700
                    {'$match':{'category_id':category_id,'showDeal':1}},
2714
                    {'$match':{'category_id':category_id,'showDeal':1}},
2701
                    {"$group": { "_id": { "subCategoryId": "$subCategoryId", "brand_id": "$brand_id", "brand":"$brand","subCategory":"$subCategory" }, "count": {"$sum": 1} } }
2715
                    {"$group": { "_id": { "subCategoryId": "$subCategoryId", "brand_id": "$brand_id", "brand":"$brand","subCategory":"$subCategory" }, "count": {"$sum": 1} } }
2702
                ]
2716
                ]
2703
            );
2717
            );
2704
        from pprint import pprint
2718
        #from pprint import pprint
2705
        pprint(result)
2719
        #pprint(result)
2706
        
2720
        
2707
        subCategoryMap = {}
2721
        subCategoryMap = {}
2708
        brandMap = {}
2722
        brandMap = {}
2709
        
2723
        
2710
        for data in result['result']:
2724
        for data in result['result']:
Line 2729... Line 2743...
2729
    
2743
    
2730
    
2744
    
2731
    returnMap = {}    
2745
    returnMap = {}    
2732
    brandSubCategoryInfo = mc.get("brandSubCategoryInfo")
2746
    brandSubCategoryInfo = mc.get("brandSubCategoryInfo")
2733
    if brandSubCategoryInfo is None:
2747
    if brandSubCategoryInfo is None:
2734
        return []
2748
        return {'idListInfo':id_list_mapping,'result':[]}
2735
    
2749
    
2736
    if type == "subCategoryInfo":
2750
    if type == "subCategoryInfo":
2737
        if brandSubCategoryInfo.get('subCategoryMap') is None:
2751
        if brandSubCategoryInfo.get('subCategoryMap') is None:
2738
            return []
2752
            return {'idListInfo':id_list_mapping,'result':[]}
2739
        subCategories = [int(subCategoryId) for subCategoryId in id_list.split('^')]
2753
        subCategories = [int(subCategoryId) for subCategoryId in id_list.split('^')]
2740
        subCategoryMap = brandSubCategoryInfo.get('subCategoryMap')
2754
        subCategoryMap = brandSubCategoryInfo.get('subCategoryMap')
2741
        for subCategory in subCategories:
2755
        for subCategory in subCategories:
2742
            tempList = subCategoryMap.get(subCategory)
2756
            tempList = subCategoryMap.get(subCategory)
2743
            print tempList
2757
            print tempList
Line 2751... Line 2765...
2751
                    returnMap[v['brand_id']] = {'brand_id':v['brand_id'],'brand':v['brand'],'count':v['count']}
2765
                    returnMap[v['brand_id']] = {'brand_id':v['brand_id'],'brand':v['brand'],'count':v['count']}
2752
            
2766
            
2753
            
2767
            
2754
    elif type == "brandInfo":
2768
    elif type == "brandInfo":
2755
        if brandSubCategoryInfo.get('brandMap') is None:
2769
        if brandSubCategoryInfo.get('brandMap') is None:
2756
            return []
2770
            return {'idListInfo':id_list_mapping,'result':[]}
2757
        brands = [int(brand_id) for brand_id in id_list.split('^')]
2771
        brands = [int(brand_id) for brand_id in id_list.split('^')]
2758
        brandMap = brandSubCategoryInfo.get('brandMap')
2772
        brandMap = brandSubCategoryInfo.get('brandMap')
2759
        for brand_id in brands:
2773
        for brand_id in brands:
2760
            tempList = brandMap.get(brand_id)
2774
            tempList = brandMap.get(brand_id)
2761
            print tempList
2775
            print tempList
Line 2766... Line 2780...
2766
                    existing = returnMap.get(v['subCategoryId'])
2780
                    existing = returnMap.get(v['subCategoryId'])
2767
                    existing['count'] = existing['count'] + v['count'] 
2781
                    existing['count'] = existing['count'] + v['count'] 
2768
                else:
2782
                else:
2769
                    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']}
2770
    
2784
    
2771
    return returnMap.values()
2785
    return {'idListInfo':id_list_mapping,'result':returnMap.values()}
2772
 
2786
 
2773
            
2787
            
2774
def main():
2788
def main():
2775
    #getDealsForSearchText("20", 'Samsung', 0, 10)
2789
    #getDealsForSearchText("20", 'Samsung', 0, 10)
2776
   
2790