|
|
@ -1,4 +1,5 @@ |
|
|
|
from flask import render_template, redirect, url_for, flash |
|
|
|
from flask import render_template, redirect, url_for, flash, request, \ |
|
|
|
current_app |
|
|
|
from flask_login import login_required, current_user |
|
|
|
from . import main |
|
|
|
from .forms import EditProfileForm, EditProfileAdminForm, PostForm |
|
|
@ -16,15 +17,25 @@ def index(): |
|
|
|
db.session.add(post) |
|
|
|
db.session.commit() |
|
|
|
return redirect(url_for('.index')) |
|
|
|
posts = Post.query.order_by(Post.timestamp.desc()).all() |
|
|
|
return render_template('index.html', form=form, posts=posts) |
|
|
|
page = request.args.get('page', 1, type=int) |
|
|
|
pagination = Post.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) |
|
|
|
|
|
|
|
|
|
|
|
@main.route('/user/<username>') |
|
|
|
def user(username): |
|
|
|
user = User.query.filter_by(username=username).first_or_404() |
|
|
|
posts = user.posts.order_by(Post.timestamp.desc()).all() |
|
|
|
return render_template('user.html', user=user, posts=posts) |
|
|
|
page = request.args.get('page', 1, type=int) |
|
|
|
pagination = user.posts.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('user.html', user=user, posts=posts, |
|
|
|
pagination=pagination) |
|
|
|
|
|
|
|
|
|
|
|
@main.route('/edit-profile', methods=['GET', 'POST']) |
|
|
|