Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
13804 amit.gupta 1
'''
2
Created on Feb 12, 2015
3
 
4
@author: amit
5
'''
6
from dtr import main
14427 amit.gupta 7
from dtr.storage import Mongo, Mysql
14058 amit.gupta 8
import datetime
13804 amit.gupta 9
import falcon
10
import json
14014 amit.gupta 11
import urlparse
13804 amit.gupta 12
class StoreOrder():
13
    def on_post(self, req, resp):
14
 
15
        try:
16
            string1 = req.stream.read()
17
            req_json = json.loads(string1, encoding='utf-8')
18
        except ValueError:
19
            raise falcon.HTTPError(falcon.HTTP_400,
20
                'Malformed JSON',
21
                'Could not decode the request body. The '
22
                'JSON was incorrect.')
23
 
24
        store = main.getStore(int(req_json['sourceId']))
25
        result = store.parseOrderRawHtml(int(req_json['orderId']), req_json['subTagId'], int(req_json['userId']), req_json['rawHtml'], req_json['orderSuccessUrl'])
26
        resp.body = json.dumps(result, encoding='utf-8')
27
 
28
    def on_get(self, req, resp, userId):
29
        page = req.get_param_as_int("page")
30
        window = req.get_param_as_int("window")
14003 amit.gupta 31
        string1 = req.get_param("searchMap")
14004 amit.gupta 32
        searchMap={}
14006 amit.gupta 33
        if string1 is None or string1 == "":
14007 amit.gupta 34
            pass
35
        else:
14006 amit.gupta 36
            try:
14007 amit.gupta 37
                searchMap = json.loads(string1, encoding='utf-8')
14006 amit.gupta 38
            except:
39
                raise falcon.HTTPError(falcon.HTTP_400,
40
                    'Malformed JSON',
41
                    'Could not decode the request body. The '
42
                    'JSON was incorrect.')
14003 amit.gupta 43
        result = Mongo.getMerchantOrdersByUser(int(userId), page, window, searchMap)
13868 amit.gupta 44
        resp.body = json.dumps(result, encoding='utf-8')
45
 
14352 amit.gupta 46
class Orders():
47
    def on_get(self, req, resp):
48
        page = req.get_param_as_int("page")
49
        window = req.get_param_as_int("window")
50
        string1 = req.get_param("searchMap")
51
        searchMap={}
52
        if string1 is None or string1 == "":
53
            pass
54
        else:
55
            try:
56
                searchMap = json.loads(string1, encoding='utf-8')
57
            except:
58
                raise falcon.HTTPError(falcon.HTTP_400,
59
                    'Malformed JSON',
60
                    'Could not decode the request body. The '
61
                    'JSON was incorrect.')
62
        result = Mongo.getMerchantOrdersByUser(None, page, window, searchMap)
63
        resp.body = json.dumps(result, encoding='utf-8')
64
 
13868 amit.gupta 65
class Track():
13939 amit.gupta 66
    def on_post(self, req, resp, userId):
13868 amit.gupta 67
        try:
14013 amit.gupta 68
            string1 = req.stream.read()
14014 amit.gupta 69
            req_obj = urlparse.parse_qs(string1)
14013 amit.gupta 70
        except ValueError:
71
            raise falcon.HTTPError(falcon.HTTP_400,
72
                'Malformed JSON',
73
                'Could not decode the request body. The '
74
                'JSON was incorrect.')
75
        try:
13927 amit.gupta 76
            store = main.getStore(req.get_param_as_int("storeId"))
77
            if req.get_param_as_int("storeId") == 1:
14015 amit.gupta 78
                result = store.trackOrdersForUser(int(userId),req_obj['url'][0],req_obj['html'][0])
13927 amit.gupta 79
                resp.body = json.dumps({'result':result}, encoding='utf-8')
80
            else:
81
                resp.body = json.dumps({'result':'NOT_IMPLEMENTED'}, encoding='utf-8')
82
        except:
83
            resp.body = json.dumps({'result':'PARSE_ERROR'}, encoding='utf-8')
14087 amit.gupta 84
 
14096 amit.gupta 85
        print "Returned from track POST", resp.body
86
        resp.body = json.dumps({'result':'PARSE_ERROR'}, encoding='utf-8')
87
 
13868 amit.gupta 88
 
13939 amit.gupta 89
    def on_get(self, req, resp, userId):
13868 amit.gupta 90
        try:
91
            storeId = req.get_param_as_int("storeId")
13939 amit.gupta 92
            result = main.getStore(storeId).getTrackingUrls(int(userId))
13887 amit.gupta 93
            resp.body = json.dumps({'result':result}, encoding='utf-8')
13868 amit.gupta 94
        except ValueError:
95
            raise falcon.HTTPError(falcon.HTTP_400,
96
                'Malformed JSON',
97
                'Could not decode the request body. The '
98
                'JSON was incorrect.')
99
 
13927 amit.gupta 100
class Refunds():
13990 amit.gupta 101
    def on_get(self, req, resp, userId):
13927 amit.gupta 102
        try:
103
            page = req.get_param_as_int("page")
104
            window = req.get_param_as_int("window")
13990 amit.gupta 105
            result = Mongo.getRefunds(int(userId),page,window)
13927 amit.gupta 106
            resp.body = json.dumps(result, encoding='utf-8')
107
        except ValueError:
108
            raise falcon.HTTPError(falcon.HTTP_400,
109
                'Malformed JSON',
110
                'Could not decode the request body. The '
111
                'JSON was incorrect.')
112
 
14427 amit.gupta 113
class Transactions():
114
    def on_get(self, req, resp):
115
        try:
116
            page = req.get_param_as_int("page")
117
            window = req.get_param_as_int("window")
14725 amit.gupta 118
            user = req.get_param("user")
119
            status = req.get_param("status")
120
            if user == "" :
121
                user = None
122
            if status == "" :
123
                status = None
124
            result = Mysql.getOrders(page, window,status,user)
14427 amit.gupta 125
            resp.body = result
126
            resp.content_type = 'text/html'
127
        except ValueError:
128
            raise falcon.HTTPError(falcon.HTTP_400,
129
                'Malformed JSON',
130
                'Could not decode the request body. The '
131
                'JSON was incorrect.')
132
 
133
class RawHtml():
134
    def on_get(self, req, resp, orderId):
135
        try:
136
            result = Mysql.getOrderHtml(orderId)
137
            resp.body = result
138
            resp.content_type = 'text/html'
139
        except ValueError:
140
            raise falcon.HTTPError(falcon.HTTP_400,
141
                'Malformed JSON',
142
                'Could not decode the request body. The '
143
                'JSON was incorrect.')
144
 
13927 amit.gupta 145
class PendingRefunds():
146
    def on_get(self, req, resp,userId):
147
        try:
148
            result = Mongo.getPendingRefunds(int(userId))
149
            resp.body = json.dumps(result, encoding='utf-8')
150
        except ValueError:
151
            raise falcon.HTTPError(falcon.HTTP_400,
152
                'Malformed JSON',
153
                'Could not decode the request body. The '
14671 amit.gupta 154
                'JSON was incorrect.')
155
 
156
class PendingCashBacks():
157
    def on_get(self, req, resp,userId):
158
        try:
159
            result = Mongo.getPendingCashbacks(int(userId))
160
            resp.body = json.dumps(result, encoding='utf-8')
161
        except ValueError:
162
            raise falcon.HTTPError(falcon.HTTP_400,
163
                'Malformed JSON',
164
                'Could not decode the request body. The '
13927 amit.gupta 165
                'JSON was incorrect.')