add motd schema and motd editor
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
from flask import (
|
||||
Blueprint, render_template, request, redirect, url_for
|
||||
Blueprint, render_template, request, redirect, url_for,
|
||||
flash
|
||||
)
|
||||
from .users import get_active_user, is_logged_in
|
||||
from ..models import Users, PasswordResetLinks
|
||||
from ..models import Users, PasswordResetLinks, MOTD
|
||||
from ..constants import InfoboxKind
|
||||
from ..lib.babycode import babycode_to_html, BABYCODE_VERSION
|
||||
from ..db import db
|
||||
import secrets
|
||||
import time
|
||||
@@ -55,3 +58,47 @@ def create_reset_pass(user_id):
|
||||
@bp.get('/panel')
|
||||
def panel():
|
||||
return render_template('mod/panel.html')
|
||||
|
||||
|
||||
@bp.get('/motd')
|
||||
def motd_editor():
|
||||
current = MOTD.get_all()[0] if MOTD.has_motd() else None
|
||||
return render_template('mod/motd.html', current=current)
|
||||
|
||||
|
||||
@bp.post('/motd')
|
||||
def motd_editor_form():
|
||||
orig_body = request.form.get('body', default='')
|
||||
title = request.form.get('title', default='')
|
||||
data = {
|
||||
'title': title,
|
||||
'body_original_markup': orig_body,
|
||||
'body_rendered': babycode_to_html(orig_body, banned_tags=['img', 'spoiler']),
|
||||
'format_version': BABYCODE_VERSION,
|
||||
'edited_at': int(time.time()),
|
||||
}
|
||||
|
||||
if MOTD.has_motd():
|
||||
motd = MOTD.get_all()[0]
|
||||
motd.update(data)
|
||||
message = 'MOTD updated.'
|
||||
else:
|
||||
data['created_at'] = int(time.time())
|
||||
data['user_id'] = get_active_user().id
|
||||
motd = MOTD.create(data)
|
||||
message = 'MOTD created.'
|
||||
|
||||
flash(message, InfoboxKind.INFO)
|
||||
return redirect(url_for('.motd_editor'))
|
||||
|
||||
|
||||
@bp.post('/motd/delete')
|
||||
def motd_delete():
|
||||
if not MOTD.has_motd():
|
||||
flash('No MOTD to delete.', InfoboxKind.WARN)
|
||||
return redirect(url_for('.motd_editor'))
|
||||
|
||||
current = MOTD.get_all()[0]
|
||||
current.delete()
|
||||
flash('MOTD deleted.', InfoboxKind.INFO)
|
||||
return redirect(url_for('.motd_editor'))
|
||||
|
||||
Reference in New Issue
Block a user