Subversion Repositories SmartDukaan

Rev

Rev 13572 | Rev 13603 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13572 kshitij.so 1
import pymongo
2
from datetime import datetime
3
from dtr.utils.utils import to_java_date 
4
 
5
con = None
6
 
7
def get_mongo_connection(host='localhost', port=27017):
8
    global con
9
    if con is None:
10
        print "Establishing connection %s host and port %d" %(host,port)
11
        try:
12
            con = pymongo.MongoClient(host, port)
13
        except Exception, e:
14
            print e
15
            return None
16
    return con
17
 
18
def addCategoryDiscount(data):
19
    collection = get_mongo_connection().Dtr.CategoryDiscount
20
    query = []
21
    data['brand'] = data['brand'].strip().upper()
22
    query.append({"brand":data['brand']})
23
    query.append({"category_id":data['category_id']})
24
    r = collection.find({"$and":query})
25
    if r.count() > 0:
26
        return {"0":"Brand & Category info already present."}
27
    else:
28
        collection.insert(data)
29
        return {"1":"Data added successfully"}
30
 
31
def getAllCategoryDiscount():
32
    data = []
33
    collection = get_mongo_connection().Dtr.CategoryDiscount
34
    cursor = collection.find()
35
    for val in cursor:
36
        data.append(val)
37
    return data
38
 
39
def addSchemeDetailsForSku(data):
40
    collection = get_mongo_connection().Dtr.SkuSchemeDetails
41
    data['addedOn'] = to_java_date(datetime.now())
42
    collection.insert(data)
43
    return {"1":"Data added successfully"}
44
 
45
def getAllSkuWiseSchemeDetails():
46
    data = []
47
    collection = get_mongo_connection().Dtr.SkuSchemeDetails
48
    cursor = collection.find()
49
    for val in cursor:
50
        data.append(val)
51
    return data
52
 
53
def addSkuDiscountInfo(data):
54
    collection = get_mongo_connection().Dtr.SkuDiscountInfo
55
    cursor = collection.find({"sku":data['sku']})
56
    if cursor.count > 0:
57
        return {"0":"Sku information already present."}
58
    else:
59
        collection.insert(data)
60
        return {"1":"Data added successfully"}
61
 
62
def getallSkuDiscountInfo():
63
    data = []
64
    collection = get_mongo_connection().Dtr.SkuDiscountInfo
65
    cursor = collection.find()
66
    for val in cursor:
67
        data.append(val)
68
    return data
69
 
70
def addExceptionalNlc(data):
71
    collection = get_mongo_connection().Dtr.ExceptionalNlc
72
    cursor = collection.find({"sku":data['sku']})
73
    if cursor.count > 0:
74
        return {"0":"Sku information already present."}
75
    else:
76
        collection.insert(data)
77
        return {"1":"Data added successfully"}
78
 
79
def getAllExceptionlNlcItems():
80
    data = []
81
    collection = get_mongo_connection().Dtr.SkuDiscountInfo
82
    cursor = collection.find()
83
    for val in cursor:
84
        data.append(val)
85
    return data
86
 
13582 amit.gupta 87
def getMerchantOrdersByUser(userId, page=1, window=50):
88
    data = []
89
    skip = (page-1)*window
90
    collection = get_mongo_connection().dtr.merchantOrder
91
    cursor = collection.find({"userId":userId}, {"limit":window, "skip":skip})
92
 
13572 kshitij.so 93
def main():
94
    pass
95
 
96
if __name__=='__main__':
97
    main()