Subversion Repositories SmartDukaan

Rev

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

Rev 14475 Rev 14481
Line 589... Line 589...
589
        return {1:"Data updated successfully"}
589
        return {1:"Data updated successfully"}
590
    except Exception as e:
590
    except Exception as e:
591
        print e
591
        print e
592
        return {0:"Data not updated."}
592
        return {0:"Data not updated."}
593
    
593
    
-
 
594
def addNegativeDeals(data):
-
 
595
    collection = get_mongo_connection().Catalog.NegativeDeals
-
 
596
    cursor = collection.find({"sku":data['sku']})
-
 
597
    if cursor.count() > 0:
-
 
598
        return {0:"Sku information already present."}
-
 
599
    else:
-
 
600
        collection.insert(data)
-
 
601
        return {1:"Data added successfully"}
-
 
602
 
-
 
603
def getAllNegativeDeals(offset, limit):
-
 
604
    data = []
-
 
605
    collection = get_mongo_connection().Catalog.NegativeDeals
-
 
606
    cursor = collection.find().skip(offset).limit(limit)
-
 
607
    for val in cursor:
-
 
608
        master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
-
 
609
        if len(master) > 0:
-
 
610
            val['brand'] = master[0]['brand']
-
 
611
            val['source_product_name'] = master[0]['source_product_name']
-
 
612
            val['skuBundleId'] = master[0]['skuBundleId']
-
 
613
        else:
-
 
614
            val['brand'] = ""
-
 
615
            val['source_product_name'] = ""
-
 
616
            val['skuBundleId'] = ""
-
 
617
        data.append(val)
-
 
618
    return data
-
 
619
 
-
 
620
def getAllManualDeals(offset, limit):
-
 
621
    data = []
-
 
622
    collection = get_mongo_connection().Catalog.ManualDeals
-
 
623
    cursor = collection.find({'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())}}).skip(offset).limit(limit)
-
 
624
    for val in cursor:
-
 
625
        master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
-
 
626
        if len(master) > 0:
-
 
627
            val['brand'] = master[0]['brand']
-
 
628
            val['source_product_name'] = master[0]['source_product_name']
-
 
629
            val['skuBundleId'] = master[0]['skuBundleId']
-
 
630
        else:
-
 
631
            val['brand'] = ""
-
 
632
            val['source_product_name'] = ""
-
 
633
            val['skuBundleId'] = ""
-
 
634
        data.append(val)
-
 
635
    return data
594
    
636
    
-
 
637
def addManualDeal(data):
-
 
638
    collection = get_mongo_connection().Catalog.ManualDeals
-
 
639
    cursor = collection.find({'sku':data['sku'],'startDate':{'$lte':to_java_date(datetime.now())},'endDate':{'$gte':to_java_date(datetime.now())}})
-
 
640
    if cursor.count() > 0:
-
 
641
        return {0:"Sku information already present."}
-
 
642
    else:
-
 
643
        collection.insert(data)
-
 
644
        get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
-
 
645
        return {1:"Data added successfully"}
-
 
646
    
-
 
647
def deleteDocument(data):
-
 
648
    print data
-
 
649
    try:
-
 
650
        collection = get_mongo_connection().Catalog[data['class']]
-
 
651
        class_name = data.pop('class')
-
 
652
        _id = data.pop('oid')
-
 
653
        record = list(collection.find({'_id':ObjectId(_id)}))
-
 
654
        collection.remove({'_id':ObjectId(_id)})
-
 
655
        if class_name !="CategoryDiscount":
-
 
656
            get_mongo_connection().Catalog.MasterData.update({'_id':record[0]['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}})
-
 
657
        else:
-
 
658
            get_mongo_connection().Catalog.MasterData.update({'brand':re.compile(record[0]['brand'], re.IGNORECASE),'category_id':record[0]['category_id']}, \
-
 
659
                                                             {"$set":{'updatedOn':to_java_date(datetime.now())}},upsert=False,multi=True)
-
 
660
        return {1:"Document deleted successfully"}
-
 
661
    except Exception as e:
-
 
662
        print e
-
 
663
        return {0:"Document not deleted."}
-
 
664
    
-
 
665
 
595
 
666
 
596
def main():
667
def main():
597
    x = getNewDeals(1, 0, 0, 500, None, None)
668
    x = getNewDeals(1, 0, 0, 500, None, None)
598
    for i in x:
669
    for i in x:
599
        print i['_id'],
670
        print i['_id'],