Subversion Repositories SmartDukaan

Rev

Rev 14015 | Rev 14022 | 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
7
from dtr.storage import Mongo
8
import falcon
9
import json
14014 amit.gupta 10
import urlparse
13804 amit.gupta 11
class StoreOrder():
12
    def on_post(self, req, resp):
13
 
14
        try:
15
            string1 = req.stream.read()
16
            req_json = json.loads(string1, encoding='utf-8')
17
        except ValueError:
18
            raise falcon.HTTPError(falcon.HTTP_400,
19
                'Malformed JSON',
20
                'Could not decode the request body. The '
21
                'JSON was incorrect.')
22
 
23
        store = main.getStore(int(req_json['sourceId']))
24
        result = store.parseOrderRawHtml(int(req_json['orderId']), req_json['subTagId'], int(req_json['userId']), req_json['rawHtml'], req_json['orderSuccessUrl'])
25
        resp.body = json.dumps(result, encoding='utf-8')
26
 
27
    def on_get(self, req, resp, userId):
28
        page = req.get_param_as_int("page")
29
        window = req.get_param_as_int("window")
14003 amit.gupta 30
        string1 = req.get_param("searchMap")
14004 amit.gupta 31
        searchMap={}
14006 amit.gupta 32
        if string1 is None or string1 == "":
14007 amit.gupta 33
            pass
34
        else:
14006 amit.gupta 35
            try:
14007 amit.gupta 36
                searchMap = json.loads(string1, encoding='utf-8')
14006 amit.gupta 37
            except:
38
                raise falcon.HTTPError(falcon.HTTP_400,
39
                    'Malformed JSON',
40
                    'Could not decode the request body. The '
41
                    'JSON was incorrect.')
14003 amit.gupta 42
        result = Mongo.getMerchantOrdersByUser(int(userId), page, window, searchMap)
13868 amit.gupta 43
        resp.body = json.dumps(result, encoding='utf-8')
44
 
45
class Track():
13939 amit.gupta 46
    def on_post(self, req, resp, userId):
13868 amit.gupta 47
        try:
14013 amit.gupta 48
            string1 = req.stream.read()
14014 amit.gupta 49
            req_obj = urlparse.parse_qs(string1)
14013 amit.gupta 50
        except ValueError:
51
            raise falcon.HTTPError(falcon.HTTP_400,
52
                'Malformed JSON',
53
                'Could not decode the request body. The '
54
                'JSON was incorrect.')
55
        try:
13927 amit.gupta 56
            store = main.getStore(req.get_param_as_int("storeId"))
57
            if req.get_param_as_int("storeId") == 1:
14021 amit.gupta 58
                print "RAWHTML ----",req_obj['html'][0]
14015 amit.gupta 59
                result = store.trackOrdersForUser(int(userId),req_obj['url'][0],req_obj['html'][0])
13927 amit.gupta 60
                resp.body = json.dumps({'result':result}, encoding='utf-8')
61
            else:
62
                resp.body = json.dumps({'result':'NOT_IMPLEMENTED'}, encoding='utf-8')
63
        except:
64
            resp.body = json.dumps({'result':'PARSE_ERROR'}, encoding='utf-8')
13868 amit.gupta 65
 
13939 amit.gupta 66
    def on_get(self, req, resp, userId):
13868 amit.gupta 67
        try:
68
            storeId = req.get_param_as_int("storeId")
13939 amit.gupta 69
            result = main.getStore(storeId).getTrackingUrls(int(userId))
13887 amit.gupta 70
            resp.body = json.dumps({'result':result}, encoding='utf-8')
13868 amit.gupta 71
        except ValueError:
72
            raise falcon.HTTPError(falcon.HTTP_400,
73
                'Malformed JSON',
74
                'Could not decode the request body. The '
75
                'JSON was incorrect.')
76
 
13927 amit.gupta 77
class Refunds():
13990 amit.gupta 78
    def on_get(self, req, resp, userId):
13927 amit.gupta 79
        try:
80
            page = req.get_param_as_int("page")
81
            window = req.get_param_as_int("window")
13990 amit.gupta 82
            result = Mongo.getRefunds(int(userId),page,window)
13927 amit.gupta 83
            resp.body = json.dumps(result, encoding='utf-8')
84
        except ValueError:
85
            raise falcon.HTTPError(falcon.HTTP_400,
86
                'Malformed JSON',
87
                'Could not decode the request body. The '
88
                'JSON was incorrect.')
89
 
90
class PendingRefunds():
91
    def on_get(self, req, resp,userId):
92
        try:
93
            result = Mongo.getPendingRefunds(int(userId))
94
            resp.body = json.dumps(result, encoding='utf-8')
95
        except ValueError:
96
            raise falcon.HTTPError(falcon.HTTP_400,
97
                'Malformed JSON',
98
                'Could not decode the request body. The '
99
                'JSON was incorrect.')