Exemple #1
0
def new_list():
    #import pdb; pdb.set_trace()
    list_name = request.form['list_name']
    if list_name is not None and len(list_name) == 0:
        list_name = None
    if 'access_token' in session:
        access_token = session.get('access_token', None)
        db = connect_db ()
        try:
            user_info = auth.authenticate_using_access_token(access_token, db)
            user_id = user_info['id']
        except AccessTokenExpiredError:
            flash("Access Token Expired. Login again")
            return redirect(url_for('login'))
        except InvalidAccessTokenError:
            flash("In Valid Access Token. Login again")
            return redirect(url_for('login'))
        if list_name == None:
            flash('Enter the name of the new list')
            return redirect(url_for('users'))
        else:
            dm.create_new_list(list_name, user_id, db)
            return redirect(url_for('users'))
    else:
        return redirect(url_for('login'))
Exemple #2
0
def lists():

    query_access_token = request.args.get('access_token')
    db = connect_db ()
    try:
        user_info = auth.authenticate_using_access_token(query_access_token, db)
        user_id = user_info['id']
    except AccessTokenExpiredError:
        response_data = {
            "meta" : {},
            "data" : {
                "users" : [{
                    "authentication" : 'Expired',
                    "message" : "Access token Expired"
                }]
            }
        }
        status = 401
        body = json.dumps(response_data)
        headers = {
            'Content-Type' : 'application/json'
        }
        return (body, status, headers)
    except InvalidAccessTokenError:
        response_data = {
            "meta" : {},
            "data" : {
                "users" : [
                    {
                        "message" : "Invalid access token : %s" % (query_access_token)
                    }
                ]
            }
        }
        status = 400
        body = json.dumps(response_data)
        headers = {
            'Content-Type' : 'application/json'
        }
        return (body, status, headers)
    #All list under that user
    if request.method == 'GET':
        try:
            list_of_lists = dm.list_of_list(user_id, db)
            print list_of_lists
        except NoListFoundError:
            response_data = {
                "meta" : {},
                "data" : {
                    "lists" : [{
                        "message" : "No List found of this user"
                    }]
                }
            }
            body = json.dumps(response_data)
            status = 200
            headers = {
                "Content-Type" : 'application/json'
            }
            return (body,status,headers)
        response_data = {
            "meta" : {},
            "data" : {
                "users" : user_info,
                "lists" : list_of_lists
            }
        }
        body = json.dumps(response_data)
        status = 200
        headers = {
            "Content-Type" : 'application/json'
        }
        return (body,status,headers)
    else:
        # Add new list(how to handle request data)
        data = request.json['data']
        list_name = data['lists'][0]['name']
        list_info = list(dm.create_new_list(list_name, user_id, db))
        response_data = {
            "meta" : {},
            "data" : {
                "lists" : list_info
            }
        }
        body = json.dumps(response_data)
        status = 200
        headers = {
            "Content-Type" : 'application/json'
        }
        return (body,status,headers)