|
|
@ -1,4 +1,4 @@
|
|
|
|
from flask import (Blueprint, abort, current_app, flash, redirect,
|
|
|
|
from flask import (Blueprint, current_app, flash, redirect,
|
|
|
|
render_template, request, send_from_directory, url_for)
|
|
|
|
render_template, request, send_from_directory, url_for)
|
|
|
|
from flask_login import login_required, current_user
|
|
|
|
from flask_login import login_required, current_user
|
|
|
|
from yadc.forms import UserForm, PostForm, TagForm, CommentForm
|
|
|
|
from yadc.forms import UserForm, PostForm, TagForm, CommentForm
|
|
|
@ -28,9 +28,11 @@ def manage_users(page):
|
|
|
|
@bp.route('/posts', defaults={'page': 1})
|
|
|
|
@bp.route('/posts', defaults={'page': 1})
|
|
|
|
@bp.route('/posts/<int:page>')
|
|
|
|
@bp.route('/posts/<int:page>')
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
@moderator_required
|
|
|
|
|
|
|
|
def manage_posts(page):
|
|
|
|
def manage_posts(page):
|
|
|
|
|
|
|
|
if current_user.is_moderator:
|
|
|
|
posts = Post.query.order_by(Post.id.desc()).paginate(page, current_app.config.get('MANAGE_PER_PAGE'))
|
|
|
|
posts = Post.query.order_by(Post.id.desc()).paginate(page, current_app.config.get('MANAGE_PER_PAGE'))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
posts = Post.query.filter_by(author=current_user).order_by(Post.id.desc()).paginate(page, current_app.config.get('MANAGE_PER_PAGE'))
|
|
|
|
|
|
|
|
|
|
|
|
for post in posts.items:
|
|
|
|
for post in posts.items:
|
|
|
|
post.editform = PostForm(
|
|
|
|
post.editform = PostForm(
|
|
|
@ -78,6 +80,13 @@ def modify_user():
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
el = User.query.filter_by(id=form.id.data).first()
|
|
|
|
el = User.query.filter_by(id=form.id.data).first()
|
|
|
|
if form.delete.data:
|
|
|
|
if form.delete.data:
|
|
|
|
|
|
|
|
if el.is_current:
|
|
|
|
|
|
|
|
flash("You can't just delete yourself.")
|
|
|
|
|
|
|
|
return redirect(url_for('.manage_users'))
|
|
|
|
|
|
|
|
elif el.is_admin:
|
|
|
|
|
|
|
|
flash("You can't just delete admins.")
|
|
|
|
|
|
|
|
return redirect(url_for('.manage_users'))
|
|
|
|
|
|
|
|
|
|
|
|
db.session.delete(el)
|
|
|
|
db.session.delete(el)
|
|
|
|
db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
|
flash('{} deleted.'.format(str(el)))
|
|
|
|
flash('{} deleted.'.format(str(el)))
|
|
|
@ -97,7 +106,6 @@ def modify_user():
|
|
|
|
|
|
|
|
|
|
|
|
@bp.route('/modify_post', methods=['POST'])
|
|
|
|
@bp.route('/modify_post', methods=['POST'])
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
@moderator_required
|
|
|
|
|
|
|
|
def modify_post():
|
|
|
|
def modify_post():
|
|
|
|
form = PostForm(request.form)
|
|
|
|
form = PostForm(request.form)
|
|
|
|
# flash(str(request.form))
|
|
|
|
# flash(str(request.form))
|
|
|
@ -106,6 +114,9 @@ def modify_post():
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
el = Post.query.filter_by(id=form.id.data).first()
|
|
|
|
el = Post.query.filter_by(id=form.id.data).first()
|
|
|
|
|
|
|
|
if not current_user.is_moderator or not el.author.is_current:
|
|
|
|
|
|
|
|
flash("You don't have sufficient rights to do this.")
|
|
|
|
|
|
|
|
return redirect(url_for('main.index'))
|
|
|
|
if form.delete.data:
|
|
|
|
if form.delete.data:
|
|
|
|
db.session.delete(el)
|
|
|
|
db.session.delete(el)
|
|
|
|
db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
@ -165,11 +176,12 @@ def modify_comment():
|
|
|
|
|
|
|
|
|
|
|
|
db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
|
flash('Successfully submitted {}'.format(str(el)))
|
|
|
|
flash('Successfully submitted {}'.format(str(el)))
|
|
|
|
return redirect(url_for('.post_show', id=form.post_id.data))
|
|
|
|
return redirect(url_for('post.post_show', id=form.post_id.data))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
el = Comment.query.filter_by(id=form.id.data).first()
|
|
|
|
el = Comment.query.filter_by(id=form.id.data).first()
|
|
|
|
if not current_user.is_moderator or not el.is_current:
|
|
|
|
if not current_user.is_moderator or not el.user.is_current:
|
|
|
|
return abort(403)
|
|
|
|
flash("You don't have sufficient rights to do this.")
|
|
|
|
|
|
|
|
return redirect(url_for('main.index'))
|
|
|
|
if form.delete.data:
|
|
|
|
if form.delete.data:
|
|
|
|
db.session.delete(el)
|
|
|
|
db.session.delete(el)
|
|
|
|
db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
@ -180,6 +192,6 @@ def modify_comment():
|
|
|
|
db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
|
flash('Changes to {} have been applied.'.format(str(el)))
|
|
|
|
flash('Changes to {} have been applied.'.format(str(el)))
|
|
|
|
|
|
|
|
|
|
|
|
return redirect(url_for('.post_show', id=el.post_id))
|
|
|
|
return redirect(url_for('post.post_show', id=el.post_id))
|
|
|
|
|
|
|
|
|
|
|
|
return redirect(url_for('main.posts'))
|
|
|
|
return redirect(url_for('main.posts'))
|