Example #1
0
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)
Example #2
0
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)
Example #3
0
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)
Example #4
0
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)
Example #5
0
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'})
Example #6
0
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)
Example #7
0
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)
Example #8
0
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'})
Example #9
0
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)
Example #10
0
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)
Example #11
0
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)
Example #12
0
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)
Example #13
0
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)
Example #14
0
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)
Example #15
0
def delete_todo(todo_id):
    todos = get_collection()
    todos.remove(ObjectId(todo_id))
    return make_json_response({'message': 'OK'})
Example #16
0
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'})
Example #17
0
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'})
Example #18
0
def delete_location(location_id):
    locations = get_collection()
    locations.remove(ObjectId(location_id))
    return make_json_response({'message': 'OK'})
Example #19
0
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'})
Example #20
0
def delete_todo(todo_id):
    todos = get_collection()
    todos.remove(ObjectId(todo_id))
    return make_json_response({'message': 'OK'})