Exemplo n.º 1
0
def create_app(config=MainConfig):
    app = Flask(__name__)
    app.config.from_object(MainConfig)

    mongo.init_app(app)
    cache.init_app(app)

    app.register_blueprint(bp_main)
    # app.register_blueprint(bp_errors)
    app.register_blueprint(bp_streams)
    return app
Exemplo n.º 2
0
def app(config):
    from flask import Flask
    from app.extensions import mongo, babel

    app = Flask("TestMongo")
    app.config["MONGODB_SETTINGS"] = config
    app.config["BABEL_DEFAULT_TIMEZONE"] = "Asia/Shanghai"
    mongo.init_app(app)
    babel.init_app(app)

    with app.app_context():
        yield app
Exemplo n.º 3
0
def register_extensions(server):
    from app.extensions import mongo
    from app.extensions import db
    from app.extensions import login
    from app.extensions import migrate
    from app.extensions import ldap

    db.init_app(server)
    login.init_app(server)
    login.login_view = 'main.login'
    migrate.init_app(server, db)
    mongo.init_app(server)
    ldap.init_app(server)
Exemplo n.º 4
0
def app_create(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    config[config_name].init_app(app)
    db.init_app(app)
    bootstrap.init_app(app)
    mongo.init_app(app)
    # 注册蓝本,在此添加
    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    # 路由和其他处理程序定义
    # ...
    return app
Exemplo n.º 5
0
def create_app(config_name='dev'):
    app = Flask(__name__)
    # sifn = show if none
    app.jinja_env.filters['sifn'] = lambda it: u'无' if not it else it
    app.jinja_env.filters['with_site'] = lambda title: title + ' - pkyx'

    # 导入配置
    app.config.from_object(config[config_name])
    config[config_name].init_app(app)

    # 初始化flask_admin
    # admin.init_app(app)
    # admin.add_view(FileView(os.path.join(os.path.dirname(__file__), 'static'), '/static/'))

    # 初始化MongoDB
    mongo.init_app(app)
    with app.app_context():
        mongo.db['items'].create_index('title', background=True)
    # 初始化Celery
    celery.init_app(app)

    # 初始化Flask-mail
    mail.init_app(app)

    # 初始化Flask-Login
    login_manager.init_app(app)
    login_manager.login_view = 'main.index'
    login_manager.login_message = u'请先登录或注册'

    @login_manager.user_loader
    def load_user(user_id):
        user = None
        db_user = mongo.db.users.find_one({"_id": bson_obj_id(user_id)})
        if db_user is not None:
            user_id = db_user.pop('_id')
            user = User(user_id, extras=db_user)
        return user

    from app.main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    from app.users import users as users_blueprint
    app.register_blueprint(users_blueprint)

    from app.api import api as api_blueprint
    app.register_blueprint(api_blueprint)

    return app
Exemplo n.º 6
0
def create_app(config_name='dev'):
    app = Flask(__name__)
    # sifn = show if none
    app.jinja_env.filters['sifn'] = lambda it: '无' if not it else it
    app.jinja_env.filters['with_site'] = lambda title: title + ' - pkyx'
    # 导入配置
    app.config.from_object(config[config_name])
    config[config_name].init_app(app)
    # 初始化flask_admin
    admin.init_app(app)
    admin.add_view(FileView(os.path.join(os.path.dirname(__file__), 'static'), '/static/'))
    # 初始化MongoDB
    mongo.init_app(app)
    with app.app_context():
        mongo.db['items'].create_index('title', background=True)
    # 初始化Celery
    celery.init_app(app)
    # 初始化Flask-mail
    mail.init_app(app)
    # 初始化Flask-Login
    login_manager.init_app(app)
    login_manager.login_view = 'main.register'
    login_manager.login_message = '请先登录或注册'

    @login_manager.user_loader
    def load_user(user_id):
        user = None
        db_user = mongo.db.users.find_one({"_id": bson_obj_id(user_id)})
        if db_user is not None:
            user_id = db_user.pop('_id')
            user = User(user_id, extras=db_user)
        return user

    # @login_manager.unauthorized_handler
    # def unauthorized():
    #   pass


    from app.main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    from app.users import users as users_blueprint
    app.register_blueprint(users_blueprint)

    from app.api import api as api_blueprint
    app.register_blueprint(api_blueprint)

    return app
Exemplo n.º 7
0
def create_app(config_class=DevConfig):
    app = Flask(__name__)

    app.config.from_object(config_class)

    mongo.init_app(app)
    csrf.init_app(app)

    # 注册 blueprint
    from app.blueprint import admin as admin_blueprint

    app.register_blueprint(admin_blueprint, url_prefix="/")

    @app.errorhandler(404)
    def page_not_found(error):
        return render_template("404.html"), 404

    return app
Exemplo n.º 8
0
def create_app(config_class=Config):

    app = Flask(__name__)
    # set app configs
    app.config.from_object(config_class)

    # initial flask extensions
    limiter.init_app(app)
    flask_uuid.init_app(app)
    mongo.init_app(app)

    # blueprints
    from app.main import bp as main_bp
    app.register_blueprint(main_bp)

    # register custom errors
    app.register_error_handler(429, handle_429_request)
    app.register_error_handler(405, handle_wrong_method)
    app.register_error_handler(404, handle_not_found)

    # logging stuff
    formatter = logging.Formatter(
        "[%(asctime)s] [%(pathname)s:%(lineno)d] %(levelname)s - %(message)s")
    handler = RotatingFileHandler(app.config['LOG_FILENAME'],
                                  maxBytes=10000000,
                                  backupCount=5)
    log_level = app.config['LOG_LEVEL']

    if log_level == 'DEBUG':  # pragma: no cover
        app.logger.setLevel(logging.DEBUG)  # pragma: no cover
    elif log_level == 'INFO':  # pragma: no cover
        app.logger.setLevel(logging.INFO)  # pragma: no cover
    elif log_level == 'WARNING':  # pragma: no cover
        app.logger.setLevel(logging.WARNING)  # pragma: no cover
    elif log_level == 'ERROR':  # pragma: no cover
        app.logger.setLevel(logging.ERROR)  # pragma: no cover
    else:  # pragma: no cover
        app.logger.setLevel(logging.CRITICAL)  # pragma: no cover

    handler.setFormatter(formatter)
    app.logger.addHandler(handler)

    return app
Exemplo n.º 9
0
def create_app(config_class=Config):

    load_dotenv()  # Load all env variables for the app
    app = Flask(__name__)

    # Add celery config
    app.config['CELERY_BROKER_URL'] = Config.CELERY_BROKER_URL
    app.config['CELERY_RESULT_BACKEND'] = Config.CELERY_RESULT_BACKEND
    app.config['CELERYBEAT_SCHEDULE'] = Config.CELERY_BEAT_TASKS

    CORS(app)
    app.secret_key = ".*nobodysguessingthis__"
    app.config.from_object(config_class)

    mongo.init_app(app, Config.MONGO_URI)
    celery.conf.update(app.config)  #Update with celery config
    cache.init_app(app, config=Config.CACHE_CONFIG)  #Init redis cache

    from app.data import data_bp
    app.register_blueprint(data_bp, cli_group=None)
    register_errorhandlers(app)

    return app
Exemplo n.º 10
0
from flask import Flask
from flask_login import LoginManager
from config import Config
from flask_bootstrap import Bootstrap
from app.extensions import mongo
#from flask_ldap import LDAP

app = Flask(__name__)
app.config.from_object(Config)
mongo.init_app(app)
#ldap = LDAP(app, mongo)
bootstrap = Bootstrap(app)
app.jinja_env.filters['zip'] = zip
lm = LoginManager()
lm.init_app(app)
lm.login_view = 'login'

from app import routes
Exemplo n.º 11
0
def register_extensions(app):
    mongo.init_app(app)
    jwt_manager.init_app(app)
Exemplo n.º 12
0
def register_extensions(app):
    mongo.init_app(app)
    jwt.init_app(app)
Exemplo n.º 13
0
# Import flask and template operators
import os
from flask import Flask

# Application Definition
app = Flask(__name__,
            instance_path=os.path.join(
                os.path.dirname(os.path.realpath(__file__)), '../instance'),
            instance_relative_config=True)

# Initializing configuration
app.config.from_pyfile('env.cfg', silent=True)

from app.extensions import mongo, MONGO_URI
mongo.init_app(app, MONGO_URI)

# Import a module / component using its blueprint handler variable (catalog_module)
from app.stores.controllers import stores_module

# Register blueprint(s)
app.register_blueprint(stores_module)