Esempio n. 1
0
def show_all_posts():
    """the homepage of the site where all the posts will be shown in a table"""
    show_followed = False
    # get the variable "show-all" from the template to determine whether to show all posts or followed ones
    show_what = request.args.get('show-all')
    page = request.args.get('page', 1, type=int)
    print show_what, "this is show_what"
    if show_what == "false":
        show_followed = True

    if show_followed:
        viewer_id = session.get('loggedin', None)
        viewer = User.get_user_by_id(viewer_id)
        posts_all = viewer.followed_posts()
        pagination = viewer.followed_posts_pagination(page)
    else:
        posts_all = Post.get_all_posts()
        pagination = Post.get_all_posts_pagination(page)
    if posts_all:
        session["post_ids"] = [post.post_id for post in posts_all]
    tags = Tag.sort_all_tags_by_popularity()

    posts = pagination.items  # the records in the current page

    return render_template('post_list.html', posts=posts, tags=tags, pagination=pagination)