Rev 13582 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
import pymongofrom datetime import datetimefrom dtr.utils.utils import to_java_datecon = Nonedef get_mongo_connection(host='localhost', port=27017):global conif con is None:print "Establishing connection %s host and port %d" %(host,port)try:con = pymongo.MongoClient(host, port)except Exception, e:print ereturn Nonereturn condef addCategoryDiscount(data):collection = get_mongo_connection().Dtr.CategoryDiscountquery = []data['brand'] = data['brand'].strip().upper()query.append({"brand":data['brand']})query.append({"category_id":data['category_id']})r = collection.find({"$and":query})if r.count() > 0:return {"0":"Brand & Category info already present."}else:collection.insert(data)return {"1":"Data added successfully"}def getAllCategoryDiscount():data = []collection = get_mongo_connection().Dtr.CategoryDiscountcursor = collection.find()for val in cursor:data.append(val)return datadef addSchemeDetailsForSku(data):collection = get_mongo_connection().Dtr.SkuSchemeDetailsdata['addedOn'] = to_java_date(datetime.now())collection.insert(data)return {"1":"Data added successfully"}def getAllSkuWiseSchemeDetails():data = []collection = get_mongo_connection().Dtr.SkuSchemeDetailscursor = collection.find()for val in cursor:data.append(val)return datadef addSkuDiscountInfo(data):collection = get_mongo_connection().Dtr.SkuDiscountInfocursor = collection.find({"sku":data['sku']})if cursor.count > 0:return {"0":"Sku information already present."}else:collection.insert(data)return {"1":"Data added successfully"}def getallSkuDiscountInfo():data = []collection = get_mongo_connection().Dtr.SkuDiscountInfocursor = collection.find()for val in cursor:data.append(val)return datadef addExceptionalNlc(data):collection = get_mongo_connection().Dtr.ExceptionalNlccursor = collection.find({"sku":data['sku']})if cursor.count > 0:return {"0":"Sku information already present."}else:collection.insert(data)return {"1":"Data added successfully"}def getAllExceptionlNlcItems():data = []collection = get_mongo_connection().Dtr.SkuDiscountInfocursor = collection.find()for val in cursor:data.append(val)return datadef main():passif __name__=='__main__':main()