re-parse MOTDs if required on init
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from flask import Flask, session, request
|
||||
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 .routes.users import is_logged_in, get_active_user, get_prefers_theme
|
||||
from .routes.threads import get_post_url
|
||||
@@ -51,6 +51,7 @@ def create_deleted_user():
|
||||
def reparse_babycode():
|
||||
print('Re-parsing babycode, this may take a while...')
|
||||
from .db import db
|
||||
from .constants import MOTD_BANNED_TAGS
|
||||
post_histories = PostHistory.findall([
|
||||
('markup_language', '=', 'babycode'),
|
||||
('format_version', 'IS NOT', BABYCODE_VERSION)
|
||||
@@ -80,6 +81,20 @@ def reparse_babycode():
|
||||
})
|
||||
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.')
|
||||
|
||||
def create_app():
|
||||
|
||||
Reference in New Issue
Block a user