85 lines
2.5 KiB
Python
85 lines
2.5 KiB
Python
import os
|
|
from flask import Flask, render_template, g
|
|
from pathlib import Path
|
|
from .auth import login_required
|
|
|
|
|
|
DATABASE_NAME = "kanken_online.sqlite"
|
|
def create_app(test_config=None):
|
|
app = Flask(__name__, instance_relative_config=True)
|
|
app.config.from_mapping(
|
|
SECRET_KEY="dev",
|
|
DATABASE=str(Path(app.instance_path) / DATABASE_NAME)
|
|
)
|
|
|
|
if test_config is None:
|
|
app.config.from_pyfile("config.py", silent=True)
|
|
else:
|
|
app.config.from_mapping(test_config)
|
|
|
|
# Ensure instance path exists
|
|
os.makedirs(app.instance_path, exist_ok=True)
|
|
|
|
@app.route("/hello")
|
|
def hello():
|
|
return "Hello, World!"
|
|
|
|
@app.route("/")
|
|
def index():
|
|
return render_template("index.html")
|
|
|
|
@app.route("/about")
|
|
def about_page():
|
|
return render_template("about.html")
|
|
|
|
@app.route("/options")
|
|
@login_required
|
|
def options():
|
|
return render_template("options.html")
|
|
|
|
@app.route("/kanji/<kanji>")
|
|
def kanji_page(kanji: str):
|
|
# TODO use database to get kanji
|
|
class Kanji():
|
|
pass
|
|
|
|
# Highly tentative testing data
|
|
kanji = Kanji()
|
|
kanji.character = "麻"
|
|
kanji.is_joyo = "joyo kanji"
|
|
kanji.level = "pre-2"
|
|
kanji.strokes = 11
|
|
kanji.radical = "麻"
|
|
kanji.added_strokes = 0
|
|
kanji.goon = "マ"
|
|
kanji.kanon = "バ"
|
|
kanji.toon = ""
|
|
kanji.soon = ""
|
|
kanji.kanyoon = ""
|
|
kanji.kun = "あさ, しびれる"
|
|
kanji.meanings = "①あさ。クワ科の一年草。また、あさ類の総称。「亜麻」「乱麻」 ②しびれる。しびれ。「麻酔」「麻痺(マヒ)」類痲(マ)"
|
|
kanji.glyph_origin = "会意。广(げん)(いえ)と、𣏟(はい)(あさ)とから成り、屋下であさの繊維をはぎとる、ひいて「あさ」の意を表す。"
|
|
|
|
return render_template("kanji.html", kanji=kanji)
|
|
|
|
@app.route("/kotoba/<kotoba>")
|
|
def kotoba_page(kotoba: str):
|
|
return render_template("kotoba.html", kotoba=kotoba)
|
|
|
|
from . import database
|
|
database.initialize_app(app)
|
|
|
|
from . import auth, api, forum, search
|
|
app.register_blueprint(auth.blueprint)
|
|
app.register_blueprint(api.blueprint)
|
|
app.register_blueprint(forum.blueprint)
|
|
app.register_blueprint(search.blueprint)
|
|
|
|
from . import lang
|
|
|
|
def use_english(text_id: str):
|
|
return lang.localize(text_id, lang.JAPANESE)
|
|
app.jinja_env.globals.update(localize=use_english)
|
|
|
|
|
|
return app |