Rev 13603 | Rev 13631 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
import jsonfrom dtr import mainfrom dtr.storage import Mongofrom bson import json_utilimport falconclass CategoryDiscountInfo(object):def on_get(self, req, resp):result = Mongo.getAllCategoryDiscount()json_docs = [json.dumps(doc, default=json_util.default) for doc in result]resp.body = json.dumps(json_docs, encoding='utf-8')def on_post(self, req, resp):try:result_json = json.loads(req.stream.read(), encoding='utf-8')except ValueError:raise falcon.HTTPError(falcon.HTTP_400,'Malformed JSON','Could not decode the request body. The ''JSON was incorrect.')result = Mongo.addCategoryDiscount(result_json)resp.body = json.dumps(result, encoding='utf-8')class SkuSchemeDetails(object):def on_get(self, req, resp):result = Mongo.getAllCategoryDiscount()json_docs = [json.dumps(doc, default=json_util.default) for doc in result]resp.body = json.dumps(json_docs, encoding='utf-8')def on_post(self, req, resp):try:result_json = json.loads(req.stream.read(), encoding='utf-8')except ValueError:raise falcon.HTTPError(falcon.HTTP_400,'Malformed JSON','Could not decode the request body. The ''JSON was incorrect.')result = Mongo.addSchemeDetailsForSku(result_json)resp.body = json.dumps(result, encoding='utf-8')class SkuDiscountInfo():def on_get(self, req, resp):result = Mongo.getallSkuDiscountInfo()json_docs = [json.dumps(doc, default=json_util.default) for doc in result]resp.body = json.dumps(json_docs, encoding='utf-8')def on_post(self, req, resp):try:result_json = json.loads(req.stream.read(), encoding='utf-8')except ValueError:raise falcon.HTTPError(falcon.HTTP_400,'Malformed JSON','Could not decode the request body. The ''JSON was incorrect.')result = Mongo.addSkuDiscountInfo(result_json)resp.body = json.dumps(result, encoding='utf-8')class ExceptionalNlc():def on_get(self, req, resp):result = Mongo.getAllExceptionlNlcItems()json_docs = [json.dumps(doc, default=json_util.default) for doc in result]resp.body = json.dumps(json_docs, encoding='utf-8')def on_post(self, req, resp):try:result_json = json.loads(req.stream.read(), encoding='utf-8')except ValueError:raise falcon.HTTPError(falcon.HTTP_400,'Malformed JSON','Could not decode the request body. The ''JSON was incorrect.')result = Mongo.addExceptionalNlc(result_json)resp.body = json.dumps(result, encoding='utf-8')class StoreOrder():def on_post(self, req, resp):try:req_json = json.loads(req.stream.read(), encoding='utf-8')except ValueError:raise falcon.HTTPError(falcon.HTTP_400,'Malformed JSON','Could not decode the request body. The ''JSON was incorrect.')store = main.getStore(req_json['sourceId'])result = store.parseOrderRawHtml(req_json['orderId'], req_json['subTagId'], req_json['userId'], req_json['rawHtml'], req_json['orderSuccessUrl'])resp.body = json.dumps({"result":result}, encoding='utf-8')def on_get(self, req, resp, userId):page = req.get_param_as_int("page")window = req.get_param_as_int("window")result = Mongo.getMerchantOrdersByUser(int(userId), page, window)print resultresp.body = json.dumps(result, encoding='utf-8')