Subversion Repositories SmartDukaan

Rev

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

Rev 13582 Rev 13603
Line 83... Line 83...
83
    for val in cursor:
83
    for val in cursor:
84
        data.append(val)
84
        data.append(val)
85
    return data
85
    return data
86
 
86
 
87
def getMerchantOrdersByUser(userId, page=1, window=50):
87
def getMerchantOrdersByUser(userId, page=1, window=50):
-
 
88
    if page==None:
-
 
89
        page = 1
-
 
90
        
-
 
91
    if window==None:
-
 
92
        window = 50
88
    data = []
93
    result = {}
89
    skip = (page-1)*window
94
    skip = (page-1)*window
90
    collection = get_mongo_connection().dtr.merchantOrder
95
    collection = get_mongo_connection().Dtr.merchantOrder
91
    cursor = collection.find({"userId":userId}, {"limit":window, "skip":skip})
96
    cursor = collection.find({"userId":userId})
-
 
97
    total_count = cursor.count()
-
 
98
    pages = total_count/window + (0 if total_count%window==0 else 1)  
-
 
99
    print "total_count", total_count
-
 
100
    if total_count > skip:
-
 
101
        cursor = cursor.skip(skip).limit(window)
-
 
102
        orders = []
-
 
103
        for order in cursor:
-
 
104
            del(order["_id"])
-
 
105
            orders.append(order)
-
 
106
        result['data'] = orders
-
 
107
        result['window'] = window
-
 
108
        result['totalCount'] = total_count 
-
 
109
        result['currCount'] = cursor.count()
-
 
110
        result['totalPages'] = pages
-
 
111
        result['currPage'] = page    
-
 
112
        return result
92
 
113
    else:
-
 
114
        return result
93
def main():
115
def main():
94
    pass
116
    pass
95
    
117
    
96
if __name__=='__main__':
118
if __name__=='__main__':
97
    main()
119
    main()
98
120