re-parse MOTDs if required on init
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
from flask import Flask, session, request
|
from flask import Flask, session, request
|
||||||
from dotenv import load_dotenv
|
from dotenv import load_dotenv
|
||||||
from .models import Avatars, Users, PostHistory, Posts
|
from .models import Avatars, Users, PostHistory, Posts, MOTD
|
||||||
from .auth import digest
|
from .auth import digest
|
||||||
from .routes.users import is_logged_in, get_active_user, get_prefers_theme
|
from .routes.users import is_logged_in, get_active_user, get_prefers_theme
|
||||||
from .routes.threads import get_post_url
|
from .routes.threads import get_post_url
|
||||||
@@ -51,6 +51,7 @@ def create_deleted_user():
|
|||||||
def reparse_babycode():
|
def reparse_babycode():
|
||||||
print('Re-parsing babycode, this may take a while...')
|
print('Re-parsing babycode, this may take a while...')
|
||||||
from .db import db
|
from .db import db
|
||||||
|
from .constants import MOTD_BANNED_TAGS
|
||||||
post_histories = PostHistory.findall([
|
post_histories = PostHistory.findall([
|
||||||
('markup_language', '=', 'babycode'),
|
('markup_language', '=', 'babycode'),
|
||||||
('format_version', 'IS NOT', BABYCODE_VERSION)
|
('format_version', 'IS NOT', BABYCODE_VERSION)
|
||||||
@@ -80,6 +81,20 @@ def reparse_babycode():
|
|||||||
})
|
})
|
||||||
print(f'Re-parsed {len(users_with_sigs)} user sigs.')
|
print(f'Re-parsed {len(users_with_sigs)} user sigs.')
|
||||||
|
|
||||||
|
stale_motds = MOTD.findall([
|
||||||
|
['markup_language', '=', 'babycode'],
|
||||||
|
['format_version', 'IS NOT', BABYCODE_VERSION]
|
||||||
|
])
|
||||||
|
if stale_motds:
|
||||||
|
print('Re-parsing MOTDs...')
|
||||||
|
with db.transaction():
|
||||||
|
for motd in stale_motds:
|
||||||
|
motd.update({
|
||||||
|
'body_rendered': babycode_to_html(motd['body_original_markup'], banned_tags=MOTD_BANNED_TAGS),
|
||||||
|
'format_version': BABYCODE_VERSION,
|
||||||
|
})
|
||||||
|
print('Re-parsing MOTDs done.')
|
||||||
|
|
||||||
print('Re-parsing done.')
|
print('Re-parsing done.')
|
||||||
|
|
||||||
def create_app():
|
def create_app():
|
||||||
|
|||||||
@@ -47,6 +47,10 @@ REACTION_EMOJI = [
|
|||||||
'scissors',
|
'scissors',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
MOTD_BANNED_TAGS = [
|
||||||
|
'img', 'spoiler',
|
||||||
|
]
|
||||||
|
|
||||||
def permission_level_string(perm):
|
def permission_level_string(perm):
|
||||||
return PermissionLevelString[PermissionLevel(int(perm))]
|
return PermissionLevelString[PermissionLevel(int(perm))]
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ from flask import (
|
|||||||
)
|
)
|
||||||
from .users import get_active_user, is_logged_in
|
from .users import get_active_user, is_logged_in
|
||||||
from ..models import Users, PasswordResetLinks, MOTD
|
from ..models import Users, PasswordResetLinks, MOTD
|
||||||
from ..constants import InfoboxKind
|
from ..constants import InfoboxKind, MOTD_BANNED_TAGS
|
||||||
from ..lib.babycode import babycode_to_html, BABYCODE_VERSION
|
from ..lib.babycode import babycode_to_html, BABYCODE_VERSION
|
||||||
from ..db import db
|
from ..db import db
|
||||||
import secrets
|
import secrets
|
||||||
@@ -73,7 +73,7 @@ def motd_editor_form():
|
|||||||
data = {
|
data = {
|
||||||
'title': title,
|
'title': title,
|
||||||
'body_original_markup': orig_body,
|
'body_original_markup': orig_body,
|
||||||
'body_rendered': babycode_to_html(orig_body, banned_tags=['img', 'spoiler']),
|
'body_rendered': babycode_to_html(orig_body, banned_tags=MOTD_BANNED_TAGS),
|
||||||
'format_version': BABYCODE_VERSION,
|
'format_version': BABYCODE_VERSION,
|
||||||
'edited_at': int(time.time()),
|
'edited_at': int(time.time()),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user