implement thread mod ops
This commit is contained in:
parent
29bb9872d3
commit
bd556d102b
@ -1,9 +1,10 @@
|
||||
from flask import (
|
||||
Blueprint, render_template, request, redirect, url_for
|
||||
Blueprint, render_template, request, redirect, url_for, flash
|
||||
)
|
||||
from .users import login_required, mod_only, get_active_user, is_logged_in
|
||||
from ..db import db
|
||||
from ..models import Threads, Topics, Posts, Subscriptions
|
||||
from ..constants import InfoboxKind
|
||||
from .posts import create_post
|
||||
from slugify import slugify
|
||||
import math
|
||||
@ -118,21 +119,61 @@ def create_form():
|
||||
@bp.post("/<slug>/lock")
|
||||
@login_required
|
||||
def lock(slug):
|
||||
pass
|
||||
user = get_active_user()
|
||||
thread = Threads.find({'slug': slug})
|
||||
if not ((thread.user_id == user.id) or user.is_mod()):
|
||||
return 'no'
|
||||
target_op = request.form.get('target_op')
|
||||
thread.update({
|
||||
'is_locked': target_op
|
||||
})
|
||||
return redirect(url_for('.thread', slug=slug))
|
||||
|
||||
|
||||
@bp.post("/<slug>/sticky")
|
||||
@login_required
|
||||
@mod_only(".thread", slug = lambda slug: slug)
|
||||
def sticky(slug):
|
||||
pass
|
||||
user = get_active_user()
|
||||
thread = Threads.find({'slug': slug})
|
||||
if not ((thread.user_id == user.id) or user.is_mod()):
|
||||
return 'no'
|
||||
target_op = request.form.get('target_op')
|
||||
thread.update({
|
||||
'is_stickied': target_op
|
||||
})
|
||||
return redirect(url_for('.thread', slug=slug))
|
||||
|
||||
|
||||
@bp.post("/<slug>/move")
|
||||
@login_required
|
||||
@mod_only(".thread", slug = lambda slug: slug)
|
||||
def move(slug):
|
||||
pass
|
||||
user = get_active_user()
|
||||
|
||||
new_topic_id = request.form.get('new_topic_id', default=None)
|
||||
if new_topic_id is None:
|
||||
flash('Thread is already in this topic.', InfoboxKind.ERROR)
|
||||
return redirect(url_for('.thread', slug=slug))
|
||||
|
||||
new_topic = Topics.find({
|
||||
'id': new_topic_id
|
||||
})
|
||||
if not new_topic:
|
||||
return 'no'
|
||||
thread = Threads.find({
|
||||
'slug': slug
|
||||
})
|
||||
if not thread:
|
||||
return 'no'
|
||||
if new_topic.id == thread.topic_id:
|
||||
flash('Thread is already in this topic.', InfoboxKind.ERROR)
|
||||
return redirect(url_for('.thread', slug=slug))
|
||||
|
||||
old_topic = Topics.find({'id': thread.topic_id})
|
||||
thread.update({'topic_id': new_topic_id})
|
||||
flash(f'Topic moved from "{old_topic.name}" to "{new_topic.name}".', InfoboxKind.INFO)
|
||||
return redirect(url_for('.thread', slug=slug))
|
||||
|
||||
|
||||
@bp.post("/<slug>/subscribe")
|
||||
|
@ -28,13 +28,13 @@
|
||||
{% endif %}
|
||||
{% if can_lock %}
|
||||
<form class="modform" action="{{ url_for("threads.lock", slug=thread.slug) }}" method="post">
|
||||
<input type=hidden value="{{ (not thread.is_locked) | int }}">
|
||||
<input type=hidden name='target_op' value="{{ (not thread.is_locked) | int }}">
|
||||
<input class="warn" type="submit" value="{{"Unlock thread" if thread.is_locked else "Lock thread"}}">
|
||||
</form>
|
||||
{% endif %}
|
||||
{% if active_user.is_mod() %}
|
||||
<form class="modform" action="{{ url_for("threads.sticky", slug=thread.slug) }}" method="post">
|
||||
<input type=hidden value="{{ (not thread.is_stickied) | int }}">
|
||||
<input type=hidden name='target_op' value="{{ (not thread.is_stickied) | int }}">
|
||||
<input class="warn" type="submit" value="{{"Unsticky thread" if thread.is_stickied else "Sticky thread"}}">
|
||||
</form>
|
||||
<form class="modform" action="{{ url_for("threads.move", slug=thread.slug) }}" method="post">
|
||||
|
Loading…
Reference in New Issue
Block a user