Ejemplo n.º 1
0
def show_user_home(user_id):
    """Using the unique user id number, display this user's profile to
    anyone that is not logged in, or is not this user. If the current
    user matches this ID, then show them their own user dashboard.
    """
    # Try to lookup the user id in the database
    try:
        this_user = session.query(User).filter_by(id=user_id).one()
    # ... if no result is found route to the main page with a flash
    except NoResultFound:
        flash("This user does not exist.")
        return redirect(url_for('show_home'))
    # However, if no exceptions are raised then proceed as normal by
    # getting the user's disc collection and makers
    else:
        list_of_makers = session.query(Manufacturer).all()
        this_users_discs = session.query(Disc).filter_by(user_id=user_id).all()
        this_users_makers = session.query(
            Manufacturer).filter_by(user_id=user_id).all()
    # Check if this is the user's own profile
    if user_id == login_session.get('user_id'):
        return render_template('user.html',
                               user_info=this_user,
                               discs=this_users_discs,
                               makers=list_of_makers,
                               this_makers=this_users_makers)
    else:
        return render_template('public_user.html',
                               user_info=this_user,
                               discs=this_users_discs,
                               makers=list_of_makers,
                               this_makers=this_users_makers)
Ejemplo n.º 2
0
def show_user_home(user_id):
    """Using the unique user id number, display this user's profile to
    anyone that is not logged in, or is not this user. If the current
    user matches this ID, then show them their own user dashboard.
    """
    # Try to lookup the user id in the database
    try:
        this_user = session.query(User).filter_by(id=user_id).one()
    # ... if no result is found route to the main page with a flash
    except NoResultFound:
        flash("This user does not exist.")
        return redirect(url_for('show_home'))
    # However, if no exceptions are raised then proceed as normal by
    # getting the user's disc collection and makers
    else:
        list_of_makers = session.query(Manufacturer).all()
        this_users_discs = session.query(Disc).filter_by(user_id=user_id).all()
        this_users_makers = session.query(Manufacturer).filter_by(
            user_id=user_id).all()
    # Check if this is the user's own profile
    if user_id == login_session.get('user_id'):
        return render_template('user.html',
                               user_info=this_user,
                               discs=this_users_discs,
                               makers=list_of_makers,
                               this_makers=this_users_makers)
    else:
        return render_template('public_user.html',
                               user_info=this_user,
                               discs=this_users_discs,
                               makers=list_of_makers,
                               this_makers=this_users_makers)
Ejemplo n.º 3
0
def show_sess_info():
    """Quick and dirty func see what's going on."""
    output = 'Session info'
    for i in login_session:
        output += '<br>'
        output += i
        output += '<br>'
        output += str(login_session.get(i))
        output += '<br>'
    return output
Ejemplo n.º 4
0
def show_sess_info():
    """Quick and dirty func see what's going on."""
    output = 'Session info'
    for i in login_session:
        output += '<br>'
        output += i
        output += '<br>'
        output += str(login_session.get(i))
        output += '<br>'
    return output
Ejemplo n.º 5
0
def show_disc(disc_id):
    """ Show details about a unique disc on the site. Because any user can
    submit a description of their unique disc, the unique id from the 'disc'
    table will be used to pull the first record matching the disc_id from
    the URL.
    """
    # Try to lookup the disc in the database
    try:
        this_disc = session.query(Disc).filter_by(id=disc_id).one()
    # ... if no result is found set this_disc to None
    except NoResultFound:
        this_disc = None
    # However, if no exceptions are raised then proceed as normal by
    # getting the disc owner info
    else:
        disc_owner = get_user_info(this_disc.user_id)
    # Verify this disc exists AND the currently logged in user owns the disc.
    # If so show the disc owner page which includes edit/delete links.
    list_of_makers = session.query(Manufacturer).all()
    if this_disc and this_disc.user_id == login_session.get('user_id'):
        return render_template('disc.html',
                               makers=list_of_makers,
                               disc=this_disc,
                               disc_owner=disc_owner,
                               UPLOAD_FOLDER=UPLOAD_FOLDER)
    # If the disc exists but the user is not the owner, show the public
    # disc page which does not include edit/delete.
    elif this_disc:
        return render_template('public_disc.html',
                               makers=list_of_makers,
                               disc=this_disc,
                               disc_owner=disc_owner,
                               UPLOAD_FOLDER=UPLOAD_FOLDER)
    # Finally if the disc doesn't exist, route to main with a flash
    else:
        flash("Disc does not exist.")
        return redirect(url_for('show_home'))
Ejemplo n.º 6
0
def show_disc(disc_id):
    """ Show details about a unique disc on the site. Because any user can
    submit a description of their unique disc, the unique id from the 'disc'
    table will be used to pull the first record matching the disc_id from
    the URL.
    """
    # Try to lookup the disc in the database
    try:
        this_disc = session.query(Disc).filter_by(id=disc_id).one()
    # ... if no result is found set this_disc to None
    except NoResultFound:
        this_disc = None
    # However, if no exceptions are raised then proceed as normal by
    # getting the disc owner info
    else:
        disc_owner = get_user_info(this_disc.user_id)
    # Verify this disc exists AND the currently logged in user owns the disc.
    # If so show the disc owner page which includes edit/delete links.
    list_of_makers = session.query(Manufacturer).all()
    if this_disc and this_disc.user_id == login_session.get('user_id'):
        return render_template('disc.html',
                               makers=list_of_makers,
                               disc=this_disc,
                               disc_owner=disc_owner,
                               UPLOAD_FOLDER=UPLOAD_FOLDER)
    # If the disc exists but the user is not the owner, show the public
    # disc page which does not include edit/delete.
    elif this_disc:
        return render_template('public_disc.html',
                               makers=list_of_makers,
                               disc=this_disc,
                               disc_owner=disc_owner,
                               UPLOAD_FOLDER=UPLOAD_FOLDER)
    # Finally if the disc doesn't exist, route to main with a flash
    else:
        flash("Disc does not exist.")
        return redirect(url_for('show_home'))
Ejemplo n.º 7
0
def get_current_user():
    email = login_session.get('email')
    return get_user_by_email(email) if email else None