Files
myriad/myriad/__init__.py
2026-05-19 22:31:12 +01:00

84 lines
2.9 KiB
Python

import os, datetime
from flask import Flask
from myriad.utilities import server_time, get_datetime_str, remove_html, get_pages
from myriad.db import get_db
def create_app():
# create and configure the app
app = Flask(__name__, instance_relative_config=True)
app.config.from_pyfile('config.py')
app.config.from_mapping(DATABASE=os.path.join(app.instance_path, 'database.sqlite'),)
# ensure the necessary directories exist
os.makedirs(app.instance_path, exist_ok=True)
os.makedirs(app.config["ICON_UPLOAD_FOLDER"], exist_ok=True)
os.makedirs(app.config["BLINKIES_UPLOAD_FOLDER"], exist_ok=True)
os.makedirs(app.config["STAMPS_UPLOAD_FOLDER"], exist_ok=True)
os.makedirs(app.config["MISC_UPLOAD_FOLDER"], exist_ok=True)
os.makedirs(app.config["TMP_FOLDER"], exist_ok=True)
from . import db
db.init_app(app)
from . import commands
commands.init_commands(app)
from . import auth
app.register_blueprint(auth.bp)
from . import home
app.register_blueprint(home.bp)
app.add_url_rule('/', endpoint='index')
from . import manage
app.register_blueprint(manage.bp)
from . import blog
app.register_blueprint(blog.bp)
@app.context_processor
def utility_processor():
def get_themes():
themes = os.listdir(app.config["THEMES_FOLDER"])
return themes
def w_server_time():
return server_time()
def w_get_datetime_str(dt_obj):
return get_datetime_str(dt_obj)
def get_member(mid):
db = get_db()
member = db.execute("SELECT * FROM member WHERE id=(?)",(mid,)).fetchone()
return member
def get_system_name():
return app.config["SYSTEM_NAME"]
def get_pages_name():
return app.config["PAGES_NAME"]
def check_favicon():
if os.path.isfile(os.path.join(app.config["STATIC_FOLDER"], "favicon.ico")):
return True
return False
def get_pins_public():
db = get_db()
pins = db.execute("SELECT * FROM member WHERE homepage=(?) AND public=(?) ORDER BY member_name",(1, 1)).fetchall()
return pins
def get_pins_all():
db = get_db()
pins = db.execute("SELECT * FROM member WHERE homepage=(?) ORDER BY member_name",(1,)).fetchall()
return pins
return dict(get_themes=get_themes,
server_time=w_server_time,
get_datetime_str=w_get_datetime_str,
get_member=get_member,
remove_html=remove_html,
get_pages=get_pages,
get_system_name=get_system_name,
get_pages_name=get_pages_name,
check_favicon=check_favicon,
get_pins_public=get_pins_public,
get_pins_all=get_pins_all)
return app