draw the rest of the owl
This commit is contained in:
@@ -3,15 +3,15 @@ from dotenv import load_dotenv
|
||||
from .models import Avatars, Users, PostHistory, Posts, MOTD, BadgeUploads
|
||||
from .auth import digest
|
||||
from .routes.users import is_logged_in, get_active_user, get_prefers_theme
|
||||
from .routes.threads import get_post_url
|
||||
from .constants import (
|
||||
PermissionLevel, permission_level_string,
|
||||
InfoboxKind, InfoboxHTMLClass,
|
||||
REACTION_EMOJI, MOTD_BANNED_TAGS,
|
||||
SIG_BANNED_TAGS, STRICT_BANNED_TAGS,
|
||||
)
|
||||
from .lib.babycode import babycode_to_html, EMOJI, BABYCODE_VERSION
|
||||
from datetime import datetime
|
||||
from .lib.babycode import babycode_to_html, babycode_to_rssxml, EMOJI, BABYCODE_VERSION
|
||||
from datetime import datetime, timezone
|
||||
from flask_caching import Cache
|
||||
import os
|
||||
import time
|
||||
import secrets
|
||||
@@ -55,6 +55,18 @@ def reparse_babycode():
|
||||
print('Re-parsing babycode, this may take a while...')
|
||||
from .db import db
|
||||
from .constants import MOTD_BANNED_TAGS
|
||||
|
||||
post_histories_without_rss = PostHistory.findall([
|
||||
('markup_language', '=', 'babycode'),
|
||||
('content_rss', 'IS', None),
|
||||
])
|
||||
|
||||
with db.transaction():
|
||||
for ph in post_histories_without_rss:
|
||||
ph.update({
|
||||
'content_rss': babycode_to_rssxml(ph['original_markup']),
|
||||
})
|
||||
|
||||
post_histories = PostHistory.findall([
|
||||
('markup_language', '=', 'babycode'),
|
||||
('format_version', 'IS NOT', BABYCODE_VERSION)
|
||||
@@ -65,6 +77,7 @@ def reparse_babycode():
|
||||
for ph in post_histories:
|
||||
ph.update({
|
||||
'content': babycode_to_html(ph['original_markup']).result,
|
||||
'content_rss': babycode_to_rssxml(ph['original_markup']),
|
||||
'format_version': BABYCODE_VERSION,
|
||||
})
|
||||
print('Re-parsing posts done.')
|
||||
@@ -125,6 +138,8 @@ def bind_default_badges(path):
|
||||
})
|
||||
|
||||
|
||||
cache = Cache()
|
||||
|
||||
def create_app():
|
||||
app = Flask(__name__)
|
||||
app.config['SITE_NAME'] = 'Pyrom'
|
||||
@@ -133,6 +148,10 @@ def create_app():
|
||||
app.config['USERS_CAN_INVITE'] = False
|
||||
app.config['ADMIN_CONTACT_INFO'] = ''
|
||||
app.config['GUIDE_DESCRIPTION'] = ''
|
||||
|
||||
app.config['CACHE_TYPE'] = 'FileSystemCache'
|
||||
app.config['CACHE_DEFAULT_TIMEOUT'] = 300
|
||||
|
||||
try:
|
||||
app.config.from_file('../config/pyrom_config.toml', load=tomllib.load, text=False)
|
||||
except FileNotFoundError:
|
||||
@@ -142,6 +161,7 @@ def create_app():
|
||||
app.static_folder = os.path.join(os.path.dirname(__file__), "../data/static")
|
||||
app.debug = True
|
||||
app.config["DB_PATH"] = "data/db/db.dev.sqlite"
|
||||
app.config["SERVER_NAME"] = "localhost:8080"
|
||||
load_dotenv()
|
||||
else:
|
||||
app.config["DB_PATH"] = "data/db/db.prod.sqlite"
|
||||
@@ -156,6 +176,13 @@ def create_app():
|
||||
os.makedirs(os.path.dirname(app.config["DB_PATH"]), exist_ok = True)
|
||||
os.makedirs(os.path.dirname(app.config["BADGES_UPLOAD_PATH"]), exist_ok = True)
|
||||
|
||||
if app.config['CACHE_TYPE'] == 'FileSystemCache':
|
||||
cache_dir = app.config.get('CACHE_DIR', 'data/_cached')
|
||||
os.makedirs(cache_dir, exist_ok = True)
|
||||
app.config['CACHE_DIR'] = cache_dir
|
||||
|
||||
cache.init_app(app)
|
||||
|
||||
css_dir = 'data/static/css/'
|
||||
allowed_themes = []
|
||||
for f in os.listdir(css_dir):
|
||||
@@ -229,10 +256,12 @@ def create_app():
|
||||
|
||||
@app.context_processor
|
||||
def inject_funcs():
|
||||
from .routes.threads import get_post_url
|
||||
return {
|
||||
'get_post_url': get_post_url,
|
||||
'get_prefers_theme': get_prefers_theme,
|
||||
'get_motds': MOTD.get_all,
|
||||
'get_time_now': lambda: int(time.time()),
|
||||
}
|
||||
|
||||
@app.template_filter("ts_datetime")
|
||||
@@ -308,4 +337,8 @@ def create_app():
|
||||
def fromjson(subject: str):
|
||||
return json.loads(subject)
|
||||
|
||||
@app.template_filter('iso8601')
|
||||
def unix_to_iso8601(subject: str):
|
||||
return datetime.fromtimestamp(int(subject), timezone.utc).isoformat()
|
||||
|
||||
return app
|
||||
|
||||
Reference in New Issue
Block a user