Esempio n. 1
0
 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()
Esempio n. 2
0
 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))
Esempio n. 3
0
 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)
Esempio n. 4
0
 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))
Esempio n. 5
0
 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()
Esempio n. 6
0
 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()
Esempio n. 7
0
 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))
Esempio n. 8
0
 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))
Esempio n. 9
0
    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))
Esempio n. 10
0
    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))
Esempio n. 11
0
 def delete(self, site, col):
     ResManager.get(site, col).drop()
     ResManager.end()
Esempio n. 12
0
 def _delete(self, site, col):
     ResManager.get(site, col).drop()
     ResManager.end()
     self.finish()