add most mod routes
This commit is contained in:
@@ -1,27 +1,81 @@
|
||||
from flask import Blueprint
|
||||
|
||||
from flask import Blueprint, abort, redirect, url_for, request, render_template
|
||||
from ..auth import is_logged_in, get_active_user
|
||||
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 'stub'
|
||||
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', slug=topic.slug))
|
||||
|
||||
@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', slug=topic.slug))
|
||||
|
||||
@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', slug=topic.slug))
|
||||
|
||||
@bp.post('/threads/<int:thread_id>/move')
|
||||
def move_thread(thread_id):
|
||||
return 'stub'
|
||||
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', slug=thread.slug))
|
||||
|
||||
@bp.post('/threads/<int:thread_id>/lock')
|
||||
def lock_thread(thread_id):
|
||||
return 'stub'
|
||||
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', slug=thread.slug))
|
||||
|
||||
@bp.post('/threads/<int:thread_id>/sticky')
|
||||
def sticky_thread(thread_id):
|
||||
return 'stub'
|
||||
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', slug=thread.slug))
|
||||
|
||||
Reference in New Issue
Block a user