|
|
@ -4,7 +4,7 @@ from flask_login import login_required, current_user
|
|
|
|
from yadc.forms import UserForm, PostForm, TagForm, CommentForm
|
|
|
|
from yadc.forms import UserForm, PostForm, TagForm, CommentForm
|
|
|
|
|
|
|
|
|
|
|
|
from yadc import db
|
|
|
|
from yadc import db
|
|
|
|
from yadc.models import User, USER_STATUS, moderator_required, admin_required, Post, Tag, TAG_CATEGORY, Comment
|
|
|
|
from yadc.models import User, USER_STATUS, moderator_required, admin_required, Post, Tag, TAG_CATEGORY, Comment, POST_STATUS
|
|
|
|
from yadc.utils import flasherrors
|
|
|
|
from yadc.utils import flasherrors
|
|
|
|
|
|
|
|
|
|
|
|
bp = Blueprint('manage', __name__)
|
|
|
|
bp = Blueprint('manage', __name__)
|
|
|
@ -60,7 +60,7 @@ def manage_tags(page):
|
|
|
|
return render_template('manage/tags.html', tags=tags, elements=tags.items, createform=TagForm())
|
|
|
|
return render_template('manage/tags.html', tags=tags, elements=tags.items, createform=TagForm())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# ONLY THROUGH MANAGEMENT
|
|
|
|
@bp.route('/modify_user', methods=['POST'])
|
|
|
|
@bp.route('/modify_user', methods=['POST'])
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
@admin_required
|
|
|
|
@admin_required
|
|
|
@ -78,8 +78,10 @@ def modify_user():
|
|
|
|
|
|
|
|
|
|
|
|
db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
|
flash('New {} has been created.'.format(str(el)))
|
|
|
|
flash('New {} has been created.'.format(str(el)))
|
|
|
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
if el.is_current:
|
|
|
|
flash("You can't just delete yourself.")
|
|
|
|
flash("You can't just delete yourself.")
|
|
|
@ -91,6 +93,7 @@ def modify_user():
|
|
|
|
db.session.delete(el)
|
|
|
|
db.session.delete(el)
|
|
|
|
db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
|
flash('{} deleted.'.format(str(el)))
|
|
|
|
flash('{} deleted.'.format(str(el)))
|
|
|
|
|
|
|
|
|
|
|
|
elif form.edit.data:
|
|
|
|
elif form.edit.data:
|
|
|
|
# if form.username.data: el.username = form.username.data
|
|
|
|
# if form.username.data: el.username = form.username.data
|
|
|
|
|
|
|
|
|
|
|
@ -104,7 +107,7 @@ def modify_user():
|
|
|
|
flasherrors(form)
|
|
|
|
flasherrors(form)
|
|
|
|
return redirect(url_for('.manage_users'))
|
|
|
|
return redirect(url_for('.manage_users'))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# THROUGH MANAGEMENT AND POST PAGE + USERS CAN USE
|
|
|
|
@bp.route('/modify_post', methods=['POST'])
|
|
|
|
@bp.route('/modify_post', methods=['POST'])
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
def modify_post():
|
|
|
|
def modify_post():
|
|
|
@ -118,11 +121,13 @@ def modify_post():
|
|
|
|
if not current_user.is_moderator and not (el.author.is_current if el.author is not None else None):
|
|
|
|
if not current_user.is_moderator and not (el.author.is_current if el.author is not None else None):
|
|
|
|
flash("You don't have sufficient rights to do this.")
|
|
|
|
flash("You don't have sufficient rights to do this.")
|
|
|
|
return redirect(url_for('main.index'))
|
|
|
|
return redirect(url_for('main.index'))
|
|
|
|
|
|
|
|
|
|
|
|
if form.delete.data:
|
|
|
|
if form.delete.data:
|
|
|
|
el.remove_image_files()
|
|
|
|
el.remove_image_files()
|
|
|
|
db.session.delete(el)
|
|
|
|
db.session.delete(el)
|
|
|
|
db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
|
flash('{} deleted.'.format(str(el)))
|
|
|
|
flash('{} deleted.'.format(str(el)))
|
|
|
|
|
|
|
|
|
|
|
|
elif form.edit.data:
|
|
|
|
elif form.edit.data:
|
|
|
|
if form.rating.raw_data and form.rating.data: el.rating = form.rating.data
|
|
|
|
if form.rating.raw_data and form.rating.data: el.rating = form.rating.data
|
|
|
|
if form.status.raw_data and form.status.data: el.status = form.status.data
|
|
|
|
if form.status.raw_data and form.status.data: el.status = form.status.data
|
|
|
@ -135,21 +140,26 @@ def modify_post():
|
|
|
|
|
|
|
|
|
|
|
|
db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
|
flash('Changes to {} have been applied.'.format(str(el)))
|
|
|
|
flash('Changes to {} have been applied.'.format(str(el)))
|
|
|
|
|
|
|
|
|
|
|
|
elif form.approve.data:
|
|
|
|
elif form.approve.data:
|
|
|
|
if not current_user.is_moderator:
|
|
|
|
if not current_user.is_moderator:
|
|
|
|
flash("You don't have sufficient rights to do this.")
|
|
|
|
flash("You don't have sufficient rights to do this.")
|
|
|
|
return redirect(url_for('main.index'))
|
|
|
|
return redirect(url_for('main.index'))
|
|
|
|
post.status = POST_STATUS.active
|
|
|
|
el.status = POST_STATUS.active
|
|
|
|
post.approver = current_user
|
|
|
|
el.approver = current_user
|
|
|
|
|
|
|
|
|
|
|
|
db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
|
flash('Approved post {}'.format(str(post)))
|
|
|
|
flash('Approved post {}'.format(str(el)))
|
|
|
|
redirect(url_for('post.post_show', id=post.id))
|
|
|
|
# redirect(url_for('post.post_show', id=el.id))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if form.referer.data == 'post_show':
|
|
|
|
|
|
|
|
return redirect(url_for('post.post_show', id=el.id))
|
|
|
|
|
|
|
|
|
|
|
|
flasherrors(form)
|
|
|
|
flasherrors(form)
|
|
|
|
return redirect(url_for('.manage_posts'))
|
|
|
|
return redirect(url_for('.manage_posts'))
|
|
|
|
|
|
|
|
|
|
|
|
# Example perfect create/edit/delete form endpoint
|
|
|
|
# Example perfect create/edit/delete form endpoint
|
|
|
|
|
|
|
|
# ONLY THROUGH MANAGEMENT
|
|
|
|
@bp.route('/modify_tag', methods=['POST'])
|
|
|
|
@bp.route('/modify_tag', methods=['POST'])
|
|
|
|
@login_required
|
|
|
|
@login_required
|
|
|
|
@moderator_required
|
|
|
|
@moderator_required
|
|
|
@ -161,16 +171,18 @@ def modify_tag():
|
|
|
|
el = Tag(content_deser=form.content.data)
|
|
|
|
el = Tag(content_deser=form.content.data)
|
|
|
|
db.session.add(el)
|
|
|
|
db.session.add(el)
|
|
|
|
|
|
|
|
|
|
|
|
if form.category.data: el.category = form.category.data
|
|
|
|
if form.category.raw_data and form.category.data: el.category = form.category.data
|
|
|
|
|
|
|
|
|
|
|
|
db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
|
flash('New {} has been created.'.format(str(el)))
|
|
|
|
flash('New {} has been created.'.format(str(el)))
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
el = Tag.query.filter_by(id=form.id.data).first()
|
|
|
|
el = Tag.query.filter_by(id=form.id.data).first()
|
|
|
|
|
|
|
|
|
|
|
|
if form.delete.data:
|
|
|
|
if form.delete.data:
|
|
|
|
db.session.delete(el)
|
|
|
|
db.session.delete(el)
|
|
|
|
db.session.commit()
|
|
|
|
db.session.commit()
|
|
|
|
flash('{} deleted.'.format(str(el)))
|
|
|
|
flash('{} deleted.'.format(str(el)))
|
|
|
|
|
|
|
|
|
|
|
|
elif form.edit.data:
|
|
|
|
elif form.edit.data:
|
|
|
|
# if form.content.data: el.content = form.content.data
|
|
|
|
# if form.content.data: el.content = form.content.data
|
|
|
|
if form.category.raw_data and form.category.data: el.category = form.category.data
|
|
|
|
if form.category.raw_data and form.category.data: el.category = form.category.data
|
|
|
@ -180,37 +192,4 @@ def modify_tag():
|
|
|
|
|
|
|
|
|
|
|
|
flasherrors(form)
|
|
|
|
flasherrors(form)
|
|
|
|
return redirect(url_for('.manage_tags'))
|
|
|
|
return redirect(url_for('.manage_tags'))
|
|
|
|
# return redirect(url_for('main.index'))
|
|
|
|
# return redirect(url_for('main.index'))
|
|
|
|
|
|
|
|
|
|
|
|
# Creation/editing only through post page
|
|
|
|
|
|
|
|
@bp.route('/modify_comment', methods=['POST'])
|
|
|
|
|
|
|
|
@login_required
|
|
|
|
|
|
|
|
def modify_comment():
|
|
|
|
|
|
|
|
form = CommentForm(request.form)
|
|
|
|
|
|
|
|
# flash(str(request.form))
|
|
|
|
|
|
|
|
if form.validate():
|
|
|
|
|
|
|
|
if form.create.data:
|
|
|
|
|
|
|
|
el = Comment(content=form.content.data.strip(), post_id=form.post_id.data, user=current_user)
|
|
|
|
|
|
|
|
db.session.add(el)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
flash('Successfully submitted {}'.format(str(el)))
|
|
|
|
|
|
|
|
return redirect(url_for('post.post_show', id=form.post_id.data))
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
el = Comment.query.filter_by(id=form.id.data).first()
|
|
|
|
|
|
|
|
if not current_user.is_moderator and not (el.user.is_current if el.user is not None else None):
|
|
|
|
|
|
|
|
flash("You don't have sufficient rights to do this.")
|
|
|
|
|
|
|
|
return redirect(url_for('main.index'))
|
|
|
|
|
|
|
|
if form.delete.data:
|
|
|
|
|
|
|
|
db.session.delete(el)
|
|
|
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
flash('{} deleted.'.format(str(el)))
|
|
|
|
|
|
|
|
elif form.edit.data:
|
|
|
|
|
|
|
|
if form.content.raw_data and form.content.data: el.content = form.content.data.strip()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
flash('Changes to {} have been applied.'.format(str(el)))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return redirect(url_for('post.post_show', id=el.post_id))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return redirect(url_for('main.posts'))
|
|
|
|
|