def get_item(self, item_id): oid = None try: oid = ObjectId(item_id) except: return bad_id_response() item = self.mongo.db[self.name].find_one({'_id': oid}) if item is None: return jsonify({'message': 'no item with id: ' + item_id}, 404) return jsonify(item)
def delete_item(self, item_id): coll = self.mongo.db[self.name] coll.remove(ObjectId(item_id)) return jsonify({'message': 'OK'})
def update_item(self, item_id): coll = self.mongo.db[self.name] coll.save(json_load(request.data)) return jsonify({'message': 'OK'})
def create_item(self): coll = self.mongo.db[self.name] item = json_load(request.data) coll.save(item) return jsonify(item)
def get_items(self): coll = self.mongo.db[self.name] return jsonify(list(coll.find().sort('order', 1)))