| Line 359... |
Line 359... |
| 359 |
temp.append(temp_map)
|
359 |
temp.append(temp_map)
|
| 360 |
brandPrefMap[(x.brand).strip().upper()] = temp
|
360 |
brandPrefMap[(x.brand).strip().upper()] = temp
|
| 361 |
|
361 |
|
| 362 |
for x in session.query(user_actions).filter_by(user_id=userId).all():
|
362 |
for x in session.query(user_actions).filter_by(user_id=userId).all():
|
| 363 |
actionsMap[x.store_product_id] = 1 if x.action == 'like' else 0
|
363 |
actionsMap[x.store_product_id] = 1 if x.action == 'like' else 0
|
| 364 |
all_deals = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query},{'_id':1,'category_id':1,'brand':1,'totalPoints':1,'bestSellerPoints':1,'nlcPoints':1,'rank':1,'available_price':1,'dealType':1,'source_id':1}).sort([('totalPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING),('nlcPoints',pymongo.DESCENDING),('rank',pymongo.DESCENDING)]))
|
364 |
all_deals = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query},{'_id':1,'category_id':1,'brand':1,'totalPoints':1,'bestSellerPoints':1,'nlcPoints':1,'rank':1,'available_price':1,'dealType':1,'source_id':1,'brand_id':1}).sort([('totalPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING),('nlcPoints',pymongo.DESCENDING),('rank',pymongo.DESCENDING)]))
|
| 365 |
all_category_deals = []
|
365 |
all_category_deals = []
|
| 366 |
mobile_deals = []
|
366 |
mobile_deals = []
|
| 367 |
tablet_deals = []
|
367 |
tablet_deals = []
|
| 368 |
for deal in all_deals:
|
368 |
for deal in all_deals:
|
| 369 |
if actionsMap.get(deal['_id']) == 0:
|
369 |
if actionsMap.get(deal['_id']) == 0:
|
| Line 473... |
Line 473... |
| 473 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
|
473 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
|
| 474 |
if not dealsMap.has_key(item[0]['identifier']):
|
474 |
if not dealsMap.has_key(item[0]['identifier']):
|
| 475 |
item[0]['dealRank'] = rank
|
475 |
item[0]['dealRank'] = rank
|
| 476 |
item[0]['persPoints'] = d['persPoints']
|
476 |
item[0]['persPoints'] = d['persPoints']
|
| 477 |
if d['dealType'] == 1 and d['source_id'] ==1:
|
477 |
if d['dealType'] == 1 and d['source_id'] ==1:
|
| 478 |
item[0]['marketPlaceUrl'] = "http://www.amazon.in/dp/%s"%(item[0]['identifier'].strip())
|
478 |
item[0]['marketPlaceUrl'] = "http://www.amazon.in/dp/%s"%(item[0]['identifier'].strip())
|
| - |
|
479 |
elif d['source_id'] ==3:
|
| - |
|
480 |
item[0]['marketPlaceUrl'] = item[0]['marketPlaceUrl']+'?supc='+item[0].get('identifier')
|
| - |
|
481 |
else:
|
| - |
|
482 |
pass
|
| 479 |
try:
|
483 |
try:
|
| 480 |
cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
|
484 |
cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
|
| 481 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
485 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
| 482 |
item[0]['cash_back_type'] = 0
|
486 |
item[0]['cash_back_type'] = 0
|
| 483 |
item[0]['cash_back'] = 0
|
487 |
item[0]['cash_back'] = 0
|
| Line 521... |
Line 525... |
| 521 |
if len(toFilter) == 0 or (len(toFilter)==1 and toFilter[0]==''):
|
525 |
if len(toFilter) == 0 or (len(toFilter)==1 and toFilter[0]==''):
|
| 522 |
brandsFiltered = deals
|
526 |
brandsFiltered = deals
|
| 523 |
for deal in deals:
|
527 |
for deal in deals:
|
| 524 |
if str(deal['brand_id']) in toFilter:
|
528 |
if str(deal['brand_id']) in toFilter:
|
| 525 |
brandsFiltered.append(deal)
|
529 |
brandsFiltered.append(deal)
|
| - |
|
530 |
if len(dealFiltered) == 0:
|
| - |
|
531 |
return brandsFiltered
|
| 526 |
return [i for i in dealFiltered for j in brandsFiltered if i['_id']==j['_id']]
|
532 |
return [i for i in dealFiltered for j in brandsFiltered if i['_id']==j['_id']]
|
| 527 |
|
533 |
|
| 528 |
|
534 |
|
| 529 |
def getDeals(userId, category_id, offset, limit, sort, direction):
|
535 |
def getDeals(userId, category_id, offset, limit, sort, direction):
|
| 530 |
if not bool(mc.get("category_cash_back")):
|
536 |
if not bool(mc.get("category_cash_back")):
|
| Line 1064... |
Line 1070... |
| 1064 |
|
1070 |
|
| 1065 |
def getBrandsForFilter(category_id):
|
1071 |
def getBrandsForFilter(category_id):
|
| 1066 |
if mc.get("brandFilter") is None:
|
1072 |
if mc.get("brandFilter") is None:
|
| 1067 |
tabData, mobData = [], []
|
1073 |
tabData, mobData = [], []
|
| 1068 |
mobileDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
1074 |
mobileDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
| 1069 |
{"$match":{"category_id":3,"showDeal":1}
|
1075 |
{"$match":{"category_id":3,"showDeal":1,"totalPoints":{"$gt":0}}
|
| 1070 |
},
|
1076 |
},
|
| 1071 |
{"$group" :
|
1077 |
{"$group" :
|
| 1072 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
1078 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
| 1073 |
}
|
1079 |
}
|
| 1074 |
])
|
1080 |
])
|
| 1075 |
|
1081 |
|
| 1076 |
tabletDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
1082 |
tabletDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
| 1077 |
{"$match":{"category_id":5,"showDeal":1}
|
1083 |
{"$match":{"category_id":5,"showDeal":1,"totalPoints":{"$gt":0}}
|
| 1078 |
},
|
1084 |
},
|
| 1079 |
{"$group" :
|
1085 |
{"$group" :
|
| 1080 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
1086 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
| 1081 |
}
|
1087 |
}
|
| 1082 |
])
|
1088 |
])
|
| 1083 |
|
1089 |
|
| 1084 |
allDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
1090 |
allDeals = get_mongo_connection().Catalog.Deals.aggregate([
|
| 1085 |
{"$match":{"showDeal":1}
|
1091 |
{"$match":{"showDeal":1,"totalPoints":{"$gt":0}}
|
| 1086 |
},
|
1092 |
},
|
| 1087 |
{"$group" :
|
1093 |
{"$group" :
|
| 1088 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
1094 |
{'_id':{'brand_id':'$brand_id','brand':'$brand'},'count':{'$sum':1}}
|
| 1089 |
}
|
1095 |
}
|
| 1090 |
])
|
1096 |
])
|
| Line 1126... |
Line 1132... |
| 1126 |
temp.append(allDeal.get('_id').get('brand_id'))
|
1132 |
temp.append(allDeal.get('_id').get('brand_id'))
|
| 1127 |
brandMap[allDeal.get('_id').get('brand')] = {'brand_ids':temp,'count':allDeal.get('count')}
|
1133 |
brandMap[allDeal.get('_id').get('brand')] = {'brand_ids':temp,'count':allDeal.get('count')}
|
| 1128 |
|
1134 |
|
| 1129 |
mc.set("brandFilter",{0:brandMap, 3:mobData, 5:tabData}, 600)
|
1135 |
mc.set("brandFilter",{0:brandMap, 3:mobData, 5:tabData}, 600)
|
| 1130 |
|
1136 |
|
| 1131 |
return mc.get("brandFilter").get(category_id)
|
1137 |
return sorted(mc.get("brandFilter").get(category_id), key = lambda x: (x['count']),reverse=True)
|
| 1132 |
|
- |
|
| 1133 |
|
- |
|
| 1134 |
|
- |
|
| 1135 |
|
1138 |
|
| 1136 |
def main():
|
1139 |
def main():
|
| 1137 |
print (getBrandsForFilter(0))
|
1140 |
print (getBrandsForFilter(0))
|
| 1138 |
|
1141 |
|
| 1139 |
|
1142 |
|