Start moving things out of the admin module

master
kaiyou 7 years ago
parent 0223999a04
commit 9358a76d89

@ -11,6 +11,8 @@ import docker
from apscheduler.schedulers import background from apscheduler.schedulers import background
from mailu import models
# Create application # Create application
app = flask.Flask(__name__, static_url_path='/admin/app_static') app = flask.Flask(__name__, static_url_path='/admin/app_static')
@ -41,36 +43,45 @@ default_config = {
for key, value in default_config.items(): for key, value in default_config.items():
app.config[key] = os.environ.get(key, value) app.config[key] = os.environ.get(key, value)
# Setup components # Base application
flask_bootstrap.Bootstrap(app) flask_bootstrap.Bootstrap(app)
db = flask_sqlalchemy.SQLAlchemy(app) db = flask_sqlalchemy.SQLAlchemy(app)
migrate = flask_migrate.Migrate(app, db) migrate = flask_migrate.Migrate(app, db)
login_manager = flask_login.LoginManager()
login_manager.init_app(app)
babel = flask_babel.Babel(app)
translations = list(map(str, babel.list_translations()))
scheduler = background.BackgroundScheduler({
'apscheduler.timezone': 'UTC'
})
# Manager commnad # Manager commnad
manager = flask_script.Manager(app) manager = flask_script.Manager(app)
manager.add_command('db', flask_migrate.MigrateCommand) manager.add_command('db', flask_migrate.MigrateCommand)
# Task scheduling # Task scheduling
scheduler = background.BackgroundScheduler({
'apscheduler.timezone': 'UTC'
})
if not app.debug or os.environ.get('WERKZEUG_RUN_MAIN') == 'true': if not app.debug or os.environ.get('WERKZEUG_RUN_MAIN') == 'true':
scheduler.start() scheduler.start()
from mailu import tlstasks from mailu import tlstasks
# Babel configuration # Babel configuration
babel = flask_babel.Babel(app)
translations = list(map(str, babel.list_translations()))
@babel.localeselector @babel.localeselector
def get_locale(): def get_locale():
return flask.request.accept_languages.best_match(translations) return flask.request.accept_languages.best_match(translations)
# Finally setup the blueprint and redirect / # Login configuration
from mailu import admin login_manager = flask_login.LoginManager()
app.register_blueprint(admin.app, url_prefix='/admin') login_manager.init_app(app)
login_manager.login_view = "admin.login"
login_manager.user_loader(models.User.query.get)
@app.context_processor
def inject_user():
return dict(current_user=flask_login.current_user)
@app.route("/") @app.route("/")
def index(): def index():
return flask.redirect("/webmail/") return flask.redirect("/webmail/")
# Import views
from mailu.views import *

@ -1,33 +0,0 @@
from flask import Blueprint
from mailu import login_manager, db
import flask_login
app = Blueprint(
'admin', __name__,
template_folder='templates',
static_folder='static')
# Import models
from mailu.admin import models
# Register the login components
login_manager.login_view = "admin.login"
login_manager.user_loader(models.User.query.get)
@app.context_processor
def inject_user():
return dict(current_user=flask_login.current_user)
# Import views
from mailu.admin.views import \
admins, \
managers, \
base, \
aliases, \
users, \
domains, \
relays, \
alternatives, \
fetches

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save