Add new lexicon model to request context
This commit is contained in:
parent
4b33f17169
commit
23873f7a52
|
@ -3,12 +3,13 @@ import os
|
|||
from flask import Flask, render_template
|
||||
from flask_login import LoginManager
|
||||
|
||||
from amanuensis.config import get
|
||||
from amanuensis.config import get, root
|
||||
from amanuensis.server.auth import get_bp as get_auth_bp
|
||||
from amanuensis.server.home import get_bp as get_home_bp
|
||||
from amanuensis.server.helpers import register_custom_filters
|
||||
from amanuensis.server.lexicon import get_bp as get_lex_bp
|
||||
from amanuensis.user import AnonymousUserModel
|
||||
from amanuensis.models import ModelFactory
|
||||
|
||||
# Flask app init
|
||||
static_root = os.path.abspath(get("static_root"))
|
||||
|
@ -17,6 +18,7 @@ app = Flask(
|
|||
template_folder="../templates",
|
||||
static_folder=static_root)
|
||||
app.secret_key = bytes.fromhex(get('secret_key'))
|
||||
app.config['model_factory'] = ModelFactory(root)
|
||||
app.jinja_options['trim_blocks'] = True
|
||||
app.jinja_options['lstrip_blocks'] = True
|
||||
register_custom_filters(app)
|
||||
|
|
|
@ -3,14 +3,14 @@ from datetime import datetime
|
|||
from functools import wraps
|
||||
|
||||
# Third party imports
|
||||
from flask import g, flash, redirect, url_for
|
||||
from flask import g, flash, redirect, url_for, current_app
|
||||
from flask_login import current_user
|
||||
|
||||
# Module imports
|
||||
from amanuensis.lexicon import LexiconModel
|
||||
from amanuensis.parser import filesafe_title
|
||||
from amanuensis.user import UserModel
|
||||
|
||||
from amanuensis.models import ModelFactory
|
||||
|
||||
def register_custom_filters(app):
|
||||
"""Adds custom filters to the Flask app"""
|
||||
|
@ -42,6 +42,9 @@ def lexicon_param(route):
|
|||
if g.lexicon is None:
|
||||
flash("Couldn't find a lexicon with the name '{}'".format(name))
|
||||
return redirect(url_for("home.home"))
|
||||
# TODO transition to new model
|
||||
model_factory: ModelFactory = current_app.config['model_factory']
|
||||
g.lexicon_ = model_factory.lexicon(name)
|
||||
return route(**kwargs)
|
||||
return with_lexicon
|
||||
|
||||
|
|
Loading…
Reference in New Issue