|
@@ -1,5 +1,5 @@
|
1
|
1
|
from flask import render_template, redirect, url_for, flash, request, \
|
2
|
|
- current_app, abort
|
|
2
|
+ current_app, abort, make_response
|
3
|
3
|
from flask_login import login_required, current_user
|
4
|
4
|
from . import main
|
5
|
5
|
from .forms import EditProfileForm, EditProfileAdminForm, PostForm
|
|
@@ -18,12 +18,19 @@ def index():
|
18
|
18
|
db.session.commit()
|
19
|
19
|
return redirect(url_for('.index'))
|
20
|
20
|
page = request.args.get('page', 1, type=int)
|
21
|
|
- pagination = Post.query.order_by(Post.timestamp.desc()).paginate(
|
|
21
|
+ show_followed = False
|
|
22
|
+ if current_user.is_authenticated:
|
|
23
|
+ show_followed = bool(request.cookies.get('show_followed', ''))
|
|
24
|
+ if show_followed:
|
|
25
|
+ query = current_user.followed_posts
|
|
26
|
+ else:
|
|
27
|
+ query = Post.query
|
|
28
|
+ pagination = query.order_by(Post.timestamp.desc()).paginate(
|
22
|
29
|
page, per_page=current_app.config['FLASKY_POSTS_PER_PAGE'],
|
23
|
30
|
error_out=False)
|
24
|
31
|
posts = pagination.items
|
25
|
32
|
return render_template('index.html', form=form, posts=posts,
|
26
|
|
- pagination=pagination)
|
|
33
|
+ show_followed=show_followed, pagination=pagination)
|
27
|
34
|
|
28
|
35
|
|
29
|
36
|
@main.route('/user/<username>')
|
|
@@ -174,3 +181,19 @@ def followed_by(username):
|
174
|
181
|
return render_template('followers.html', user=user, title="Followed by",
|
175
|
182
|
endpoint='.followed_by', pagination=pagination,
|
176
|
183
|
follows=follows)
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+@main.route('/all')
|
|
187
|
+@login_required
|
|
188
|
+def show_all():
|
|
189
|
+ resp = make_response(redirect(url_for('.index')))
|
|
190
|
+ resp.set_cookie('show_followed', '', max_age=30*24*60*60) # lasts 30 days
|
|
191
|
+ return resp
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+@main.route('/followed')
|
|
195
|
+@login_required
|
|
196
|
+def show_followed():
|
|
197
|
+ resp = make_response(redirect(url_for('.index')))
|
|
198
|
+ resp.set_cookie('show_followed', '1', max_age=30*24*60*60) # lasts 30 days
|
|
199
|
+ return resp
|