def _post(self, site, col): data = json.loads(self.request.body) if "_id" in data: del (data["_id"]) oid = ResManager.get(site, col).save(data) ResManager.end() self.write(str(oid)) self.finish()
def head(self, site, col, id): try: i = ResManager.get(site, col).find_one(ResManager.oid(id), fields={}) ResManager.end() if i is None: raise tornado.web.HTTPError(404) except InvalidId as e: raise tornado.web.HTTPError(400, str(e))
def get(self, site, col): list = [] col = ResManager.get(site, col) params = self._parse_params() for entry in col.find(**params) : entry['_id'] = str(entry['_id']) list.append(entry) ResManager.end() self.render(list)
def get(self, site, col, id): try: i = ResManager.get(site, col).find_one(ResManager.oid(id)) ResManager.end() if i is None: raise tornado.web.HTTPError(404) i['_id'] = str(i['_id']) self.render(i) except InvalidId as e: raise tornado.web.HTTPError(400, str(e))
def post(self, site, col): if self.request.body is None: raise tornado.web.HTTPError(403, 'Missing new data as JSON dict') data = json.loads(self.request.body) if '_id' in data: del(data['_id']) id = ResManager.get(site, col).save(data) ResManager.end() self.render(str(id)) ResManager.end()
def _get(self, site, col): list_ = [] col_ = ResManager.get(site, col) params = self._parse_params() for entry in col_.find(**params): entry["_id"] = str(entry["_id"]) list_.append(entry) ResManager.end() self.write(list_) self.finish()
def _get(self, site, col, oid, extra_args={}): try: i = ResManager.get(site, col).find_one(ResManager.oid(oid), **extra_args) ResManager.end() if i is None: raise web.HTTPError(404) i["_id"] = str(i["_id"]) self.write(i) self.finish() except InvalidId as e: raise web.HTTPError(400, str(e))
def delete(self, site, col, id): try: i = ResManager.get(site, col).find_one(ResManager.oid(id)) if i is None: ResManager.end() raise tornado.web.HTTPError(404) ResManager.get(site, col).remove(ResManager.oid(id)) ResManager.end() except InvalidId as e: raise tornado.web.HTTPError(400, str(e))
def put(self, site, col, id): try: i = ResManager.get(site, col).find_one(ResManager.oid(id)) if i is None: ResManager.end() raise tornado.web.HTTPError(404) data = json.loads(self.request.body) if '_id' in data: del(data['_id']) data['_id'] = ResManager.oid(id) id = ResManager.get(site, col).save(data) ResManager.end() except InvalidId as e: raise tornado.web.HTTPError(400, str(e))
def _put(self, site, col, oid): try: i = ResManager.get(site, col).find_one(ResManager.oid(oid)) if i is None: ResManager.end() raise web.HTTPError(404) data = json.loads(self.request.body) if "_id" in data: del (data["_id"]) data["_id"] = ResManager.oid(oid) oid = ResManager.get(site, col).save(data) ResManager.end() self.finish() except InvalidId as e: raise web.HTTPError(400, str(e))
def delete(self, site, col): ResManager.get(site, col).drop() ResManager.end()
def _delete(self, site, col): ResManager.get(site, col).drop() ResManager.end() self.finish()