2017-06-09 06:25:41 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
###############################################################################
|
2021-06-11 21:31:14 +00:00
|
|
|
# ScribeEngine - Open Source Content Management System #
|
2017-06-09 06:25:41 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
2021-06-11 21:31:14 +00:00
|
|
|
# Copyright (c) 2010-2021 Raoul Snyman #
|
2017-06-09 06:25:41 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
2021-06-11 21:31:14 +00:00
|
|
|
# This file is part of ScribeEngine. #
|
|
|
|
# #
|
|
|
|
# ScribeEngine is free software: you can redistribute it and/or modify it #
|
2017-06-09 06:25:41 +00:00
|
|
|
# under the terms of the GNU General Public License as published by the Free #
|
2021-06-11 21:31:14 +00:00
|
|
|
# Software Foundation, either version 3 of the License, or (at your option) #
|
|
|
|
# any later version. #
|
2017-06-09 06:25:41 +00:00
|
|
|
# #
|
2021-06-11 21:31:14 +00:00
|
|
|
# ScribeEngine is distributed in the hope that it will be useful, but WITHOUT #
|
2017-06-09 06:25:41 +00:00
|
|
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
2021-06-11 21:31:14 +00:00
|
|
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
2017-06-09 06:25:41 +00:00
|
|
|
# more details. #
|
|
|
|
# #
|
|
|
|
# You should have received a copy of the GNU General Public License along #
|
2021-06-11 21:31:14 +00:00
|
|
|
# with ScribeEngine. If not, see <https://www.gnu.org/licenses/>. #
|
2017-06-09 06:25:41 +00:00
|
|
|
###############################################################################
|
|
|
|
"""
|
|
|
|
The :mod:`~scribeengine` module sets up and runs ScribeEngine
|
|
|
|
"""
|
|
|
|
import os
|
|
|
|
|
|
|
|
from flask import Flask
|
|
|
|
from flask_mail import Mail
|
2019-02-14 23:01:27 +00:00
|
|
|
from flask_themes2 import Themes, packaged_themes_loader, theme_paths_loader, load_themes_from
|
|
|
|
from flask_user import UserManager
|
2017-06-09 06:25:41 +00:00
|
|
|
|
2021-01-30 04:19:48 +00:00
|
|
|
from scribeengine.admin import admin
|
2017-06-09 06:25:41 +00:00
|
|
|
from scribeengine.config import read_config_from_file
|
|
|
|
from scribeengine.db import db
|
|
|
|
from scribeengine.models import User
|
2019-02-14 23:01:27 +00:00
|
|
|
from scribeengine.views.account import account
|
2021-06-11 21:31:14 +00:00
|
|
|
from scribeengine.views.node import node_views
|
2019-02-14 23:01:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
def _scribeengine_themes_loader(app):
|
|
|
|
"""
|
|
|
|
Loads ScribeEngine's themes
|
|
|
|
"""
|
|
|
|
themes_path = os.path.join(os.path.dirname(__file__), 'themes')
|
|
|
|
return load_themes_from(themes_path)
|
2017-06-09 06:25:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
def create_app(config_file=None):
|
|
|
|
"""
|
|
|
|
Create the application object
|
|
|
|
"""
|
|
|
|
application = Flask('ScribeEngine')
|
|
|
|
# Set up configuration
|
|
|
|
if not config_file:
|
|
|
|
if os.environ.get('SCRIBEENGINE_CONFIG'):
|
|
|
|
config_file = os.environ['SCRIBEENGINE_CONFIG']
|
2019-02-14 23:01:27 +00:00
|
|
|
elif os.path.exists('config.ini'):
|
|
|
|
config_file = 'config.ini'
|
2017-06-09 06:25:41 +00:00
|
|
|
if config_file:
|
|
|
|
application.config.update(read_config_from_file(config_file))
|
|
|
|
# Set up mail, themes
|
|
|
|
Mail(application)
|
2019-02-14 23:01:27 +00:00
|
|
|
Themes(application, app_identifier='ScribeEngine', loaders=[
|
|
|
|
_scribeengine_themes_loader, packaged_themes_loader, theme_paths_loader])
|
2017-06-09 06:25:41 +00:00
|
|
|
# Set up database
|
|
|
|
db.init_app(application)
|
2019-02-14 23:01:27 +00:00
|
|
|
db.create_all(app=application)
|
2017-06-09 06:25:41 +00:00
|
|
|
# Setup Flask-User
|
2019-02-14 23:01:27 +00:00
|
|
|
UserManager(application, db, User)
|
2017-06-09 06:25:41 +00:00
|
|
|
# Register all the blueprints
|
2021-01-30 04:19:48 +00:00
|
|
|
application.register_blueprint(admin)
|
2021-06-11 21:31:14 +00:00
|
|
|
application.register_blueprint(node_views)
|
2019-02-14 23:01:27 +00:00
|
|
|
application.register_blueprint(account)
|
2017-06-09 06:25:41 +00:00
|
|
|
# Return the application object
|
|
|
|
return application
|