diff --git a/app/main/views.py b/app/main/views.py index bcd8367..003dbbc 100644 --- a/app/main/views.py +++ b/app/main/views.py @@ -1,5 +1,5 @@ from flask import render_template, redirect, url_for, flash, request, \ - current_app, abort + current_app, abort, make_response from flask_login import login_required, current_user from . import main from .forms import EditProfileForm, EditProfileAdminForm, PostForm @@ -18,12 +18,19 @@ def index(): db.session.commit() return redirect(url_for('.index')) page = request.args.get('page', 1, type=int) - pagination = Post.query.order_by(Post.timestamp.desc()).paginate( + show_followed = False + if current_user.is_authenticated: + show_followed = bool(request.cookies.get('show_followed', '')) + if show_followed: + query = current_user.followed_posts + else: + query = Post.query + pagination = query.order_by(Post.timestamp.desc()).paginate( page, per_page=current_app.config['FLASKY_POSTS_PER_PAGE'], error_out=False) posts = pagination.items return render_template('index.html', form=form, posts=posts, - pagination=pagination) + show_followed=show_followed, pagination=pagination) @main.route('/user/') @@ -174,3 +181,19 @@ def followed_by(username): return render_template('followers.html', user=user, title="Followed by", endpoint='.followed_by', pagination=pagination, follows=follows) + + +@main.route('/all') +@login_required +def show_all(): + resp = make_response(redirect(url_for('.index'))) + resp.set_cookie('show_followed', '', max_age=30*24*60*60) # lasts 30 days + return resp + + +@main.route('/followed') +@login_required +def show_followed(): + resp = make_response(redirect(url_for('.index'))) + resp.set_cookie('show_followed', '1', max_age=30*24*60*60) # lasts 30 days + return resp diff --git a/app/static/styles.css b/app/static/styles.css index 7084ad1..4d648a5 100644 --- a/app/static/styles.css +++ b/app/static/styles.css @@ -5,12 +5,19 @@ min-height: 260px; margin-left: 280px; } +div.post-tabs { + margin-top: 16px; +} ul.posts { list-style-type: none; padding: 0px; margin: 16px 0px 0px 0px; border-top: 1px solid #e0e0e0; } +div.post-tabs ul.posts { + margin: 0px; + border-top: none; +} ul.posts li.post { padding: 8px; border-bottom: 1px solid #e0e0e0; diff --git a/app/templates/index.html b/app/templates/index.html index 87b19c7..9955bca 100644 --- a/app/templates/index.html +++ b/app/templates/index.html @@ -16,7 +16,20 @@ {% endif %} -{% include '_posts.html' %} +
+ + {% include '_posts.html' %} +
+ {% if pagination %}