예제 #1
0
파일: __init__.py 프로젝트: betterlife/psi
def init_all(app, migrate=True):
    init_logging(app)
    # === Important notice to the maintainer ===
    # This line was use to database = init_db(app)
    # But we found session can not be cleaned among different
    # Unit tests, so we add this to avoid issue
    # sqlalchemy-object-already-attached-to-session
    # http://stackoverflow.com/questions/24291933/sqlalchemy-object-already-attached-to-session
    # A similar issue was captured on
    # https://github.com/jarus/flask-testing/issues/32
    # Please don't try to modify the follow four lines.
    # Please don't try to modify the follow four lines.
    # Please don't try to modify the follow four lines.
    if Info.get_db() is None:
        database = init_db(app)
    else:
        database = Info.get_db()
        database.init_app(app)
    security = init_flask_security(app, database)
    init_migrate(app, database)
    if migrate:
        with app.app_context():
            upgrade(directory=MIGRATION_DIR)

    init_https(app)
    init_admin_views(app, database)
    babel = init_babel(app)
    api = init_flask_restful(app)
    init_reports(app, api)
    init_jinja2_functions(app)
    # init_debug_toolbar(app)
    init_image_service(app)
    socket_io = init_socket_io(app)
    define_route_context(app, database, babel)

    # define a context processor for merging flask-admin's template context
    # into the flask-security views.
    @security.context_processor
    def security_context_processor():
        from flask import url_for
        return dict(
            get_url=url_for
        )

    @app.teardown_appcontext
    def shutdown_session(exception=None):
        database = Info.get_db()
        database.session.remove()

    return socket_io
예제 #2
0
def init_all(app, migrate=True):
    init_logging(app)
    # === Important notice to the maintainer ===
    # This line was use to database = init_db(app)
    # But we found session can not be cleaned among different
    # Unit tests, so we add this to avoid issue
    # sqlalchemy-object-already-attached-to-session
    # http://stackoverflow.com/questions/24291933/sqlalchemy-object-already-attached-to-session
    # A similar issue was captured on
    # https://github.com/jarus/flask-testing/issues/32
    # Please don't try to modify the follow four lines.
    # Please don't try to modify the follow four lines.
    # Please don't try to modify the follow four lines.
    if Info.get_db() is None:
        database = init_db(app)
    else:
        database = Info.get_db()
        database.init_app(app)
    security = init_flask_security(app, database)
    init_migrate(app, database)
    if migrate:
        with app.app_context():
            upgrade(directory=MIGRATION_DIR)

    init_https(app)
    init_admin_views(app, database)
    babel = init_babel(app)
    api = init_flask_restful(app)
    init_reports(app, api)
    init_jinja2_functions(app)
    # init_debug_toolbar(app)
    init_image_service(app)
    socket_io = init_socket_io(app)
    define_route_context(app, database, babel)

    # define a context processor for merging flask-admin's template context
    # into the flask-security views.
    @security.context_processor
    def security_context_processor():
        from flask import url_for
        return dict(get_url=url_for)

    @app.teardown_appcontext
    def shutdown_session(exception=None):
        database = Info.get_db()
        database.session.remove()

    return socket_io
예제 #3
0
파일: __init__.py 프로젝트: betterlife/psi
def init_admin_views(flask_app, database):
    from psi.app.views import init_admin_views
    try:
        return init_admin_views(flask_app, database)
    except sqlalchemy.exc.SQLAlchemyError as e:
        # If we're running the flask utility script and Postgres
        # isn't available, `init_admin_views` will raise an OperationalError,
        # blocking the utility script from running. Instead, we catch the
        # exception and warn the user so the user can invoke some of the
        # commands that don't require database connections.
        # TODO: don't require Postgres on app object initialization
        log.exception(e)
        log.warn('Cannot register admin views because of a SQLAlchemy error. '
                 'Skipping...')
예제 #4
0
def init_admin_views(flask_app, database):
    from psi.app.views import init_admin_views
    try:
        return init_admin_views(flask_app, database)
    except sqlalchemy.exc.SQLAlchemyError as e:
        # If we're running the flask utility script and Postgres
        # isn't available, `init_admin_views` will raise an OperationalError,
        # blocking the utility script from running. Instead, we catch the
        # exception and warn the user so the user can invoke some of the
        # commands that don't require database connections.
        # TODO: don't require Postgres on app object initialization
        log.exception(e)
        log.warn('Cannot register admin views because of a SQLAlchemy error. '
                 'Skipping...')
예제 #5
0
def init_admin_views(flask_app, database):
    from psi.app.views import init_admin_views
    return init_admin_views(flask_app, database)