def create_todo(): data = request.json todos = get_collection() oid = todos.insert(data) todo = todos.find_one({'_id': ObjectId(oid)}) todo['id'] = str(todo['_id']) del todo['_id'] return make_json_response(todo)
def get_todo(todo_id): oid = None try: oid = ObjectId(todo_id) except: return bad_id_response() todos = get_collection() todo = todos.find_one({'_id': oid}) if todo is None: return make_json_response({'message': 'no todo with id: ' + todo_id}, 404) todo['id'] = str(todo['_id']) del todo['_id'] return make_json_response(todo)
def create_location(): data = request.json update_data(data); locations = get_collection() oid = locations.insert(data) location = locations.find_one({'_id': ObjectId(oid)}) location['id'] = str(location['_id']) del location['_id'] return make_json_response(location)
def delete_location(location_id): """ Removes a specific Location. :param location_id: str -- The id of location object which will be deleted.. :return: -- Json response status 200. """ locations = get_collection() locations.remove(ObjectId(location_id)) return make_json_response({'message': 'OK'})
def get_location(location_id): oid = None try: oid = ObjectId(location_id) except: return bad_id_response() locations = get_collection() location = locations.find_one({'_id': oid}) if location is None: return make_json_response({'message': 'no location with id: ' + location_id}, 404) location['id'] = str(location['_id']) del location['_id'] return make_json_response(location)
def update_location(location_id): """ Updates specific location. :param location_id: str -- The id of location object which will be updated. :return: -- Json response status 200. """ data = request.json locations = get_collection() locations.update({'_id': ObjectId(location_id)}, {'$set': data}) return make_json_response({'message': 'OK'})
def get_locations(): locations = get_collection() cur = locations.find().sort('order', pymongo.ASCENDING) data = [] for location in cur: location['id'] = str(location['_id']) del location['_id'] data.append(location) return make_json_response(data)
def get_todos(): todos = get_collection() cur = todos.find().sort('order', pymongo.ASCENDING) data = [] for todo in cur: todo['id'] = str(todo['_id']) del todo['_id'] data.append(todo) return make_json_response(data)
def create_location(): """ Saves a location to the DB, :return: dict -- location """ data = request.json locations = get_collection() oid = locations.insert(data) location = locations.find_one({'_id': ObjectId(oid)}) location['id'] = str(location['_id']) del location['_id'] return make_json_response(location)
def get_location(location_id): """ Retrieves a specific location. :param location_id: str -- The id of location object which will be updated. :return: -- Json response The specified location object. """ oid = None try: oid = ObjectId(location_id) except: return bad_id_response() locations = get_collection() location = locations.find_one({'_id': oid}) if location is None: return make_json_response({'message': 'no location with id: ' + location_id}, 404) location['id'] = str(location['_id']) del location['_id'] return make_json_response(location)
def get_locations(): """ Used to retrieve all locations from the DB. :return:list -- of locations """ locations = get_collection() cur = locations.find().sort('order', pymongo.ASCENDING) data = [] for location in cur: location['id'] = str(location['_id']) del location['_id'] data.append(location) return make_json_response(data)
def delete_todo(todo_id): todos = get_collection() todos.remove(ObjectId(todo_id)) return make_json_response({'message': 'OK'})
def update_todo(todo_id): data = request.json todos = get_collection() todos.update({'_id': ObjectId(todo_id)}, {'$set': data}) return make_json_response({'message': 'OK'})
def update_location(location_id): data = request.json update_data(data); locations = get_collection() locations.update({'_id': ObjectId(location_id)}, {'$set': data}) return make_json_response({'message': 'OK'})
def delete_location(location_id): locations = get_collection() locations.remove(ObjectId(location_id)) return make_json_response({'message': 'OK'})