def post(self,action): request = self.get_django_request() if action == "weblink": self.action = action self.links = json.loads( self.request.body ) self.data = {} if len(self.links)>=1: http = tornado.httpclient.AsyncHTTPClient() http.fetch(self.links[0],callback=self.on_response) else: self.finish({"status":"failed","reason":"invalid request syntax"}) elif action == "upload": self.finish(api_class.image(request,action)) elif action == "delete": self.finish(api_class.image(request,action))
def post(self, action): request = self.get_django_request() if action == "weblink": self.action = action self.links = json.loads(self.request.body) self.data = {} if len(self.links) >= 1: http = tornado.httpclient.AsyncHTTPClient() http.fetch(self.links[0], callback=self.on_response) else: self.finish({ "status": "failed", "reason": "invalid request syntax" }) elif action == "upload": self.finish(api_class.image(request, action)) elif action == "delete": self.finish(api_class.image(request, action))
def on_response(self, response): '''recursively fetch the links, finally finish''' if response.error: self.data[self.links[0]] = None else: self.data[self.links[0]] = response.body self.links = self.links[1:] if len(self.links) >= 1: http = tornado.httpclient.AsyncHTTPClient() http.fetch(self.links[0], callback=self.on_response) else: request = self.get_django_request() response = api_class.image(request, self.action, self.data) self.finish(response)
def on_response(self,response): '''recursively fetch the links, finally finish''' if response.error: self.data[self.links[0]] = None else: self.data[self.links[0]] = response.body self.links = self.links[1:] if len(self.links)>=1: http = tornado.httpclient.AsyncHTTPClient() http.fetch(self.links[0],callback=self.on_response) else: request = self.get_django_request() response = api_class.image(request,self.action,self.data) self.finish(response)