add motd editor and motd display
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
from flask import Blueprint, abort, redirect, url_for, request, render_template, flash
|
||||
from ..constants import InfoboxKind, PermissionLevel
|
||||
from ..constants import InfoboxKind, PermissionLevel, MOTD_BANNED_TAGS
|
||||
from ..auth import is_logged_in, get_active_user, csrf_verified
|
||||
from ..models import Topics, Threads, Users
|
||||
from ..models import Topics, Threads, Users, MOTD
|
||||
from ..lib.babycode import babycode_to_html, BABYCODE_VERSION
|
||||
from slugify import slugify
|
||||
from functools import wraps
|
||||
import time
|
||||
@@ -24,7 +25,49 @@ def admin_only(view_func):
|
||||
|
||||
@bp.get('/')
|
||||
def index():
|
||||
return 'stub'
|
||||
motd = MOTD.get_all()[0] if MOTD.has_motd() else None
|
||||
return render_template('mod/panel.html', MOTD_BANNED_TAGS=MOTD_BANNED_TAGS, motd=motd)
|
||||
|
||||
@bp.post('/motd/set/')
|
||||
def set_motd():
|
||||
title = request.form.get('motd_title', '')
|
||||
if not title:
|
||||
flash('MOTD must have a title.', InfoboxKind.ERROR)
|
||||
return redirect(url_for('.index'))
|
||||
orig_body = request.form.get('babycode_content', '')
|
||||
if not orig_body:
|
||||
flash('MOTD must have a body.', InfoboxKind.ERROR)
|
||||
return redirect(url_for('.index'))
|
||||
user = get_active_user()
|
||||
data = {
|
||||
'title': title.strip(),
|
||||
'body_original_markup': orig_body,
|
||||
'body_rendered': babycode_to_html(orig_body, banned_tags=MOTD_BANNED_TAGS).result,
|
||||
'format_version': BABYCODE_VERSION,
|
||||
'edited_at': int(time.time()),
|
||||
'user_id': user.id,
|
||||
}
|
||||
if MOTD.has_motd():
|
||||
motd = MOTD.get_all()[0]
|
||||
motd.update(data)
|
||||
message = 'MOTD updated.'
|
||||
else:
|
||||
data['created_at'] = int(time.time())
|
||||
motd = MOTD.create(data)
|
||||
message = 'MOTD created.'
|
||||
|
||||
flash(message, InfoboxKind.INFO)
|
||||
return redirect(url_for('.index'))
|
||||
|
||||
@bp.post('/motd/clear/')
|
||||
def clear_motd():
|
||||
if not MOTD.has_motd():
|
||||
return redirect(url_for('.index'))
|
||||
|
||||
current = MOTD.get_all()[0]
|
||||
current.delete()
|
||||
flash('MOTD cleared.', InfoboxKind.INFO)
|
||||
return redirect(url_for('.index'))
|
||||
|
||||
@bp.get('/topics/new/')
|
||||
def new_topic():
|
||||
@@ -35,10 +78,6 @@ 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})
|
||||
|
||||
Reference in New Issue
Block a user