def lock_topic(topic_id): topic = Topic.query.filter_by(id=topic_id).first_or_404() if not can_lock_topic(user=current_user, forum=topic.forum): flash("Yo do not have the permissions to lock this topic", "danger") return redirect(url_for("forum.view_topic", topic_id=topic.id)) topic.locked = True topic.save() return redirect(url_for("forum.view_topic", topic_id=topic.id))
def unlock_topic(topic_id): topic = Topic.query.filter_by(id=topic_id).first_or_404() # Unlock is basically the same as lock if not can_lock_topic(user=current_user, forum=topic.forum): flash("Yo do not have the permissions to unlock this topic", "danger") return redirect(url_for("forum.view_topic", topic_id=topic.id)) topic.locked = False topic.save() return redirect(url_for("forum.view_topic", topic_id=topic.id))