| Line 365... |
Line 365... |
| 365 |
def __constructDummyDealObject(skuBundleId):
|
365 |
def __constructDummyDealObject(skuBundleId):
|
| 366 |
temp =[]
|
366 |
temp =[]
|
| 367 |
deals = get_mongo_connection().Catalog.Deals.find({"skuBundleId":skuBundleId,"$or":[{"showDeal":1}, {"prepaidDeal":1}]},{'_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,'skuBundleId':1,'dp':1, 'showDp':1, 'gross_price':1,'subCategoryId':1,'netPriceAfterCashBack':1})
|
367 |
deals = get_mongo_connection().Catalog.Deals.find({"skuBundleId":skuBundleId,"$or":[{"showDeal":1}, {"prepaidDeal":1}]},{'_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,'skuBundleId':1,'dp':1, 'showDp':1, 'gross_price':1,'subCategoryId':1,'netPriceAfterCashBack':1})
|
| 368 |
for d in deals:
|
368 |
for d in deals:
|
| 369 |
d['persPoints'] = 0
|
369 |
d['persPoints'] = 0
|
| - |
|
370 |
d['internalRank'] = 999999
|
| 370 |
temp.append(d)
|
371 |
temp.append(d)
|
| 371 |
return temp
|
372 |
return temp
|
| 372 |
|
373 |
|
| 373 |
|
374 |
|
| 374 |
|
375 |
|
| Line 380... |
Line 381... |
| 380 |
|
381 |
|
| 381 |
except Exception as e:
|
382 |
except Exception as e:
|
| 382 |
print traceback.print_exc()
|
383 |
print traceback.print_exc()
|
| 383 |
featuredDeals = {3:{},5:{},6:{}}
|
384 |
featuredDeals = {3:{},5:{},6:{}}
|
| 384 |
|
385 |
|
| - |
|
386 |
|
| - |
|
387 |
#Not taking into account accessories
|
| - |
|
388 |
featuredDeals.pop(6,None)
|
| - |
|
389 |
|
| 385 |
fd_bundles = []
|
390 |
fd_bundles = []
|
| 386 |
|
391 |
|
| 387 |
for catMap in featuredDeals.itervalues():
|
392 |
for catMap in featuredDeals.itervalues():
|
| 388 |
for fd_map in catMap.itervalues():
|
393 |
for fd_map in catMap.itervalues():
|
| 389 |
if not fd_map.get('skuBundleId') in fd_bundles:
|
394 |
if not fd_map.get('skuBundleId') in fd_bundles:
|
| Line 393... |
Line 398... |
| 393 |
outer_query = []
|
398 |
outer_query = []
|
| 394 |
outer_query.append({ "$or": [ { "showDeal": 1} , { "prepaidDeal": 1 } ] })
|
399 |
outer_query.append({ "$or": [ { "showDeal": 1} , { "prepaidDeal": 1 } ] })
|
| 395 |
query = {}
|
400 |
query = {}
|
| 396 |
query['$gt'] = -100
|
401 |
query['$gt'] = -100
|
| 397 |
outer_query.append({'totalPoints':query})
|
402 |
outer_query.append({'totalPoints':query})
|
| - |
|
403 |
outer_query.append({'category_id':{"$in":[3,5]}})
|
| 398 |
brandPrefMap = {}
|
404 |
brandPrefMap = {}
|
| 399 |
pricePrefMap = {}
|
405 |
pricePrefMap = {}
|
| 400 |
actionsMap = {}
|
406 |
actionsMap = {}
|
| 401 |
brand_p = session.query(price_preferences).filter_by(user_id=userId).all()
|
407 |
brand_p = session.query(price_preferences).filter_by(user_id=userId).all()
|
| 402 |
for x in brand_p:
|
408 |
for x in brand_p:
|
| Line 416... |
Line 422... |
| 416 |
for x in session.query(user_actions).filter_by(user_id=userId).all():
|
422 |
for x in session.query(user_actions).filter_by(user_id=userId).all():
|
| 417 |
actionsMap[x.store_product_id] = 1 if x.action == 'like' else 0
|
423 |
actionsMap[x.store_product_id] = 1 if x.action == 'like' else 0
|
| 418 |
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,'skuBundleId':1,'dp':1, 'showDp':1, 'gross_price':1, 'subCategoryId':1,'netPriceAfterCashBack':1}).sort([('totalPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING),('nlcPoints',pymongo.DESCENDING),('rank',pymongo.DESCENDING)]))
|
424 |
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,'skuBundleId':1,'dp':1, 'showDp':1, 'gross_price':1, 'subCategoryId':1,'netPriceAfterCashBack':1}).sort([('totalPoints',pymongo.DESCENDING),('bestSellerPoints',pymongo.DESCENDING),('nlcPoints',pymongo.DESCENDING),('rank',pymongo.DESCENDING)]))
|
| 419 |
mobile_deals = []
|
425 |
mobile_deals = []
|
| 420 |
tablet_deals = []
|
426 |
tablet_deals = []
|
| 421 |
accessories_deals = []
|
427 |
#accessories_deals = []
|
| 422 |
for deal in all_deals:
|
428 |
for deal in all_deals:
|
| 423 |
|
429 |
|
| 424 |
try:
|
430 |
try:
|
| 425 |
fd_bundles.remove(deal.get('skuBundleId'))
|
431 |
fd_bundles.remove(deal.get('skuBundleId'))
|
| 426 |
except:
|
432 |
except:
|
| Line 459... |
Line 465... |
| 459 |
|
465 |
|
| 460 |
if deal['category_id'] ==3:
|
466 |
if deal['category_id'] ==3:
|
| 461 |
mobile_deals.append(deal)
|
467 |
mobile_deals.append(deal)
|
| 462 |
elif deal['category_id'] ==5:
|
468 |
elif deal['category_id'] ==5:
|
| 463 |
tablet_deals.append(deal)
|
469 |
tablet_deals.append(deal)
|
| 464 |
elif deal['category_id'] ==6:
|
470 |
#elif deal['category_id'] ==6:
|
| 465 |
accessories_deals.append(deal)
|
471 |
# accessories_deals.append(deal)
|
| 466 |
else:
|
472 |
else:
|
| 467 |
continue
|
473 |
continue
|
| 468 |
|
474 |
|
| 469 |
session.close()
|
475 |
session.close()
|
| 470 |
|
476 |
|
| 471 |
mobile_deals = sorted(mobile_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
477 |
mobile_deals = sorted(mobile_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
| 472 |
tablet_deals = sorted(tablet_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
478 |
tablet_deals = sorted(tablet_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
| 473 |
accessories_deals = sorted(accessories_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
479 |
#accessories_deals = sorted(accessories_deals, key = lambda x: (x['persPoints'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints'], x['rank']),reverse=True)
|
| 474 |
|
480 |
|
| 475 |
|
481 |
|
| 476 |
if len(fd_bundles) > 0:
|
482 |
if len(fd_bundles) > 0:
|
| 477 |
print "There is still bundle in feature deals with points less than -100.Lets add info"
|
483 |
print "There is still bundle in feature deals with points less than -100.Lets add info"
|
| 478 |
for skuBundleId in fd_bundles:
|
484 |
for skuBundleId in fd_bundles:
|
| Line 480... |
Line 486... |
| 480 |
for dummyDealObj in dummyDealObjList:
|
486 |
for dummyDealObj in dummyDealObjList:
|
| 481 |
if dummyDealObj['category_id'] ==3:
|
487 |
if dummyDealObj['category_id'] ==3:
|
| 482 |
mobile_deals.append(dummyDealObj)
|
488 |
mobile_deals.append(dummyDealObj)
|
| 483 |
elif dummyDealObj['category_id'] ==5:
|
489 |
elif dummyDealObj['category_id'] ==5:
|
| 484 |
tablet_deals.append(dummyDealObj)
|
490 |
tablet_deals.append(dummyDealObj)
|
| 485 |
elif dummyDealObj['category_id'] ==6:
|
491 |
#elif dummyDealObj['category_id'] ==6:
|
| 486 |
accessories_deals.append(dummyDealObj)
|
492 |
# accessories_deals.append(dummyDealObj)
|
| 487 |
else:
|
493 |
else:
|
| 488 |
pass
|
494 |
pass
|
| 489 |
|
495 |
|
| 490 |
for super_category, categoryFeaturedDeals in featuredDeals.iteritems():
|
496 |
for super_category, categoryFeaturedDeals in featuredDeals.iteritems():
|
| 491 |
for val in categoryFeaturedDeals.itervalues():
|
497 |
for val in categoryFeaturedDeals.itervalues():
|
| Line 496... |
Line 502... |
| 496 |
|
502 |
|
| 497 |
if super_category ==3:
|
503 |
if super_category ==3:
|
| 498 |
mobile_deals.append(dummyDealObj)
|
504 |
mobile_deals.append(dummyDealObj)
|
| 499 |
elif super_category ==5:
|
505 |
elif super_category ==5:
|
| 500 |
tablet_deals.append(dummyDealObj)
|
506 |
tablet_deals.append(dummyDealObj)
|
| 501 |
elif super_category ==6:
|
507 |
#elif super_category ==6:
|
| 502 |
accessories_deals.append(dummyDealObj)
|
508 |
# accessories_deals.append(dummyDealObj)
|
| 503 |
else:
|
509 |
else:
|
| 504 |
pass
|
510 |
pass
|
| 505 |
|
511 |
|
| 506 |
sortedMapMobiles = {}
|
512 |
sortedMapMobiles = {}
|
| 507 |
rankMapMobiles = {}
|
513 |
rankMapMobiles = {}
|
| Line 590... |
Line 596... |
| 590 |
for rank in blockedRanksTablets:
|
596 |
for rank in blockedRanksTablets:
|
| 591 |
if blockedInfoTablets.get((featuredDealsTablets.get(rank+1)).get('skuBundleId')) is not None:
|
597 |
if blockedInfoTablets.get((featuredDealsTablets.get(rank+1)).get('skuBundleId')) is not None:
|
| 592 |
rankMapTablets[rank] = blockedInfoTablets.get((featuredDealsTablets.get(rank+1)).get('skuBundleId'))
|
598 |
rankMapTablets[rank] = blockedInfoTablets.get((featuredDealsTablets.get(rank+1)).get('skuBundleId'))
|
| 593 |
|
599 |
|
| 594 |
|
600 |
|
| - |
|
601 |
# sortedMapAccessories = {}
|
| - |
|
602 |
# rankMapAccessories = {}
|
| - |
|
603 |
# rankAccessories = 0
|
| - |
|
604 |
#
|
| - |
|
605 |
# blockedRanksAccessories = []
|
| - |
|
606 |
# blockedSkuBundlesAccessories = []
|
| - |
|
607 |
# blockedInfoAccessories = {}
|
| - |
|
608 |
#
|
| - |
|
609 |
# featuredDealsAccessories = featuredDeals.get(6)
|
| - |
|
610 |
#
|
| - |
|
611 |
# for k, v in featuredDealsAccessories.iteritems():
|
| - |
|
612 |
# blockedRanksAccessories.append(k-1)
|
| - |
|
613 |
# blockedSkuBundlesAccessories.append(v.get('skuBundleId'))
|
| - |
|
614 |
#
|
| - |
|
615 |
#
|
| - |
|
616 |
# for sorted_deal in accessories_deals:
|
| - |
|
617 |
#
|
| - |
|
618 |
# while(True):
|
| - |
|
619 |
# if rankAccessories in blockedRanksAccessories:
|
| - |
|
620 |
# rankAccessories = rankAccessories +1
|
| - |
|
621 |
# else:
|
| - |
|
622 |
# break
|
| - |
|
623 |
#
|
| - |
|
624 |
# if sorted_deal['skuBundleId'] in blockedSkuBundlesAccessories:
|
| - |
|
625 |
# if blockedInfoAccessories.has_key(sorted_deal['skuBundleId']):
|
| - |
|
626 |
# blockedInfoAccessories.get(sorted_deal['skuBundleId']).append(sorted_deal)
|
| - |
|
627 |
# else:
|
| - |
|
628 |
# blockedInfoAccessories[sorted_deal['skuBundleId']] = [sorted_deal]
|
| - |
|
629 |
# continue
|
| - |
|
630 |
#
|
| - |
|
631 |
# if sortedMapAccessories.get(sorted_deal['skuBundleId']) is None:
|
| - |
|
632 |
# sortedMapAccessories[sorted_deal['skuBundleId']] = {rankAccessories:[sorted_deal]}
|
| - |
|
633 |
# rankMapAccessories[rankAccessories] = (sortedMapAccessories[sorted_deal['skuBundleId']].values())[0]
|
| - |
|
634 |
# rankAccessories = rankAccessories +1
|
| - |
|
635 |
# else:
|
| - |
|
636 |
# for temp_list in sortedMapAccessories.get(sorted_deal['skuBundleId']).itervalues():
|
| - |
|
637 |
# temp_list.append(sorted_deal)
|
| - |
|
638 |
# rankMapAccessories[(sortedMapAccessories.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
| - |
|
639 |
#
|
| - |
|
640 |
#
|
| - |
|
641 |
# for rank in blockedRanksAccessories:
|
| - |
|
642 |
# if blockedInfoAccessories.get((featuredDealsAccessories.get(rank+1)).get('skuBundleId')) is not None:
|
| - |
|
643 |
# rankMapAccessories[rank] = blockedInfoAccessories.get((featuredDealsAccessories.get(rank+1)).get('skuBundleId'))
|
| - |
|
644 |
#
|
| - |
|
645 |
specialOffer = None
|
| - |
|
646 |
promoOffer = get_mongo_connection().Catalog.PromoOffer.find_one({'user_id':userId})
|
| - |
|
647 |
try:
|
| - |
|
648 |
if promoOffer is not None:
|
| - |
|
649 |
offer = get_mongo_connection().Catalog.Promotions.find_one({'_id':promoOffer.get('offer_id')})
|
| - |
|
650 |
if offer is None:
|
| - |
|
651 |
raise
|
| - |
|
652 |
promo = Promotion(offer.get('_id'),offer.get('offer_name'),offer.get('offer_description') , offer.get('categories_applicable'), offer.get('sub_categories_not_applicable'),
|
| - |
|
653 |
offer.get('startDate'), offer.get('endDate'), promoOffer.get('target1'), promoOffer.get('target1_cash_back_percetage'), promoOffer.get('target2'), promoOffer.get('target2_cash_back_percetage'), promoOffer.get('maxCashBack'),offer.get('url'),
|
| - |
|
654 |
promoOffer.get('pending_order_value'), promoOffer.get('delivered_order_value'), promoOffer.get('last_run_timestamp'))
|
| - |
|
655 |
|
| - |
|
656 |
specialOffer = promo
|
| - |
|
657 |
except:
|
| - |
|
658 |
traceback.print_exc()
|
| - |
|
659 |
|
| - |
|
660 |
|
| - |
|
661 |
mem_cache_val = {3:mobile_deals, 5:tablet_deals,"3_rankMap": rankMapMobiles,"5_rankMap": rankMapTablets, "specialOffer":specialOffer }
|
| - |
|
662 |
mc.set(str(userId), mem_cache_val)
|
| - |
|
663 |
|
| - |
|
664 |
def __populateCacheForAccessories(userId):
|
| - |
|
665 |
try:
|
| - |
|
666 |
if mc.get("featured_deals") is None:
|
| - |
|
667 |
__populateFeaturedDeals()
|
| - |
|
668 |
featuredDeals = mc.get("featured_deals")
|
| - |
|
669 |
|
| - |
|
670 |
except Exception as e:
|
| - |
|
671 |
print traceback.print_exc()
|
| - |
|
672 |
featuredDeals = {3:{},5:{},6:{}}
|
| - |
|
673 |
|
| - |
|
674 |
|
| - |
|
675 |
#Not taking into account mobiles, tablets
|
| - |
|
676 |
featuredDeals.pop(3,None)
|
| - |
|
677 |
featuredDeals.pop(5,None)
|
| - |
|
678 |
|
| - |
|
679 |
fd_bundles = []
|
| - |
|
680 |
|
| - |
|
681 |
for catMap in featuredDeals.itervalues():
|
| - |
|
682 |
for fd_map in catMap.itervalues():
|
| - |
|
683 |
if not fd_map.get('skuBundleId') in fd_bundles:
|
| - |
|
684 |
fd_bundles.append(fd_map.get('skuBundleId'))
|
| - |
|
685 |
|
| - |
|
686 |
print "Populating accessory memcache for userId",userId
|
| - |
|
687 |
outer_query = []
|
| - |
|
688 |
outer_query.append({ "$or": [ { "showDeal": 1} , { "prepaidDeal": 1 } ] })
|
| - |
|
689 |
query = {}
|
| - |
|
690 |
query['$gte'] = 0
|
| - |
|
691 |
outer_query.append({'internalRank':query})
|
| - |
|
692 |
outer_query.append({'category_id':{"$in":[6]}})
|
| - |
|
693 |
|
| - |
|
694 |
accessories_deals = list(get_mongo_connection().Catalog.Deals.find({"$and":outer_query},{'_id':1,'category_id':1,'brand':1,'bestSellerPoints':1,'nlcPoints':1,'totalPoints':1,'internalRank':1,'available_price':1,'dealType':1,'source_id':1,'brand_id':1,'skuBundleId':1,'dp':1, 'showDp':1, 'gross_price':1, 'subCategoryId':1,'netPriceAfterCashBack':1}).sort([('internalRank',pymongo.ASCENDING),('bestSellerPoints',pymongo.DESCENDING)]))
|
| - |
|
695 |
|
| - |
|
696 |
actionsMap = {}
|
| - |
|
697 |
|
| - |
|
698 |
actionRank = 3
|
| - |
|
699 |
for x in session.query(user_actions).filter_by(user_id=userId).order_by(asc(user_actions.created)).all():
|
| - |
|
700 |
#actionsMap[x.store_product_id] = 1 if x.action == 'like' else 0
|
| - |
|
701 |
action = 1 if x.action == 'like' else 0
|
| - |
|
702 |
if action==1:
|
| - |
|
703 |
actionsMap[x.store_product_id] = {'action':action,'rank':actionRank}
|
| - |
|
704 |
actionRank = actionRank+3
|
| - |
|
705 |
else:
|
| - |
|
706 |
actionsMap[x.store_product_id] = {'action':action,'rank':None}
|
| - |
|
707 |
|
| - |
|
708 |
session.close()
|
| - |
|
709 |
|
| - |
|
710 |
psuedo_count = 1
|
| - |
|
711 |
|
| - |
|
712 |
if actionsMap:
|
| - |
|
713 |
for k,v in actionsMap.iteritems():
|
| - |
|
714 |
if v['action'] == 0:
|
| - |
|
715 |
tmp_deal = get_mongo_connection().Catalog.Deals.find_one({'_id':k})
|
| - |
|
716 |
if tmp_deal is None:
|
| - |
|
717 |
v['rank'] = 999999
|
| - |
|
718 |
continue
|
| - |
|
719 |
max_rank = list(get_mongo_connection().Catalog.Deals.find({'subCategoryId':tmp_deal.get('subCategoryId')}).sort([('internalRank',pymongo.DESCENDING)]).limit(1))
|
| - |
|
720 |
if len(max_rank) == 0 or max_rank[0].get('internalRank') is None:
|
| - |
|
721 |
v['rank'] = 999999
|
| - |
|
722 |
continue
|
| - |
|
723 |
v['rank'] = max_rank[0]['internalRank'] + 1
|
| - |
|
724 |
|
| - |
|
725 |
for deal in accessories_deals:
|
| - |
|
726 |
|
| - |
|
727 |
try:
|
| - |
|
728 |
fd_bundles.remove(deal.get('skuBundleId'))
|
| - |
|
729 |
except:
|
| - |
|
730 |
pass
|
| - |
|
731 |
if actionsMap and actionsMap.get(deal['_id'])!=None:
|
| - |
|
732 |
if actionsMap.get(deal['_id']).get('action') ==1:
|
| - |
|
733 |
actionRank = actionsMap.get(deal['_id']).get('rank')
|
| - |
|
734 |
if actionRank < psuedo_count:
|
| - |
|
735 |
deal['internalRank'] = actionRank
|
| - |
|
736 |
|
| - |
|
737 |
elif actionsMap.get(deal['_id']).get('action') ==0:
|
| - |
|
738 |
actionRank = actionsMap.get(deal['_id']).get('rank')
|
| - |
|
739 |
deal['internalRank'] = actionRank
|
| - |
|
740 |
else:
|
| - |
|
741 |
pass
|
| - |
|
742 |
psuedo_count = psuedo_count+1
|
| - |
|
743 |
|
| - |
|
744 |
if actionsMap:
|
| - |
|
745 |
accessories_deals = sorted(accessories_deals, key = lambda x: (-x['internalRank'],x['totalPoints'],x['bestSellerPoints'], x['nlcPoints']),reverse=True)
|
| - |
|
746 |
|
| - |
|
747 |
if len(fd_bundles) > 0:
|
| - |
|
748 |
print "There is still bundle in feature deals.Lets add info"
|
| - |
|
749 |
for skuBundleId in fd_bundles:
|
| - |
|
750 |
dummyDealObjList = __constructDummyDealObject(skuBundleId)
|
| - |
|
751 |
for dummyDealObj in dummyDealObjList:
|
| - |
|
752 |
if dummyDealObj['category_id'] ==6:
|
| - |
|
753 |
accessories_deals.append(dummyDealObj)
|
| - |
|
754 |
|
| - |
|
755 |
for super_category, categoryFeaturedDeals in featuredDeals.iteritems():
|
| - |
|
756 |
for val in categoryFeaturedDeals.itervalues():
|
| - |
|
757 |
dummyDealObjList = __constructDummyDealObject(val.get('skuBundleId'))
|
| - |
|
758 |
for dummyDealObj in dummyDealObjList:
|
| - |
|
759 |
if super_category == dummyDealObj['category_id']:
|
| - |
|
760 |
continue
|
| - |
|
761 |
if super_category ==6:
|
| - |
|
762 |
accessories_deals.append(dummyDealObj)
|
| - |
|
763 |
|
| - |
|
764 |
|
| 595 |
sortedMapAccessories = {}
|
765 |
sortedMapAccessories = {}
|
| 596 |
rankMapAccessories = {}
|
766 |
rankMapAccessories = {}
|
| 597 |
rankAccessories = 0
|
767 |
rankAccessories = 0
|
| 598 |
|
768 |
|
| 599 |
blockedRanksAccessories = []
|
769 |
blockedRanksAccessories = []
|
| 600 |
blockedSkuBundlesAccessories = []
|
770 |
blockedSkuBundlesAccessories = []
|
| 601 |
blockedInfoAccessories = {}
|
771 |
blockedInfoAccessories = {}
|
| 602 |
|
772 |
|
| 603 |
featuredDealsAccessories = featuredDeals.get(6)
|
773 |
featuredDealsAccessories = featuredDeals.get(6)
|
| 604 |
|
774 |
|
| 605 |
for k, v in featuredDealsAccessories.iteritems():
|
775 |
for k, v in featuredDealsAccessories.iteritems():
|
| 606 |
blockedRanksAccessories.append(k-1)
|
776 |
blockedRanksAccessories.append(k-1)
|
| 607 |
blockedSkuBundlesAccessories.append(v.get('skuBundleId'))
|
777 |
blockedSkuBundlesAccessories.append(v.get('skuBundleId'))
|
| 608 |
|
778 |
|
| 609 |
|
779 |
|
| 610 |
for sorted_deal in accessories_deals:
|
780 |
for sorted_deal in accessories_deals:
|
| 611 |
|
781 |
|
| 612 |
while(True):
|
782 |
while(True):
|
| 613 |
if rankAccessories in blockedRanksAccessories:
|
783 |
if rankAccessories in blockedRanksAccessories:
|
| 614 |
rankAccessories = rankAccessories +1
|
784 |
rankAccessories = rankAccessories +1
|
| 615 |
else:
|
785 |
else:
|
| 616 |
break
|
786 |
break
|
| 617 |
|
787 |
|
| 618 |
if sorted_deal['skuBundleId'] in blockedSkuBundlesAccessories:
|
788 |
if sorted_deal['skuBundleId'] in blockedSkuBundlesAccessories:
|
| 619 |
if blockedInfoAccessories.has_key(sorted_deal['skuBundleId']):
|
789 |
if blockedInfoAccessories.has_key(sorted_deal['skuBundleId']):
|
| 620 |
blockedInfoAccessories.get(sorted_deal['skuBundleId']).append(sorted_deal)
|
790 |
blockedInfoAccessories.get(sorted_deal['skuBundleId']).append(sorted_deal)
|
| 621 |
else:
|
791 |
else:
|
| 622 |
blockedInfoAccessories[sorted_deal['skuBundleId']] = [sorted_deal]
|
792 |
blockedInfoAccessories[sorted_deal['skuBundleId']] = [sorted_deal]
|
| 623 |
continue
|
793 |
continue
|
| 624 |
|
794 |
|
| 625 |
if sortedMapAccessories.get(sorted_deal['skuBundleId']) is None:
|
795 |
if sortedMapAccessories.get(sorted_deal['skuBundleId']) is None:
|
| 626 |
sortedMapAccessories[sorted_deal['skuBundleId']] = {rankAccessories:[sorted_deal]}
|
796 |
sortedMapAccessories[sorted_deal['skuBundleId']] = {rankAccessories:[sorted_deal]}
|
| 627 |
rankMapAccessories[rankAccessories] = (sortedMapAccessories[sorted_deal['skuBundleId']].values())[0]
|
797 |
rankMapAccessories[rankAccessories] = (sortedMapAccessories[sorted_deal['skuBundleId']].values())[0]
|
| 628 |
rankAccessories = rankAccessories +1
|
798 |
rankAccessories = rankAccessories +1
|
| 629 |
else:
|
799 |
else:
|
| 630 |
for temp_list in sortedMapAccessories.get(sorted_deal['skuBundleId']).itervalues():
|
800 |
for temp_list in sortedMapAccessories.get(sorted_deal['skuBundleId']).itervalues():
|
| 631 |
temp_list.append(sorted_deal)
|
801 |
temp_list.append(sorted_deal)
|
| 632 |
rankMapAccessories[(sortedMapAccessories.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
802 |
rankMapAccessories[(sortedMapAccessories.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
| 633 |
|
803 |
|
| 634 |
|
804 |
|
| 635 |
for rank in blockedRanksAccessories:
|
805 |
for rank in blockedRanksAccessories:
|
| 636 |
if blockedInfoAccessories.get((featuredDealsAccessories.get(rank+1)).get('skuBundleId')) is not None:
|
806 |
if blockedInfoAccessories.get((featuredDealsAccessories.get(rank+1)).get('skuBundleId')) is not None:
|
| 637 |
rankMapAccessories[rank] = blockedInfoAccessories.get((featuredDealsAccessories.get(rank+1)).get('skuBundleId'))
|
807 |
rankMapAccessories[rank] = blockedInfoAccessories.get((featuredDealsAccessories.get(rank+1)).get('skuBundleId'))
|
| 638 |
|
808 |
|
| 639 |
specialOffer = None
|
809 |
specialOffer = None
|
| 640 |
promoOffer = get_mongo_connection().Catalog.PromoOffer.find_one({'user_id':userId})
|
810 |
promoOffer = get_mongo_connection().Catalog.PromoOffer.find_one({'user_id':userId})
|
| 641 |
try:
|
811 |
try:
|
| 642 |
if promoOffer is not None:
|
812 |
if promoOffer is not None:
|
| 643 |
offer = get_mongo_connection().Catalog.Promotions.find_one({'_id':promoOffer.get('offer_id')})
|
813 |
offer = get_mongo_connection().Catalog.Promotions.find_one({'_id':promoOffer.get('offer_id')})
|
| Line 647... |
Line 817... |
| 647 |
offer.get('startDate'), offer.get('endDate'), promoOffer.get('target1'), promoOffer.get('target1_cash_back_percetage'), promoOffer.get('target2'), promoOffer.get('target2_cash_back_percetage'), promoOffer.get('maxCashBack'),offer.get('url'),
|
817 |
offer.get('startDate'), offer.get('endDate'), promoOffer.get('target1'), promoOffer.get('target1_cash_back_percetage'), promoOffer.get('target2'), promoOffer.get('target2_cash_back_percetage'), promoOffer.get('maxCashBack'),offer.get('url'),
|
| 648 |
promoOffer.get('pending_order_value'), promoOffer.get('delivered_order_value'), promoOffer.get('last_run_timestamp'))
|
818 |
promoOffer.get('pending_order_value'), promoOffer.get('delivered_order_value'), promoOffer.get('last_run_timestamp'))
|
| 649 |
|
819 |
|
| 650 |
specialOffer = promo
|
820 |
specialOffer = promo
|
| 651 |
except:
|
821 |
except:
|
| 652 |
pass
|
822 |
traceback.print_exc()
|
| 653 |
|
823 |
|
| 654 |
|
824 |
|
| 655 |
mem_cache_val = {3:mobile_deals, 5:tablet_deals, 6: accessories_deals,"3_rankMap": rankMapMobiles,"5_rankMap": rankMapTablets,"6_rankMap": rankMapAccessories, "specialOffer":specialOffer }
|
825 |
mem_cache_val = {6:accessories_deals,"6_rankMap": rankMapAccessories, "specialOffer":specialOffer }
|
| 656 |
mc.set(str(userId), mem_cache_val)
|
826 |
mc.set(str(userId)+'_acc', mem_cache_val)
|
| - |
|
827 |
|
| 657 |
|
828 |
|
| 658 |
|
829 |
|
| 659 |
def __populateFeaturedDeals():
|
830 |
def __populateFeaturedDeals():
|
| 660 |
print "Populating featured deals....."
|
831 |
print "Populating featured deals....."
|
| 661 |
featuredDealsMobiles = {}
|
832 |
featuredDealsMobiles = {}
|
| Line 940... |
Line 1111... |
| 940 |
elif item[0]['cash_back_type'] ==2:
|
1111 |
elif item[0]['cash_back_type'] ==2:
|
| 941 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price'] - math.floor(item[0]['cash_back'])
|
1112 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price'] - math.floor(item[0]['cash_back'])
|
| 942 |
else:
|
1113 |
else:
|
| 943 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price']
|
1114 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price']
|
| 944 |
|
1115 |
|
| - |
|
1116 |
temp.append(item[0])
|
| - |
|
1117 |
if len(temp) > 1:
|
| - |
|
1118 |
temp = sorted(temp, key = lambda x: (x['available_price']),reverse=False)
|
| - |
|
1119 |
dealsListMap.append(temp)
|
| - |
|
1120 |
return dealsListMap
|
| - |
|
1121 |
|
| - |
|
1122 |
|
| - |
|
1123 |
def getAccesoryDeals(userId, category_id, offset, limit, sort, direction, filterData=None):
|
| - |
|
1124 |
if mc.get("category_cash_back") is None or not bool(mc.get("category_cash_back")):
|
| - |
|
1125 |
populateCashBack()
|
| - |
|
1126 |
|
| - |
|
1127 |
dealsListMap = []
|
| - |
|
1128 |
user_specific_deals = mc.get(str(userId)+'_acc')
|
| - |
|
1129 |
if user_specific_deals is None:
|
| - |
|
1130 |
__populateCacheForAccessories(userId)
|
| - |
|
1131 |
user_specific_deals = mc.get(str(userId)+'_acc')
|
| - |
|
1132 |
else:
|
| - |
|
1133 |
print "Getting user deals from accessory cache"
|
| - |
|
1134 |
category_specific_deals = user_specific_deals.get(category_id)
|
| - |
|
1135 |
|
| - |
|
1136 |
insert_featured_deals = False
|
| - |
|
1137 |
if sort is None or direction is None:
|
| - |
|
1138 |
insert_featured_deals = True
|
| - |
|
1139 |
rankMap = user_specific_deals.get(str(category_id)+"_rankMap")
|
| - |
|
1140 |
else:
|
| - |
|
1141 |
if sort == "bestSellerPoints":
|
| - |
|
1142 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['bestSellerPoints'], x['internalRank'], x['nlcPoints']),reverse=True)
|
| - |
|
1143 |
else:
|
| - |
|
1144 |
if direction == -1:
|
| - |
|
1145 |
rev = True
|
| - |
|
1146 |
else:
|
| - |
|
1147 |
rev = False
|
| - |
|
1148 |
sorted_deals = sorted(category_specific_deals, key = lambda x: (x['available_price']),reverse=rev)
|
| - |
|
1149 |
|
| - |
|
1150 |
|
| - |
|
1151 |
filtered_deals = []
|
| - |
|
1152 |
dataExist = True
|
| - |
|
1153 |
if filterData is not None:
|
| - |
|
1154 |
try:
|
| - |
|
1155 |
filtered_deals = filterDeals(category_specific_deals, filterData)
|
| - |
|
1156 |
if len(filtered_deals)==0:
|
| - |
|
1157 |
dataExist = False
|
| - |
|
1158 |
except:
|
| - |
|
1159 |
traceback.print_exc()
|
| - |
|
1160 |
if dataExist:
|
| - |
|
1161 |
|
| - |
|
1162 |
if not insert_featured_deals:
|
| - |
|
1163 |
sortedMap = {}
|
| - |
|
1164 |
rankMap = {}
|
| - |
|
1165 |
rank = 0
|
| - |
|
1166 |
for sorted_deal in sorted_deals:
|
| - |
|
1167 |
|
| - |
|
1168 |
if len(filtered_deals) > 0 and sorted_deal['skuBundleId'] not in filtered_deals:
|
| - |
|
1169 |
continue
|
| - |
|
1170 |
|
| - |
|
1171 |
if sortedMap.get(sorted_deal['skuBundleId']) is None:
|
| - |
|
1172 |
sortedMap[sorted_deal['skuBundleId']] = {rank:[sorted_deal]}
|
| - |
|
1173 |
rankMap[rank] = (sortedMap[sorted_deal['skuBundleId']].values())[0]
|
| - |
|
1174 |
rank = rank +1
|
| - |
|
1175 |
else:
|
| - |
|
1176 |
for temp_list in sortedMap.get(sorted_deal['skuBundleId']).itervalues():
|
| - |
|
1177 |
temp_list.append(sorted_deal)
|
| - |
|
1178 |
rankMap[(sortedMap.get(sorted_deal['skuBundleId']).keys())[0]] = temp_list
|
| - |
|
1179 |
else:
|
| - |
|
1180 |
filterMap = {}
|
| - |
|
1181 |
rank = 0
|
| - |
|
1182 |
if len(filtered_deals) > 0:
|
| - |
|
1183 |
try:
|
| - |
|
1184 |
od = collections.OrderedDict(sorted(rankMap.items()))
|
| - |
|
1185 |
except:
|
| - |
|
1186 |
od = ordereddict.OrderedDict(sorted(rankMap.items()))
|
| - |
|
1187 |
for k, v in od.iteritems():
|
| - |
|
1188 |
if v[0].get('skuBundleId') in filtered_deals:
|
| - |
|
1189 |
filterMap[rank] = v
|
| - |
|
1190 |
rank =rank+1
|
| - |
|
1191 |
rankMap = filterMap
|
| - |
|
1192 |
|
| - |
|
1193 |
rankCounter = offset
|
| - |
|
1194 |
if filterData is None:
|
| - |
|
1195 |
if mc.get("featured_deals_deal_object") is None or not bool(mc.get("featured_deals_deal_object")):
|
| - |
|
1196 |
try:
|
| - |
|
1197 |
__populateFeaturedDealsForDealObject()
|
| - |
|
1198 |
fd_dealObject = mc.get("featured_deals_deal_object")
|
| - |
|
1199 |
except:
|
| - |
|
1200 |
fd_dealObject = {3:{},5:{},6:{}}
|
| - |
|
1201 |
else:
|
| - |
|
1202 |
fd_dealObject = mc.get("featured_deals_deal_object")
|
| - |
|
1203 |
|
| - |
|
1204 |
else:
|
| - |
|
1205 |
rankMap = {}
|
| - |
|
1206 |
|
| - |
|
1207 |
|
| - |
|
1208 |
specialOffer = user_specific_deals.get('specialOffer')
|
| - |
|
1209 |
|
| - |
|
1210 |
for dealList in [rankMap.get(k, []) for k in range(offset, offset+limit)]:
|
| - |
|
1211 |
if filterData is None:
|
| - |
|
1212 |
while(True):
|
| - |
|
1213 |
|
| - |
|
1214 |
rankCounter = rankCounter+1
|
| - |
|
1215 |
if (fd_dealObject.get(category_id).get(rankCounter)) is not None:
|
| - |
|
1216 |
if (fd_dealObject.get(category_id).get(rankCounter).get('offer_id') !=0):
|
| - |
|
1217 |
#Check whether user can see offer
|
| - |
|
1218 |
if specialOffer is None or specialOffer.endDate < to_java_date(datetime.now()):
|
| - |
|
1219 |
continue
|
| - |
|
1220 |
deal_object_temp = []
|
| - |
|
1221 |
deal_object_temp.append(fd_dealObject.get(category_id).get(rankCounter).get('object'))
|
| - |
|
1222 |
dealsListMap.append(deal_object_temp)
|
| - |
|
1223 |
else:
|
| - |
|
1224 |
break
|
| - |
|
1225 |
|
| - |
|
1226 |
temp = []
|
| - |
|
1227 |
if dealList is None or len(dealList)==0:
|
| - |
|
1228 |
continue
|
| - |
|
1229 |
for d in dealList:
|
| - |
|
1230 |
item = list(get_mongo_connection().Catalog.MasterData.find({'_id':d['_id']}))
|
| - |
|
1231 |
if len(item) ==0:
|
| - |
|
1232 |
continue
|
| - |
|
1233 |
if d['dealType'] == 1 and d['source_id'] ==1:
|
| - |
|
1234 |
try:
|
| - |
|
1235 |
manualDeal = list(get_mongo_connection().Catalog.ManualDeals.find({'sku':d['_id'],'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())}}))
|
| - |
|
1236 |
item[0]['marketPlaceUrl'] = manualDeal[0]['dealUrl'].strip()
|
| - |
|
1237 |
except:
|
| - |
|
1238 |
pass
|
| - |
|
1239 |
elif d['source_id'] ==3:
|
| - |
|
1240 |
item[0]['marketPlaceUrl'] = item[0]['marketPlaceUrl']+'?supc='+item[0].get('identifier')
|
| - |
|
1241 |
else:
|
| - |
|
1242 |
pass
|
| - |
|
1243 |
try:
|
| - |
|
1244 |
cashBack = getCashBack(item[0]['_id'], item[0]['source_id'], item[0]['category_id'])
|
| - |
|
1245 |
if not cashBack or cashBack.get('cash_back_status')!=1:
|
| - |
|
1246 |
item[0]['cash_back_type'] = 0
|
| - |
|
1247 |
item[0]['cash_back'] = 0
|
| - |
|
1248 |
else:
|
| - |
|
1249 |
if cashBack.get('maxCashBack') is not None:
|
| - |
|
1250 |
|
| - |
|
1251 |
if cashBack.get('cash_back_type') ==1 and (float(cashBack.get('cash_back'))*item[0]['available_price'])/100 > cashBack.get('maxCashBack'):
|
| - |
|
1252 |
cashBack['cash_back_type'] = 2
|
| - |
|
1253 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
| - |
|
1254 |
elif cashBack.get('cash_back_type') ==2 and cashBack.get('cash_back') > cashBack.get('maxCashBack'):
|
| - |
|
1255 |
cashBack['cash_back'] = cashBack['maxCashBack']
|
| - |
|
1256 |
|
| - |
|
1257 |
item[0]['cash_back_type'] = int(cashBack['cash_back_type'])
|
| - |
|
1258 |
item[0]['cash_back'] = cashBack['cash_back']
|
| - |
|
1259 |
except:
|
| - |
|
1260 |
print "Error in adding cashback to deals"
|
| - |
|
1261 |
item[0]['cash_back_type'] = 0
|
| - |
|
1262 |
item[0]['cash_back'] = 0
|
| - |
|
1263 |
try:
|
| - |
|
1264 |
item[0]['dp'] = d['dp']
|
| - |
|
1265 |
item[0]['showDp'] = d['showDp']
|
| - |
|
1266 |
except:
|
| - |
|
1267 |
item[0]['dp'] = 0.0
|
| - |
|
1268 |
item[0]['showDp'] = 0
|
| - |
|
1269 |
try:
|
| - |
|
1270 |
item[0]['thumbnail'] = item[0]['thumbnail'].strip()
|
| - |
|
1271 |
except:
|
| - |
|
1272 |
pass
|
| - |
|
1273 |
|
| - |
|
1274 |
try:
|
| - |
|
1275 |
if item[0]['showVideo']==0:
|
| - |
|
1276 |
item[0]['videoLink'] =""
|
| - |
|
1277 |
except:
|
| - |
|
1278 |
item[0]['videoLink'] =""
|
| - |
|
1279 |
try:
|
| - |
|
1280 |
if item[0]['quantity'] >1:
|
| - |
|
1281 |
ppq = float(item[0]['available_price'])/item[0]['quantity']
|
| - |
|
1282 |
|
| - |
|
1283 |
if ppq == round(ppq):
|
| - |
|
1284 |
item[0]['ppq'] = int(ppq)
|
| - |
|
1285 |
else:
|
| - |
|
1286 |
item[0]['ppq'] = round(ppq,2)
|
| - |
|
1287 |
else:
|
| - |
|
1288 |
item[0]['ppq'] = 0
|
| - |
|
1289 |
except:
|
| - |
|
1290 |
item[0]['ppq'] = 0
|
| - |
|
1291 |
if filterData is None:
|
| - |
|
1292 |
if item[0]['category_id']!=6:
|
| - |
|
1293 |
try:
|
| - |
|
1294 |
item[0]['filterLinkBrand'] = '/category/'+str(int(item[0]['category_id']))+'?searchFor='+urllib.quote(item[0]['brand'])+'&filter=brand&brands='+str(int(item[0]['brand_id']))
|
| - |
|
1295 |
item[0]['filterTextBrand'] = (item[0]['brand'])
|
| - |
|
1296 |
except:
|
| - |
|
1297 |
pass
|
| - |
|
1298 |
else:
|
| - |
|
1299 |
try:
|
| - |
|
1300 |
if item[0]['subCategory']=='' or item[0]['subCategory'] is None or item[0]['subCategoryId']==0:
|
| - |
|
1301 |
raise
|
| - |
|
1302 |
item[0]['filterLinkSubCategory'] = '/category/'+str(int(item[0]['category_id']))+'?searchFor='+urllib.quote(item[0]['subCategory'])+'&filter=subcategory&subcategories='+str(int(item[0]['subCategoryId']))
|
| - |
|
1303 |
item[0]['filterTextSubCategory'] = (item[0]['subCategory'])
|
| - |
|
1304 |
item[0]['filterLinkBrand'] = '/category/'+str(int(item[0]['category_id']))+'?searchFor='+urllib.quote(item[0]['brand'])+'&filter=brand&brands='+str(int(item[0]['brand_id']))
|
| - |
|
1305 |
item[0]['filterTextBrand'] = (item[0]['brand'])
|
| - |
|
1306 |
except:
|
| - |
|
1307 |
pass
|
| - |
|
1308 |
try:
|
| - |
|
1309 |
if item[0]['source_id']==4:
|
| - |
|
1310 |
item_availability_info = mc.get("item_availability_"+str(item[0]['identifier']).strip())
|
| - |
|
1311 |
if item_availability_info is None or len(item_availability_info)==0:
|
| - |
|
1312 |
item[0]['availabilityInfo'] = [{}]
|
| - |
|
1313 |
else:
|
| - |
|
1314 |
item[0]['availabilityInfo'] = item_availability_info
|
| - |
|
1315 |
except:
|
| - |
|
1316 |
item[0]['availabilityInfo'] = [{}]
|
| - |
|
1317 |
|
| - |
|
1318 |
if item[0]['source_id']==4:
|
| - |
|
1319 |
for av_info in item[0]['availabilityInfo']:
|
| - |
|
1320 |
if not av_info:
|
| - |
|
1321 |
continue
|
| - |
|
1322 |
av_info['cash_back'] = item[0]['cash_back']
|
| - |
|
1323 |
av_info['cash_back_type'] = item[0]['cash_back_type']
|
| - |
|
1324 |
netPriceAfterCashBack = av_info['sellingPrice']
|
| - |
|
1325 |
if av_info['cash_back_type'] ==1:
|
| - |
|
1326 |
netPriceAfterCashBack = av_info['sellingPrice'] - math.floor(float(av_info['sellingPrice'])*av_info['cash_back']/100)
|
| - |
|
1327 |
elif av_info['cash_back_type'] ==2:
|
| - |
|
1328 |
netPriceAfterCashBack = av_info['sellingPrice'] - math.floor(av_info['cash_back'])
|
| - |
|
1329 |
else:
|
| - |
|
1330 |
pass
|
| - |
|
1331 |
av_info['netPriceAfterCashBack'] = netPriceAfterCashBack
|
| - |
|
1332 |
|
| - |
|
1333 |
#item[0]['netPriceAfterCashBack'] = d['netPriceAfterCashBack']
|
| - |
|
1334 |
|
| - |
|
1335 |
if item[0]['source_id'] != SOURCE_MAP.get("PAYTM.COM"):
|
| - |
|
1336 |
if item[0]['codAvailable'] ==1:
|
| - |
|
1337 |
paytmPrice = item[0]['available_price']
|
| - |
|
1338 |
else:
|
| - |
|
1339 |
paytmPrice = item[0]['gross_price']
|
| - |
|
1340 |
|
| - |
|
1341 |
if item[0]['cash_back_type'] ==1:
|
| - |
|
1342 |
item[0]['netPriceAfterCashBack'] = paytmPrice - math.floor(float(paytmPrice)*item[0]['cash_back']/100)
|
| - |
|
1343 |
elif item[0]['cash_back_type'] ==2:
|
| - |
|
1344 |
item[0]['netPriceAfterCashBack'] = paytmPrice - math.floor(item[0]['cash_back'])
|
| - |
|
1345 |
else:
|
| - |
|
1346 |
item[0]['netPriceAfterCashBack'] = paytmPrice
|
| - |
|
1347 |
|
| - |
|
1348 |
else:
|
| - |
|
1349 |
if item[0]['cash_back_type'] ==1:
|
| - |
|
1350 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price'] - math.floor(float(item[0]['available_price'])*item[0]['cash_back']/100)
|
| - |
|
1351 |
elif item[0]['cash_back_type'] ==2:
|
| - |
|
1352 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price'] - math.floor(item[0]['cash_back'])
|
| - |
|
1353 |
else:
|
| - |
|
1354 |
item[0]['netPriceAfterCashBack'] = item[0]['available_price']
|
| - |
|
1355 |
|
| 945 |
# if specialOffer is not None and item[0]['source_id']==4:
|
1356 |
# if specialOffer is not None and item[0]['source_id']==4:
|
| 946 |
# if item[0]['category_id'] in specialOffer.categories_applicable and item[0]['subCategoryId'] not in specialOffer.sub_categories_not_applicable:
|
1357 |
# if item[0]['category_id'] in specialOffer.categories_applicable and item[0]['subCategoryId'] not in specialOffer.sub_categories_not_applicable:
|
| 947 |
# item[0]['specialOffer'] = specialOffer.__dict__
|
1358 |
# item[0]['specialOffer'] = specialOffer.__dict__
|
| 948 |
# else:
|
1359 |
# else:
|
| 949 |
# item[0]['specialOffer'] = {}
|
1360 |
# item[0]['specialOffer'] = {}
|
| Line 952... |
Line 1363... |
| 952 |
if len(temp) > 1:
|
1363 |
if len(temp) > 1:
|
| 953 |
temp = sorted(temp, key = lambda x: (x['available_price']),reverse=False)
|
1364 |
temp = sorted(temp, key = lambda x: (x['available_price']),reverse=False)
|
| 954 |
dealsListMap.append(temp)
|
1365 |
dealsListMap.append(temp)
|
| 955 |
return dealsListMap
|
1366 |
return dealsListMap
|
| 956 |
|
1367 |
|
| - |
|
1368 |
|
| 957 |
def filterDeals(deals, filterData):
|
1369 |
def filterDeals(deals, filterData):
|
| 958 |
print "Filter data ", filterData
|
1370 |
print "Filter data ", filterData
|
| 959 |
brandsFiltered = []
|
1371 |
brandsFiltered = []
|
| 960 |
subCategoryFiltered = []
|
1372 |
subCategoryFiltered = []
|
| 961 |
filterArray = filterData.split('|')
|
1373 |
filterArray = filterData.split('|')
|
| Line 1248... |
Line 1660... |
| 1248 |
return {0:"Data not updated."}
|
1660 |
return {0:"Data not updated."}
|
| 1249 |
|
1661 |
|
| 1250 |
def resetCache(userId):
|
1662 |
def resetCache(userId):
|
| 1251 |
try:
|
1663 |
try:
|
| 1252 |
mc.delete(userId)
|
1664 |
mc.delete(userId)
|
| - |
|
1665 |
mc.delete(userId+'_acc')
|
| 1253 |
return {1:'Cache cleared.'}
|
1666 |
return {1:'Cache cleared.'}
|
| 1254 |
except:
|
1667 |
except:
|
| 1255 |
return {0:'Unable to clear cache.'}
|
1668 |
return {0:'Unable to clear cache.'}
|
| 1256 |
|
1669 |
|
| 1257 |
def updateCollection(data):
|
1670 |
def updateCollection(data):
|
| Line 1540... |
Line 1953... |
| 1540 |
data['identifier'] = str(data['identifier'])
|
1953 |
data['identifier'] = str(data['identifier'])
|
| 1541 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
1954 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
| 1542 |
data['model_name'] = str(data['model_name'])
|
1955 |
data['model_name'] = str(data['model_name'])
|
| 1543 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
1956 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
| 1544 |
data['shippingCost'] = float(data['shippingCost'])
|
1957 |
data['shippingCost'] = float(data['shippingCost'])
|
| - |
|
1958 |
data['internalRank'] = int(data['internalRank'])
|
| 1545 |
if data['category_id'] ==6 and data['subCategoryId'] ==0:
|
1959 |
if data['category_id'] ==6 and data['subCategoryId'] ==0:
|
| 1546 |
return {0:'Sub-Category not selected'}
|
1960 |
return {0:'Sub-Category not selected'}
|
| 1547 |
elif data['category_id'] !=6 and data['subCategoryId'] !=0:
|
1961 |
elif data['category_id'] !=6 and data['subCategoryId'] !=0:
|
| 1548 |
return {0:'Sub-Category not valid'}
|
1962 |
return {0:'Sub-Category not valid'}
|
| 1549 |
else:
|
1963 |
else:
|
| Line 1567... |
Line 1981... |
| 1567 |
data['identifier'] = str(data['identifier'])
|
1981 |
data['identifier'] = str(data['identifier'])
|
| 1568 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
1982 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
| 1569 |
data['model_name'] = str(data['model_name'])
|
1983 |
data['model_name'] = str(data['model_name'])
|
| 1570 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
1984 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
| 1571 |
data['shippingCost'] = float(data['shippingCost'])
|
1985 |
data['shippingCost'] = float(data['shippingCost'])
|
| - |
|
1986 |
data['internalRank'] = int(data['internalRank'])
|
| 1572 |
if data['category_id'] ==6 and data['subCategoryId'] ==0:
|
1987 |
if data['category_id'] ==6 and data['subCategoryId'] ==0:
|
| 1573 |
return {0:'Sub-Category not selected'}
|
1988 |
return {0:'Sub-Category not selected'}
|
| 1574 |
elif data['category_id'] !=6 and data['subCategoryId'] !=0:
|
1989 |
elif data['category_id'] !=6 and data['subCategoryId'] !=0:
|
| 1575 |
return {0:'Sub-Category not valid'}
|
1990 |
return {0:'Sub-Category not valid'}
|
| 1576 |
else:
|
1991 |
else:
|
| Line 1593... |
Line 2008... |
| 1593 |
data['updatedOn'] = to_java_date(datetime.now())
|
2008 |
data['updatedOn'] = to_java_date(datetime.now())
|
| 1594 |
data['identifier'] = str(data['identifier'])
|
2009 |
data['identifier'] = str(data['identifier'])
|
| 1595 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
2010 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
| 1596 |
data['model_name'] = str(data['model_name'])
|
2011 |
data['model_name'] = str(data['model_name'])
|
| 1597 |
data['shippingCost'] = float(data['shippingCost'])
|
2012 |
data['shippingCost'] = float(data['shippingCost'])
|
| - |
|
2013 |
data['internalRank'] = int(data['internalRank'])
|
| 1598 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
2014 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
| 1599 |
if data['category_id'] ==6 and data['subCategoryId'] ==0:
|
2015 |
if data['category_id'] ==6 and data['subCategoryId'] ==0:
|
| 1600 |
return {0:'Sub-Category not selected'}
|
2016 |
return {0:'Sub-Category not selected'}
|
| 1601 |
elif data['category_id'] !=6 and data['subCategoryId'] !=0:
|
2017 |
elif data['category_id'] !=6 and data['subCategoryId'] !=0:
|
| 1602 |
return {0:'Sub-Category not valid'}
|
2018 |
return {0:'Sub-Category not valid'}
|
| 1603 |
else:
|
2019 |
else:
|
| 1604 |
pass
|
2020 |
pass
|
| 1605 |
data['subCategory'] = SUB_CATEGORY_MAP.get(data['subCategoryId'])
|
2021 |
data['subCategory'] = SUB_CATEGORY_MAP.get(data['subCategoryId'])
|
| 1606 |
get_mongo_connection().Catalog.MasterData.update({'_id':_id},{"$set":data},upsert=False)
|
2022 |
get_mongo_connection().Catalog.MasterData.update({'_id':_id},{"$set":data},upsert=False)
|
| - |
|
2023 |
get_mongo_connection().Catalog.MasterData.update({'skuBundleId':skuBundleId},{"$set":{'internalRank':data['internalRank']}},upsert=False, multi=True)
|
| 1607 |
return {1:'Data updated successfully.'}
|
2024 |
return {1:'Data updated successfully.'}
|
| 1608 |
else:
|
2025 |
else:
|
| 1609 |
_id = data.pop('_id')
|
2026 |
_id = data.pop('_id')
|
| 1610 |
skuBundleId = data.pop('skuBundleId')
|
2027 |
skuBundleId = data.pop('skuBundleId')
|
| 1611 |
data['updatedOn'] = to_java_date(datetime.now())
|
2028 |
data['updatedOn'] = to_java_date(datetime.now())
|
| 1612 |
data['identifier'] = str(data['identifier'])
|
2029 |
data['identifier'] = str(data['identifier'])
|
| 1613 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
2030 |
data['secondaryIdentifier'] = str(data['secondaryIdentifier'])
|
| 1614 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
2031 |
data['brand_id'] = __getBrandIdForBrand(data['brand'], data['category_id'])
|
| 1615 |
data['model_name'] = str(data['model_name'])
|
2032 |
data['model_name'] = str(data['model_name'])
|
| 1616 |
data['shippingCost'] = float(data['shippingCost'])
|
2033 |
data['shippingCost'] = float(data['shippingCost'])
|
| - |
|
2034 |
data['internalRank'] = int(data['internalRank'])
|
| 1617 |
if data['category_id'] ==6 and data['subCategoryId'] ==0:
|
2035 |
if data['category_id'] ==6 and data['subCategoryId'] ==0:
|
| 1618 |
return {0:'Sub-Category not selected'}
|
2036 |
return {0:'Sub-Category not selected'}
|
| 1619 |
elif data['category_id'] !=6 and data['subCategoryId'] !=0:
|
2037 |
elif data['category_id'] !=6 and data['subCategoryId'] !=0:
|
| 1620 |
return {0:'Sub-Category not valid'}
|
2038 |
return {0:'Sub-Category not valid'}
|
| 1621 |
else:
|
2039 |
else:
|
| Line 1635... |
Line 2053... |
| 1635 |
item['status'] = data['status']
|
2053 |
item['status'] = data['status']
|
| 1636 |
item['maxPrice'] = data['maxPrice']
|
2054 |
item['maxPrice'] = data['maxPrice']
|
| 1637 |
item['brand_id'] = data['brand_id']
|
2055 |
item['brand_id'] = data['brand_id']
|
| 1638 |
item['subCategoryId'] = data['subCategoryId']
|
2056 |
item['subCategoryId'] = data['subCategoryId']
|
| 1639 |
item['subCategory'] = data['subCategory']
|
2057 |
item['subCategory'] = data['subCategory']
|
| - |
|
2058 |
item['internalRank'] = data['internalRank']
|
| 1640 |
similar_item_id = item.pop('_id')
|
2059 |
similar_item_id = item.pop('_id')
|
| 1641 |
get_mongo_connection().Catalog.MasterData.update({'_id':similar_item_id},{"$set":item},upsert=False)
|
2060 |
get_mongo_connection().Catalog.MasterData.update({'_id':similar_item_id},{"$set":item},upsert=False)
|
| 1642 |
return {1:'Data updated successfully.'}
|
2061 |
return {1:'Data updated successfully.'}
|
| 1643 |
except:
|
2062 |
except:
|
| 1644 |
return {0:'Unable to update data'}
|
2063 |
return {0:'Unable to update data'}
|