97 lines
2.9 KiB
Python
97 lines
2.9 KiB
Python
from flask import Blueprint, abort, redirect, url_for, request, render_template
|
|
from ..auth import is_logged_in, get_active_user, csrf_verified
|
|
from ..models import Topics, Threads
|
|
bp = Blueprint('mod', __name__, url_prefix='/mod/')
|
|
|
|
@bp.before_request
|
|
def mod_only():
|
|
if not is_logged_in():
|
|
abort(403)
|
|
if not get_active_user().is_mod():
|
|
abort(403)
|
|
|
|
@bp.get('/')
|
|
def index():
|
|
return 'stub'
|
|
|
|
@bp.get('/topics/new/')
|
|
def new_topic():
|
|
return render_template('mod/new_topic.html')
|
|
|
|
@bp.post('/topics/new/')
|
|
def new_topic_post():
|
|
topic = Topics.new(request.form.get('name'), request.form.get('description'))
|
|
return redirect(url_for('topics.topic_by_id', topic_id=topic.id))
|
|
|
|
@bp.get('/topics/sort/')
|
|
def sort_topics():
|
|
return 'stub'
|
|
|
|
@bp.get('/topics/<int:topic_id>/edit/')
|
|
def edit_topic(topic_id):
|
|
topic = Topics.find({'id': topic_id})
|
|
if not topic:
|
|
abort(404)
|
|
return render_template('mod/edit_topic.html', topic=topic)
|
|
|
|
@bp.post('/topics/<int:topic_id>/edit/')
|
|
def edit_topic_post(topic_id):
|
|
topic = Topics.find({'id': topic_id})
|
|
if not topic:
|
|
abort(404)
|
|
topic.update({
|
|
'name': request.form.get('name').strip(),
|
|
'description': request.form.get('description').strip(),
|
|
})
|
|
return redirect(url_for('topics.topic_by_id', topic_id=topic.id))
|
|
|
|
@bp.post('/topics/<int:topic_id>/lock/')
|
|
def lock_topic(topic_id):
|
|
topic = Topics.find({'id': topic_id})
|
|
if not topic:
|
|
abort(404)
|
|
topic.update({'is_locked': request.form.get('lock', default=0)})
|
|
return redirect(url_for('topics.topic_by_id', topic_id=topic.id))
|
|
|
|
@bp.post('/threads/<int:thread_id>/move/')
|
|
def move_thread(thread_id):
|
|
thread = Threads.find({'id': thread_id})
|
|
if not thread:
|
|
abort(404)
|
|
target_topic = Topics.find({'id': request.form.get('new_topic_id', default=None)})
|
|
if not target_topic:
|
|
abort(404)
|
|
thread.update({'topic_id': target_topic.id})
|
|
return redirect(url_for('threads.thread_by_id', thread_id=thread.id))
|
|
|
|
@bp.post('/threads/<int:thread_id>/lock/')
|
|
def lock_thread(thread_id):
|
|
thread = Threads.find({'id': thread_id})
|
|
if not thread:
|
|
abort(404)
|
|
thread.update({'is_locked': request.form.get('lock')})
|
|
return redirect(url_for('threads.thread_by_id', thread_id=thread.id))
|
|
|
|
@bp.post('/threads/<int:thread_id>/sticky/')
|
|
def sticky_thread(thread_id):
|
|
thread = Threads.find({'id': thread_id})
|
|
if not thread:
|
|
abort(404)
|
|
thread.update({'is_stickied': request.form.get('sticky')})
|
|
return redirect(url_for('threads.thread_by_id', thread_id=thread.id))
|
|
|
|
@bp.post('/users/<int:user_id>/make-guest/')
|
|
@csrf_verified
|
|
def make_user_guest(user_id):
|
|
return 'stub'
|
|
|
|
@bp.post('/users/<int:user_id>/make-user/')
|
|
@csrf_verified
|
|
def make_user_regular(user_id):
|
|
return 'stub'
|
|
|
|
@bp.post('/users/<int:user_id>/make-mod/')
|
|
@csrf_verified
|
|
def make_user_mod(user_id):
|
|
return 'stub'
|