scribeengine/scribeengine/__init__.py

76 lines
3.3 KiB
Python

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