|
@ -1,5 +1,5 @@ |
|
|
from flask import render_template, redirect, url_for, flash, request, \ |
|
|
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 flask_login import login_required, current_user |
|
|
from . import main |
|
|
from . import main |
|
|
from .forms import EditProfileForm, EditProfileAdminForm, PostForm |
|
|
from .forms import EditProfileForm, EditProfileAdminForm, PostForm |
|
@ -18,12 +18,19 @@ def index(): |
|
|
db.session.commit() |
|
|
db.session.commit() |
|
|
return redirect(url_for('.index')) |
|
|
return redirect(url_for('.index')) |
|
|
page = request.args.get('page', 1, type=int) |
|
|
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'], |
|
|
page, per_page=current_app.config['FLASKY_POSTS_PER_PAGE'], |
|
|
error_out=False) |
|
|
error_out=False) |
|
|
posts = pagination.items |
|
|
posts = pagination.items |
|
|
return render_template('index.html', form=form, posts=posts, |
|
|
return render_template('index.html', form=form, posts=posts, |
|
|
pagination=pagination) |
|
|
|
|
|
|
|
|
show_followed=show_followed, pagination=pagination) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@main.route('/user/<username>') |
|
|
@main.route('/user/<username>') |
|
@ -174,3 +181,19 @@ def followed_by(username): |
|
|
return render_template('followers.html', user=user, title="Followed by", |
|
|
return render_template('followers.html', user=user, title="Followed by", |
|
|
endpoint='.followed_by', pagination=pagination, |
|
|
endpoint='.followed_by', pagination=pagination, |
|
|
follows=follows) |
|
|
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 |