Subversion Repositories SmartDukaan

Rev

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

Rev 14427 Rev 14439
Line 19... Line 19...
19
DB_HOST = "localhost"
19
DB_HOST = "localhost"
20
DB_USER = "root"
20
DB_USER = "root"
21
DB_PASSWORD = "shop2020"
21
DB_PASSWORD = "shop2020"
22
DB_NAME = "dtr"
22
DB_NAME = "dtr"
23
xstr = lambda s: '' if s is None else str(s)
23
xstr = lambda s: '' if s is None else str(s)
-
 
24
connection = None
24
def getDbConnection():
25
def getDbConnection():
25
    return MySQLdb.connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
26
    connection = MySQLdb.connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME)
26
 
27
 
27
 
28
 
28
ORDERS_QUERY='''
29
ORDERS_QUERY='''
29
select * from order_view order by id desc limit %s offset %s
30
select * from order_view order by id desc limit %s offset %s
30
'''
31
'''
Line 34... Line 35...
34
'''
35
'''
35
 
36
 
36
ORDER_HTML_QUERY = '''
37
ORDER_HTML_QUERY = '''
37
select rawhtml from orders where id = %s
38
select rawhtml from orders where id = %s
38
'''
39
'''
39
conn = getDbConnection()
-
 
40
 
40
 
41
 
41
 
42
def getOrders(page=1, window=50):
42
def getOrders(page=1, window=50):
-
 
43
    try:
-
 
44
        conn = getDbConnection()
43
    if page==None:
45
        if page==None:
44
        page = 1
46
            page = 1
45
    if window==None:
47
        if window==None:
46
        window = 50
48
            window = 50
47
    skip = (page-1)*window
49
        skip = (page-1)*window
48
    # prepare a cursor object using cursor() method
50
        # prepare a cursor object using cursor() method
49
    cursor = conn.cursor()
51
        cursor = conn.cursor()
50
    # Execute the SQL command
52
        # Execute the SQL command
51
    # Fetch source id.
53
        # Fetch source id.
52
    cursor.execute(ORDERS_COUNT_QUERY)
54
        cursor.execute(ORDERS_COUNT_QUERY)
53
    result = cursor.fetchall()
55
        result = cursor.fetchall()
54
    total_count = result[0][0]
56
        total_count = result[0][0]
55
    pages = total_count/window + (0 if total_count%window==0 else 1)
57
        pages = total_count/window + (0 if total_count%window==0 else 1)
56
    
58
        
57
    query = ORDERS_QUERY%(window,skip)
59
        query = ORDERS_QUERY%(window,skip)
58
    cursor.execute(query)
60
        cursor.execute(query)
59
    result = cursor.fetchall()
61
        result = cursor.fetchall()
60
    template = "<html><head><style>td,th{border:1px solid;padding:2px}</style></head><div>Total Orders: %s</div><br/><body><table style='font-size:12px;border:1px solid grey;border-spacing:0;cell-spacing:0;border-bottom:1px solid grey;border-bottom:1px solid transparent'>%s</table></body></html>"
62
        template = "<html><head><style>td,th{border:1px solid;padding:2px}</style></head><div>Total Orders: %s</div><br/><body><table style='font-size:12px;border:1px solid grey;border-spacing:0;cell-spacing:0;border-bottom:1px solid grey;border-bottom:1px solid transparent'>%s</table></body></html>"
61
    tbodyarr = []
63
        tbodyarr = []
62
    colhead="<tr><th>Id</th><th>User Id</th><th>Store Id</th><th>Order Url</th><th>Subtag</th><th>Statu</th><th>Created on</th></tr>"
64
        colhead="<tr><th>Id</th><th>User Id</th><th>Store Id</th><th>Order Url</th><th>Subtag</th><th>Statu</th><th>Created on</th></tr>"
63
    tbodyarr.append(colhead)
65
        tbodyarr.append(colhead)
64
    for row in result:
66
        for row in result:
65
        tbodyarr.append("<tr><td>" + xstr(row[0]) + "</td><td>" + xstr(row[1]) +"</td><td>" + xstr(row[2]) +"</td><td><a target='_blank' href='/rawhtml/" + xstr(row[0]) + "'>" + xstr(row[3])[:90] +"</a></td><td>" + xstr(row[4]) + "</td><td>" + row[5][:15]+ "</td><td>" + row[6].strftime("%Y-%m-%d %H:%M:%S") + "</td></tr>")
67
            tbodyarr.append("<tr><td>" + xstr(row[0]) + "</td><td>" + xstr(row[1]) +"</td><td>" + xstr(row[2]) +"</td><td><a target='_blank' href='/rawhtml/" + xstr(row[0]) + "'>" + xstr(row[3])[:90] +"</a></td><td>" + xstr(row[4]) + "</td><td>" + row[5][:15]+ "</td><td>" + row[6].strftime("%Y-%m-%d %H:%M:%S") + "</td></tr>")
66
    
68
        
67
    return template%(total_count, "".join(tbodyarr))    
69
        return template%(total_count, "".join(tbodyarr))    
68
    cursor.close()
70
    finally:
69
    
71
        conn.close()
70
def getOrderHtml(orderId):
72
def getOrderHtml(orderId):
-
 
73
    try:
-
 
74
        conn = getDbConnection()
71
    cursor = conn.cursor()
75
        cursor = conn.cursor()
72
    # Execute the SQL command
76
        # Execute the SQL command
73
    # Fetch source id.
77
        # Fetch source id.
74
    cursor.execute(ORDER_HTML_QUERY%(orderId))
78
        cursor.execute(ORDER_HTML_QUERY%(orderId))
75
    result = cursor.fetchall()
79
        result = cursor.fetchall()
76
    return result[0][0]
80
        return result[0][0]
-
 
81
    finally:
-
 
82
        conn.close()
77
 
83
 
78
def main():
84
def main():
79
    print getOrders()
85
    print getOrders()
80
 
86
 
81
 
87