Exemple #1
0
def profile():
    """ Show profile page """

    # Get user information
    user_id = session.get("user_id")
    discription, username, posts, picture, followers, following = user_information(user_id)

    # Initialize lists and dictionary
    followers_list, following_list = [], []
    id_dict, post_dict = {}, {}

    # If user has posts
    if posts:
        post_dict = fill_post_dict(posts)

    # If user has followers
    if followers:
        for follower in followers:
            name = db.execute("SELECT username FROM users WHERE id=:id", id=follower["user_id"])
            followers_list.append(name)
            id_dict[name[0]["username"]] = follower["user_id"]

    # If user follows users
    if following:
        for user in following:
            name = db.execute("SELECT username FROM users WHERE id=:id", id=user["follow_id"])
            following_list.append(name)
            id_dict[name[0]["username"]] = user["follow_id"]

    # Render profile page
    return render_template("profile.html", discription=discription, username=username, picture=picture, followerslist=followers_list, followinglist=following_list, iddict=id_dict, post_dict=post_dict)
def userprofile(user_id):
    """ Show profile page """

    # Get user information
    description, username, posts, picture, followers, following = user_information_users(
        user_id)

    # False if user follows user already
    bool_follow = is_following(followers, session.get("user_id"))

    # False if user looks at his own page
    bool_user = is_user(user_id, session.get("user_id"))

    # Initialize lists and dictionary
    followers_list, following_list = [], []
    id_dict, post_dict = {}, {}

    # If user has posts
    if posts:
        post_dict = fill_post_dict(posts)

    # If user has followers
    if followers:
        for follower in followers:
            name = db.execute("SELECT username FROM users WHERE id=:id",
                              id=follower["user_id"])
            followers_list.append(name)
            id_dict[name[0]["username"]] = follower["user_id"]

    # If user follows users
    if following:
        for user in following:
            name = db.execute("SELECT username FROM users WHERE id=:id",
                              id=user["follow_id"])
            following_list.append(name)
            id_dict[name[0]["username"]] = user["follow_id"]

    # Render profile page
    return render_template("profile.html",
                           description=description,
                           username=username,
                           posts=posts,
                           picture=picture,
                           bool_user=bool_user,
                           user_id=user_id,
                           bool_follow=bool_follow,
                           followerslist=followers_list,
                           followinglist=following_list,
                           iddict=id_dict,
                           post_dict=post_dict)