コード例 #1
0
def discover():
    """Let user discover studyspots"""

    # Get post info
    posts = db.execute("SELECT id FROM uploads")
    id_set = set()
    [id_set.add(post["id"]) for post in posts]
    post_id = random.choice(tuple(id_set))
    post = db.execute("SELECT path FROM uploads WHERE id=:id", id=post_id)
    user_id = db.execute("SELECT user_id FROM uploads WHERE id=:id",
                         id=post_id)[0]["user_id"]
    username = db.execute("SELECT username FROM users WHERE id=:id",
                          id=user_id)
    likes = len(
        db.execute("SELECT post_id FROM likes WHERE post_id=:post_id",
                   post_id=post_id))

    # True if user didnt like the post
    bool_like = liked_post(session.get("user_id"), post_id)

    # Render discover.html
    return render_template("discover.html",
                           post=post,
                           number=post_id,
                           bool_like=bool_like,
                           username=username,
                           likes=likes)
コード例 #2
0
ファイル: application.py プロジェクト: thomasjeu/project_ik15
def info(post_id):
    """ Show user extra information about studyspot """

    # Get user_id
    user_id = session.get("user_id")

    # Get all information from the post
    titles = db.execute("SELECT * FROM uploads WHERE id=:id", id=post_id)
    user = titles[0]["user_id"]
    name = db.execute("SELECT username FROM users WHERE id=:id", id=user)

    # True if user didnt favorite the post
    bool_favo = favo_post(session.get("user_id"), post_id)

    # True if user didnt like the post
    bool_like = liked_post(session.get("user_id"), post_id)

    # False if user looks at his own post
    bool_user = is_user(user, user_id)

    # Render info page
    return render_template("info.html",
                           titles=titles,
                           number=post_id,
                           name=name,
                           bool_like=bool_like,
                           user=user,
                           bool_user=bool_user,
                           bool_favo=bool_favo)