Subversion Repositories SmartDukaan

Rev

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

Rev 16753 Rev 16754
Line 236... Line 236...
236
    result = {}
236
    result = {}
237
    skip = (page-1)*window
237
    skip = (page-1)*window
238
    con = get_mongo_connection()
238
    con = get_mongo_connection()
239
    collection = con.Dtr.refund
239
    collection = con.Dtr.refund
240
    user = con.Dtr.user
240
    user = con.Dtr.user
241
    credited = user.find({"userId":userId}).get("credited")
241
    credited = user.find_one({"userId":userId})
242
    if not credited:
242
    if credited:
-
 
243
        credited = credited.get("credited")
-
 
244
    else:
243
        credited = 0
245
        credited=0
-
 
246
        
244
    cursor = collection.find({"userId":userId})
247
    cursor = collection.find({"userId":userId})
245
    total_count = cursor.count()
248
    total_count = cursor.count()
246
    pages = total_count/window + (0 if total_count%window==0 else 1)  
249
    pages = total_count/window + (0 if total_count%window==0 else 1)  
247
    print "total_count", total_count
250
    print "total_count", total_count
248
    if total_count > skip:
251
    if total_count > skip:
249
        cursor = cursor.skip(skip).limit(window).sort([('batch',-1)])
252
        cursor = cursor.skip(skip).limit(window).sort([('batch',-1)])
250
        refunds = []
253
        refunds = []
251
        for refund in cursor:
254
        for refund in cursor:
252
            del(refund["_id"])
255
            del(refund["_id"])
253
            refunds.append(refund)
256
            refunds.append(refund)
254
        result['credited'] = 0
257
        result['credited'] = credited
255
        result['data'] = refunds
258
        result['data'] = refunds
256
        result['window'] = window
259
        result['window'] = window
257
        result['totalCount'] = total_count 
260
        result['totalCount'] = total_count 
258
        result['currCount'] = cursor.count()
261
        result['currCount'] = cursor.count()
259
        result['totalPages'] = pages
262
        result['totalPages'] = pages