Subversion Repositories SmartDukaan

Rev

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

Rev 15459 Rev 15853
Line 20... Line 20...
20
DataService.initialize(db_hostname="localhost")
20
DataService.initialize(db_hostname="localhost")
21
mc = MemCache("127.0.0.1")
21
mc = MemCache("127.0.0.1")
22
 
22
 
23
SOURCE_MAP = {1:'AMAZON',2:'FLIPKART',3:'SNAPDEAL',4:'SAHOLIC'}
23
SOURCE_MAP = {1:'AMAZON',2:'FLIPKART',3:'SNAPDEAL',4:'SAHOLIC'}
24
 
24
 
-
 
25
COLLECTION_MAP = {
-
 
26
                  'ExceptionalNlc':'skuBundleId',
-
 
27
                  'SkuDealerPrices':'skuBundleId',
-
 
28
                  'SkuDiscountInfo':'skuBundleId',
-
 
29
                  'SkuSchemeDetails':'skuBundleId',
-
 
30
                  
-
 
31
                  }
-
 
32
 
25
def get_mongo_connection(host='localhost', port=27017):
33
def get_mongo_connection(host='localhost', port=27017):
26
    global con
34
    global con
27
    if con is None:
35
    if con is None:
28
        print "Establishing connection %s host and port %d" %(host,port)
36
        print "Establishing connection %s host and port %d" %(host,port)
29
        try:
37
        try:
Line 97... Line 105...
97
    if masterData is not None:
105
    if masterData is not None:
98
        return list(get_mongo_connection().Catalog.MasterData.find({"skuBundleId":masterData.get('skuBundleId')},{'_id':1,'skuBundleId':1}))
106
        return list(get_mongo_connection().Catalog.MasterData.find({"skuBundleId":masterData.get('skuBundleId')},{'_id':1,'skuBundleId':1}))
99
    else:
107
    else:
100
        return []
108
        return []
101
 
109
 
102
def addSchemeDetailsForSku(data, multi):
110
def addSchemeDetailsForSku(data):
103
    if multi ==1:
-
 
104
        skuIds = __getBundledSkusfromSku(data['sku'])
-
 
105
        for sku in skuIds:
-
 
106
            collection = get_mongo_connection().Catalog.SkuSchemeDetails
111
    collection = get_mongo_connection().Catalog.SkuSchemeDetails
107
            data['sku'] = sku.get('_id')
-
 
108
            data['addedOn'] = to_java_date(datetime.now())
-
 
109
            data.pop('_id',None)
-
 
110
            collection.insert(data)
112
    result = collection.find_one({'skuBundleId':data['skuBundleId']})
111
        get_mongo_connection().Catalog.MasterData.update({'skuBundleId':sku.get('skuBundleId')},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
-
 
112
        return {1:"Data added successfully"}
-
 
113
    else:
113
    if result is None:
114
        collection = get_mongo_connection().Catalog.SkuSchemeDetails
-
 
115
        data['addedOn'] = to_java_date(datetime.now())
-
 
116
        collection.insert(data)
114
        collection.insert(data)
117
        get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
115
        get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
118
        return {1:"Data added successfully"}
116
        return {1:"Data added successfully"}
-
 
117
    return {1:"BundleId info already present"}
119
 
118
    
120
def getAllSkuWiseSchemeDetails(offset, limit):
119
def getAllSkuWiseSchemeDetails(offset, limit):
121
    data = []
120
    data = []
122
    collection = get_mongo_connection().Catalog.SkuSchemeDetails
121
    collection = get_mongo_connection().Catalog.SkuSchemeDetails
123
    cursor = collection.find().skip(offset).limit(limit)
122
    cursor = collection.find().skip(offset).limit(limit)
124
    for val in cursor:
123
    for val in cursor:
125
        master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
124
        master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':val['skuBundleId']})
126
        if len(master) > 0:
125
        if master is not None:
127
            val['brand'] = master[0]['brand']
126
            val['brand'] = master['brand']
128
            val['source_product_name'] = master[0]['source_product_name']
127
            val['source_product_name'] = master['source_product_name']
129
            val['skuBundleId'] = master[0]['skuBundleId']
-
 
130
        else:
128
        else:
131
            val['brand'] = ""
129
            val['brand'] = ""
132
            val['source_product_name'] = ""
130
            val['source_product_name'] = ""
133
            val['skuBundleId'] = ""
-
 
134
        data.append(val)
131
        data.append(val)
135
    return data
132
    return data
136
 
133
 
137
def addSkuDiscountInfo(data, multi):
134
def addSkuDiscountInfo(data):
138
    if multi != 1:
-
 
139
        collection = get_mongo_connection().Catalog.SkuDiscountInfo
135
    collection = get_mongo_connection().Catalog.SkuDiscountInfo
140
        cursor = collection.find({"sku":data['sku']})
136
    cursor = collection.find_one({"skuBundleId":data['skuBundleId']})
141
        if cursor.count() > 0:
137
    if cursor is not None:
142
            return {0:"Sku information already present."}
138
        return {0:"BundleId information already present."}
143
        else:
-
 
144
            collection.insert(data)
-
 
145
            get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
-
 
146
            return {1:"Data added successfully"}
-
 
147
    else:
139
    else:
148
        skuIds = __getBundledSkusfromSku(data['sku'])
-
 
149
        for sku in skuIds:
-
 
150
            data['sku'] = sku.get('_id')
-
 
151
            collection = get_mongo_connection().Catalog.SkuDiscountInfo
-
 
152
            cursor = collection.find({"sku":data['sku']})
-
 
153
            if cursor.count() > 0:
-
 
154
                continue
-
 
155
            else:
-
 
156
                data.pop('_id',None)
-
 
157
                collection.insert(data)
140
        collection.insert(data)
158
        get_mongo_connection().Catalog.MasterData.update({'skuBundleId':sku.get('skuBundleId')},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
141
        get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
159
        return {1:"Data added successfully"}
142
        return {1:"Data added successfully"}
160
 
143
 
161
def getallSkuDiscountInfo(offset, limit):
144
def getallSkuDiscountInfo(offset, limit):
162
    data = []
145
    data = []
163
    collection = get_mongo_connection().Catalog.SkuDiscountInfo
146
    collection = get_mongo_connection().Catalog.SkuDiscountInfo
164
    cursor = collection.find().skip(offset).limit(limit)
147
    cursor = collection.find().skip(offset).limit(limit)
165
    for val in cursor:
148
    for val in cursor:
166
        master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
149
        master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':val['skuBundleId']})
167
        if len(master) > 0:
150
        if master is not None:
168
            val['brand'] = master[0]['brand']
151
            val['brand'] = master['brand']
169
            val['source_product_name'] = master[0]['source_product_name']
152
            val['source_product_name'] = master['source_product_name']
170
            val['skuBundleId'] = master[0]['skuBundleId']
-
 
171
        else:
153
        else:
172
            val['brand'] = ""
154
            val['brand'] = ""
173
            val['source_product_name'] = ""
155
            val['source_product_name'] = ""
174
            val['skuBundleId'] = ""
-
 
175
        data.append(val)
156
        data.append(val)
176
    return data
157
    return data
177
 
158
 
178
def updateSkuDiscount(data,_id):
159
def updateSkuDiscount(data,_id):
179
    try:
160
    try:
180
        collection = get_mongo_connection().Catalog.SkuDiscountInfo
161
        collection = get_mongo_connection().Catalog.SkuDiscountInfo
181
        collection.update({'_id':ObjectId(_id)},{"$set":{'min_discount':data['min_discount'],'max_discount':data['max_discount'],'discountType':data['discountType'].upper().strip()}},upsert=False, multi = False)
162
        collection.update({'_id':ObjectId(_id)},{"$set":{'min_discount':data['min_discount'],'max_discount':data['max_discount'],'discountType':data['discountType'].upper().strip()}},upsert=False, multi = False)
182
        get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
163
        get_mongo_connection().Catalog.MasterData.update({'_id':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
183
        return {1:"Data updated successfully"}
164
        return {1:"Data updated successfully"}
184
    except:
165
    except:
185
        return {0:"Data not updated."}
166
        return {0:"Data not updated."}
186
 
167
 
187
 
168
 
188
def addExceptionalNlc(data, multi):
169
def addExceptionalNlc(data):
189
    if multi!=1:
-
 
190
        collection = get_mongo_connection().Catalog.ExceptionalNlc
170
    collection = get_mongo_connection().Catalog.ExceptionalNlc
191
        cursor = collection.find({"sku":data['sku']})
171
    cursor = collection.find_one({"skuBundleId":data['skuBundleId']})
192
        if cursor.count() > 0:
172
    if cursor is not None:
193
            return {0:"Sku information already present."}
173
        return {0:"BundleId information already present."}
194
        else:
-
 
195
            collection.insert(data)
-
 
196
            get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
-
 
197
            return {1:"Data added successfully"}
-
 
198
    else:
174
    else:
199
        skuIds = __getBundledSkusfromSku(data['sku'])
-
 
200
        for sku in skuIds:
-
 
201
            data['sku'] = sku.get('_id')
-
 
202
            collection = get_mongo_connection().Catalog.ExceptionalNlc
-
 
203
            cursor = collection.find({"sku":data['sku']})
-
 
204
            if cursor.count() > 0:
-
 
205
                continue
-
 
206
            else:
-
 
207
                data.pop('_id',None)
-
 
208
                collection.insert(data)
175
        collection.insert(data)
209
        get_mongo_connection().Catalog.MasterData.update({'skuBundleId':sku.get('skuBundleId')},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
176
        get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
210
        return {1:"Data added successfully"}
177
        return {1:"Data added successfully"}
211
 
178
 
212
def getAllExceptionlNlcItems(offset, limit):
179
def getAllExceptionlNlcItems(offset, limit):
213
    data = []
180
    data = []
214
    collection = get_mongo_connection().Catalog.ExceptionalNlc
181
    collection = get_mongo_connection().Catalog.ExceptionalNlc
215
    cursor = collection.find().skip(offset).limit(limit)
182
    cursor = collection.find().skip(offset).limit(limit)
216
    for val in cursor:
183
    for val in cursor:
217
        master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
184
        master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':val['skuBundleId']})
218
        if len(master) > 0:
185
        if master is not None:
219
            val['brand'] = master[0]['brand']
186
            val['brand'] = master['brand']
220
            val['source_product_name'] = master[0]['source_product_name']
187
            val['source_product_name'] = master['source_product_name']
221
            val['skuBundleId'] = master[0]['skuBundleId']
-
 
222
        else:
188
        else:
223
            val['brand'] = ""
189
            val['brand'] = ""
224
            val['source_product_name'] = ""
190
            val['source_product_name'] = ""
225
            val['skuBundleId'] = ""
-
 
226
        data.append(val)
191
        data.append(val)
227
    return data
192
    return data
228
 
193
 
229
def getMerchantOrdersByUser(userId, page=1, window=50, searchMap={}):
194
def getMerchantOrdersByUser(userId, page=1, window=50, searchMap={}):
230
    if searchMap is None:
195
    if searchMap is None:
Line 651... Line 616...
651
    
616
    
652
 
617
 
653
def getCashBackDetails(identifier, source_id):
618
def getCashBackDetails(identifier, source_id):
654
    if not bool(mc.get("category_cash_back")):
619
    if not bool(mc.get("category_cash_back")):
655
        populateCashBack()
620
        populateCashBack()
656
        
-
 
657
    """Need to add item level cashback, no data available right now."""
-
 
658
    
621
    
659
    if source_id in (1,2,4,5):
622
    if source_id in (1,2,4,5):
660
        skuData = list(get_mongo_connection().Catalog.MasterData.find({'identifier':identifier.strip(), 'source_id':source_id}))
623
        skuData = list(get_mongo_connection().Catalog.MasterData.find({'identifier':identifier.strip(), 'source_id':source_id}))
661
    elif source_id == 3:
624
    elif source_id == 3:
662
        skuData = list(get_mongo_connection().Catalog.MasterData.find({'secondaryIdentifier':identifier.strip(), 'source_id':source_id}))
625
        skuData = list(get_mongo_connection().Catalog.MasterData.find({'secondaryIdentifier':identifier.strip(), 'source_id':source_id}))
Line 701... Line 664...
701
def getAllDealerPrices(offset, limit):
664
def getAllDealerPrices(offset, limit):
702
    data = []
665
    data = []
703
    collection = get_mongo_connection().Catalog.SkuDealerPrices
666
    collection = get_mongo_connection().Catalog.SkuDealerPrices
704
    cursor = collection.find().skip(offset).limit(limit)
667
    cursor = collection.find().skip(offset).limit(limit)
705
    for val in cursor:
668
    for val in cursor:
706
        master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
669
        master = get_mongo_connection().Catalog.MasterData.find_one({'skuBundleId':val['skuBundleId']})
707
        if len(master) > 0:
670
        if master is not None:
708
            val['brand'] = master[0]['brand']
671
            val['brand'] = master['brand']
709
            val['source_product_name'] = master[0]['source_product_name']
672
            val['source_product_name'] = master['source_product_name']
710
            val['skuBundleId'] = master[0]['skuBundleId']
-
 
711
        else:
673
        else:
712
            val['brand'] = ""
674
            val['brand'] = ""
713
            val['source_product_name'] = ""
675
            val['source_product_name'] = ""
714
            val['skuBundleId'] = ""
-
 
715
        data.append(val)
676
        data.append(val)
716
    return data
677
    return data
717
 
678
 
718
def addSkuDealerPrice(data, multi):
679
def addSkuDealerPrice(data):
719
    if multi != 1:
-
 
720
        collection = get_mongo_connection().Catalog.SkuDealerPrices
680
    collection = get_mongo_connection().Catalog.SkuDealerPrices
721
        cursor = collection.find({"sku":data['sku']})
681
    cursor = collection.find_one({"skuBundleId":data['skuBundleId']})
722
        if cursor.count() > 0:
682
    if cursor is not None:
723
            return {0:"Sku information already present."}
683
        return {0:"BundleId information already present."}
724
        else:
-
 
725
            collection.insert(data)
-
 
726
            get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
-
 
727
            return {1:"Data added successfully"}
-
 
728
    else:
684
    else:
729
        skuIds = __getBundledSkusfromSku(data['sku'])
-
 
730
        for sku in skuIds:
-
 
731
            data['sku'] = sku.get('_id')
-
 
732
            collection = get_mongo_connection().Catalog.SkuDealerPrices
-
 
733
            cursor = collection.find({"sku":data['sku']})
-
 
734
            if cursor.count() > 0:
-
 
735
                continue
-
 
736
            else:   
-
 
737
                data.pop('_id',None)
-
 
738
                collection.insert(data)
685
        collection.insert(data)
739
        get_mongo_connection().Catalog.MasterData.update({'skuBundleId':sku.get('skuBundleId')},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
686
        get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
740
        return {1:"Data added successfully"}
687
        return {1:"Data added successfully"}
741
        
-
 
742
        
-
 
743
 
688
 
744
def updateSkuDealerPrice(data, _id):
689
def updateSkuDealerPrice(data, _id):
745
    try:
690
    try:
746
        collection = get_mongo_connection().Catalog.SkuDealerPrices
691
        collection = get_mongo_connection().Catalog.SkuDealerPrices
747
        collection.update({'_id':ObjectId(_id)},{"$set":{'dp':data['dp']}},upsert=False, multi = False)
692
        collection.update({'_id':ObjectId(_id)},{"$set":{'dp':data['dp']}},upsert=False, multi = False)
748
        get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
693
        get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
749
        return {1:"Data updated successfully"}
694
        return {1:"Data updated successfully"}
750
    except:
695
    except:
751
        return {0:"Data not updated."}
696
        return {0:"Data not updated."}
752
 
697
 
753
def updateExceptionalNlc(data, _id):
698
def updateExceptionalNlc(data, _id):
754
    try:
699
    try:
755
        collection = get_mongo_connection().Catalog.ExceptionalNlc
700
        collection = get_mongo_connection().Catalog.ExceptionalNlc
756
        collection.update({'_id':ObjectId(_id)},{"$set":{'maxNlc':data['maxNlc'], 'minNlc':data['minNlc'], 'overrideNlc':data['overrideNlc']}},upsert=False, multi = False)
701
        collection.update({'_id':ObjectId(_id)},{"$set":{'maxNlc':data['maxNlc'], 'minNlc':data['minNlc'], 'overrideNlc':data['overrideNlc']}},upsert=False, multi = False)
757
        get_mongo_connection().Catalog.MasterData.update({'_id':data['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=False)
702
        get_mongo_connection().Catalog.MasterData.update({'skuBundleId':data['skuBundleId']},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
758
        return {1:"Data updated successfully"}
703
        return {1:"Data updated successfully"}
759
    except:
704
    except:
760
        return {0:"Data not updated."}
705
        return {0:"Data not updated."}
761
 
706
 
762
def resetCache(userId):
707
def resetCache(userId):
Line 764... Line 709...
764
        mc.delete(userId)
709
        mc.delete(userId)
765
        return {1:'Cache cleared.'}
710
        return {1:'Cache cleared.'}
766
    except:
711
    except:
767
        return {0:'Unable to clear cache.'}
712
        return {0:'Unable to clear cache.'}
768
    
713
    
769
def updateCollection(data, multi):
714
def updateCollection(data):
770
    print data
715
    print data
771
    if multi!=1:
-
 
772
        try:
716
    try:
773
            collection = get_mongo_connection().Catalog[data['class']]
717
        collection = get_mongo_connection().Catalog[data['class']]
774
            class_name = data.pop('class')
718
        class_name = data.pop('class')
775
            if class_name == "SkuSchemeDetails":
-
 
776
                data['addedOn'] = to_java_date(datetime.now())
-
 
777
            _id = data.pop('oid')
719
        _id = data.pop('oid')
778
            result = collection.update({'_id':ObjectId(_id)},{"$set":data},upsert=False, multi = False)
720
        result = collection.update({'_id':ObjectId(_id)},{"$set":data},upsert=False, multi = False)
779
            if class_name != "Notifications":
721
        if class_name != "Notifications":
780
                record = list(collection.find({'_id':ObjectId(_id)}))
-
 
781
                if class_name !="CategoryDiscount":
-
 
782
                    get_mongo_connection().Catalog.MasterData.update({'_id':record[0]['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}})
-
 
783
                else:
-
 
784
                    get_mongo_connection().Catalog.MasterData.update({'brand':re.compile(record[0]['brand'], re.IGNORECASE),'category_id':record[0]['category_id']}, \
-
 
785
                                                                     {"$set":{'updatedOn':to_java_date(datetime.now())}},upsert=False,multi=True)
-
 
786
            return {1:"Data updated successfully"}
-
 
787
        except Exception as e:
-
 
788
            print e
-
 
789
            return {0:"Data not updated."}
-
 
790
    else:
-
 
791
        try:
-
 
792
            collection = get_mongo_connection().Catalog[data['class']]
-
 
793
            class_name = data.pop('class')
-
 
794
            _id = data.pop('oid')
-
 
795
            record = list(collection.find({'_id':ObjectId(_id)}))
722
            record = list(collection.find({'_id':ObjectId(_id)}))
796
            skuIds = __getBundledSkusfromSku(record[0]['sku'])
723
            if class_name !="CategoryDiscount":
797
            for sku in skuIds:
724
                if record[0].has_key('sku'):
798
                if class_name == "SkuSchemeDetails":
725
                    field = '_id'
799
                    data['addedOn'] = to_java_date(datetime.now())
726
                    val = record[0]['sku']
-
 
727
                else:
800
                data['sku'] = sku.get('_id')
728
                    field = 'skuBundleId'
801
                data.pop('_id',None)
729
                    val = record[0]['skuBundleId']
802
                collection.update({'sku':sku.get('_id')},{"$set":data},upsert=False,multi=False)
730
                get_mongo_connection().Catalog.MasterData.update({field:val},{"$set":{'updatedOn':to_java_date(datetime.now())}},upsert=False, multi = True)
-
 
731
            else:
803
            get_mongo_connection().Catalog.MasterData.update({'skuBundleId':sku.get('skuBundleId')},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
732
                get_mongo_connection().Catalog.MasterData.update({'brand':re.compile(record[0]['brand'], re.IGNORECASE),'category_id':record[0]['category_id']}, \
-
 
733
                                                                 {"$set":{'updatedOn':to_java_date(datetime.now())}},upsert=False,multi=True)
804
            return {1:"Data updatedsuccessfully"}
734
        return {1:"Data updated successfully"}
805
        except Exception as e:
735
    except Exception as e:
806
            print e
736
        print e
807
            return {0:"Data not updated."}
737
        return {0:"Data not updated."}
808
        
738
        
809
    
739
    
810
def addNegativeDeals(data, multi):
740
def addNegativeDeals(data, multi):
811
    if multi !=1: 
741
    if multi !=1: 
812
        collection = get_mongo_connection().Catalog.NegativeDeals
742
        collection = get_mongo_connection().Catalog.NegativeDeals
Line 886... Line 816...
886
                collection.insert(data)
816
                collection.insert(data)
887
        get_mongo_connection().Catalog.MasterData.update({'skuBundleId':sku.get('skuBundleId')},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
817
        get_mongo_connection().Catalog.MasterData.update({'skuBundleId':sku.get('skuBundleId')},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
888
        return {1:"Data added successfully"}
818
        return {1:"Data added successfully"}
889
        
819
        
890
def deleteDocument(data):
820
def deleteDocument(data):
-
 
821
    print "inside detete document"
891
    print data
822
    print data
892
    try:
823
    try:
893
        collection = get_mongo_connection().Catalog[data['class']]
824
        collection = get_mongo_connection().Catalog[data['class']]
894
        class_name = data.pop('class')
825
        class_name = data.pop('class')
895
        _id = data.pop('oid')
826
        _id = data.pop('oid')
896
        record = list(collection.find({'_id':ObjectId(_id)}))
827
        record = list(collection.find({'_id':ObjectId(_id)}))
897
        collection.remove({'_id':ObjectId(_id)})
828
        collection.remove({'_id':ObjectId(_id)})
898
        if class_name != "Notifications":
829
        if class_name != "Notifications":
899
            if class_name !="CategoryDiscount":
830
            if class_name !="CategoryDiscount":
-
 
831
                print record[0]
-
 
832
                if record[0].has_key('sku'):
-
 
833
                    field = '_id'
-
 
834
                    val = record[0]['sku']
-
 
835
                else:
-
 
836
                    field = 'skuBundleId'
-
 
837
                    val = record[0]['skuBundleId']
-
 
838
                print "Updating master"
-
 
839
                print field
-
 
840
                print val
900
                get_mongo_connection().Catalog.MasterData.update({'_id':record[0]['sku']},{"$set":{'updatedOn':to_java_date(datetime.now())}})
841
                get_mongo_connection().Catalog.MasterData.update({field:val},{"$set":{'updatedOn':to_java_date(datetime.now())}},multi=True)
901
            else:
842
            else:
902
                get_mongo_connection().Catalog.MasterData.update({'brand':re.compile(record[0]['brand'], re.IGNORECASE),'category_id':record[0]['category_id']}, \
843
                get_mongo_connection().Catalog.MasterData.update({'brand':re.compile(record[0]['brand'], re.IGNORECASE),'category_id':record[0]['category_id']}, \
903
                                                                 {"$set":{'updatedOn':to_java_date(datetime.now())}},upsert=False,multi=True)
844
                                                                 {"$set":{'updatedOn':to_java_date(datetime.now())}},upsert=False,multi=True)
904
        return {1:"Document deleted successfully"}
845
        return {1:"Document deleted successfully"}
905
    except Exception as e:
846
    except Exception as e:
Line 981... Line 922...
981
                val['brand'] = ""
922
                val['brand'] = ""
982
                val['model_name'] = ""
923
                val['model_name'] = ""
983
                val['skuBundleId'] = val['skuBundleId']
924
                val['skuBundleId'] = val['skuBundleId']
984
            data.append(val)
925
            data.append(val)
985
        return data
926
        return data
-
 
927
    master = None
986
    if sku is not None:
928
    if sku is not None:
-
 
929
        if COLLECTION_MAP.has_key(class_name):
-
 
930
            master = get_mongo_connection().Catalog.MasterData.find_one({'_id':sku})
-
 
931
            cursor = collection.find({'skuBundleId':master['skuBundleId']})
-
 
932
        else:
987
        cursor = collection.find({'sku':sku})
933
            cursor = collection.find({'sku':sku})
988
        for val in cursor:
934
        for val in cursor:
-
 
935
            if master is None:
989
            master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
936
                master = get_mongo_connection().Catalog.MasterData.find_one({'_id':val['sku']})
990
            if len(master) > 0:
937
            if master is not None:
991
                val['brand'] = master[0]['brand']
938
                val['brand'] = master['brand']
992
                val['source_product_name'] = master[0]['source_product_name']
939
                val['source_product_name'] = master['source_product_name']
993
                val['skuBundleId'] = master[0]['skuBundleId']
940
                val['skuBundleId'] = master['skuBundleId']
994
            else:
941
            else:
995
                val['brand'] = ""
942
                val['brand'] = ""
996
                val['source_product_name'] = ""
943
                val['source_product_name'] = ""
997
                val['skuBundleId'] = ""
944
                val['skuBundleId'] = ""
998
            data.append(val)
945
            data.append(val)
999
        return data
946
        return data
1000
    else:
947
    else:
-
 
948
        if not COLLECTION_MAP.has_key(class_name):
1001
        skuIds = get_mongo_connection().Catalog.MasterData.find({'skuBundleId':skuBundleId}).distinct('_id')
949
            skuIds = get_mongo_connection().Catalog.MasterData.find({'skuBundleId':skuBundleId}).distinct('_id')
1002
        for sku in skuIds:
950
            for sku in skuIds:
1003
            cursor = collection.find({'sku':sku})
951
                cursor = collection.find({'sku':sku})
-
 
952
                for val in cursor:
-
 
953
                    master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
-
 
954
                    if len(master) > 0:
-
 
955
                        val['brand'] = master[0]['brand']
-
 
956
                        val['source_product_name'] = master[0]['source_product_name']
-
 
957
                        val['skuBundleId'] = master[0]['skuBundleId']
-
 
958
                    else:
-
 
959
                        val['brand'] = ""
-
 
960
                        val['source_product_name'] = ""
-
 
961
                        val['skuBundleId'] = ""
-
 
962
                    data.append(val)
-
 
963
            return data
-
 
964
        else:
-
 
965
            cursor = collection.find({'skuBundleId':skuBundleId})
1004
            for val in cursor:
966
            for val in cursor:
1005
                master = list(get_mongo_connection().Catalog.MasterData.find({'_id':val['sku']}))
967
                master = list(get_mongo_connection().Catalog.MasterData.find({'skuBundleId':val['skuBundleId']}))
1006
                if len(master) > 0:
968
                if len(master) > 0:
1007
                    val['brand'] = master[0]['brand']
969
                    val['brand'] = master[0]['brand']
1008
                    val['source_product_name'] = master[0]['source_product_name']
970
                    val['source_product_name'] = master[0]['source_product_name']
1009
                    val['skuBundleId'] = master[0]['skuBundleId']
-
 
1010
                else:
971
                else:
1011
                    val['brand'] = ""
972
                    val['brand'] = ""
1012
                    val['source_product_name'] = ""
973
                    val['source_product_name'] = ""
1013
                    val['skuBundleId'] = ""
-
 
1014
                data.append(val)
974
                data.append(val)
1015
        return data
975
            return data
1016
 
976
 
1017
def __getBrandIdForBrand(brandName, category_id):
977
def __getBrandIdForBrand(brandName, category_id):
1018
    brandInfo = Brands.query.filter(Brands.category_id==category_id).filter(Brands.name == brandName).all()
978
    brandInfo = Brands.query.filter(Brands.category_id==category_id).filter(Brands.name == brandName).all()
1019
    if brandInfo is None or len(brandInfo)!=1:
979
    if brandInfo is None or len(brandInfo)!=1:
1020
        raise
980
        raise