예제 #1
0
def register_extensions(app):
    bcrypt.init_app(app)
    db.init_app(app)
    csrf_protect.init_app(app)
    login.init_app(app)
    debug_toolbar.init_app(app)
    mail.init_app(app)
    migrate.init_app(app, db)
    moment.init_app(app)
    if not app.debug and not app.testing:
        if app.config['MAIL_SERVER']:
            auth = None
            if app.config['MAIL_USERNAME'] or app.config['MAIL_PASSWORD']:
                auth = (app.config['MAIL_USERNAME'],
                        app.config['MAIL_PASSWORD'])
            secure = None
            if app.config['MAIL_USE_TLS']:
                secure = ()
            mail_handler = SMTPHandler(
                mailhost=(app.config['MAIL_SERVER'], app.config['MAIL_PORT']),
                fromaddr='no-reply@' + app.config['MAIL_SERVER'],
                toaddrs=app.config['ADMINS'], subject='Microblog Failure',
                credentials=auth, secure=secure)
            mail_handler.setLevel(logging.ERROR)
            app.logger.addHandler(mail_handler)
    return None
예제 #2
0
def register_extensions(app):
    """Register Flask extensions."""
    bcrypt.init_app(app)
    cache.init_app(app)
    db.init_app(app)
    migrate.init_app(app, db)
    jwt.init_app(app)
예제 #3
0
def register_extensions(app):
    bcrypt.init_app(app)
    login_manager.init_app(app)
    db.init_app(app)
    # debug_toolbar.init_app(app)

    return None
예제 #4
0
def create_app(environment=None):
    """Create and bootstrap app."""
    # Instantiate the app
    app = FlaskAPI(__name__)

    # Enable CORS
    CORS(app)

    # Set config
    if not environment:
        environment = os.getenv('APP_SETTINGS', 'development')
    config_object = app_config[environment]
    app.config.from_object(config_object)

    # Set up extensions
    mongoDB.init_app(app)
    db.init_app(app)
    bcrypt.init_app(app)
    migrate.init_app(app, db)

    # Register application components
    register_tool_result_modules(app)
    register_display_modules(app)
    register_blueprints(app)
    register_error_handlers(app)

    # Update Celery config
    update_celery_settings(celery, config_object)

    return app
예제 #5
0
def load(env):
    # Flag parsing with wsgi runners is a major pain
    # We identify a flag break '--' and consume only flags after it
    if env != 'dev':
        if '--' in sys.argv:
            separator = sys.argv.index('--')
            args = sys.argv[separator:]
            logging.debug(
                'Prod mode, loading args the hard way: {args}'.format(
                    args=args))
        else:
            args = sys.argv
        FLAGS(args)
    else:
        FLAGS(sys.argv)

    # Init sentry as early as possible to catch as much as possible
    if FLAGS.sentry:
        sentry_sdk.init(dsn=FLAGS.sentry,
                        integrations=[FlaskIntegration()],
                        environment=env,
                        release=__version__)

    app = Flask(__name__)
    app.config.from_object('websiteconfig')

    # gRPC channel init
    global channels
    kwargs = {}
    if FLAGS.consul:
        kwargs['consul'] = True
    if FLAGS.jaeger:
        tracer = init_tracer()
        kwargs['tracer'] = tracer
        flask_tracer = FlaskTracing(tracer, True, app)
        logging.info('Flask tracing enabled')
    channels = Channels(**kwargs)
    channels.refresh_all()

    lm.init_app(app)
    mail.init_app(app)
    bcrypt.init_app(app)
    flask_static_digest.init_app(app)

    from app import user, maintenance, asset, pwa
    app.register_blueprint(user.bp)
    app.register_blueprint(maintenance.bp)
    app.register_blueprint(asset.bp)
    app.register_blueprint(pwa.bp)

    @app.route('/')
    def root():
        return render_template('index.html')

    @app.route('/favicon.ico')
    def favicon():
        return send_from_directory('static', 'img/icons/favicon.ico')

    return app
예제 #6
0
def register_extensions(app):
    db.init_app(app)
    cache.init_app(app)
    bcrypt.init_app(app)
    celery.config_from_object(app.config)
    redis.init_app(app)
    login_manager.init_app(app)
    principal.init_app(app)
예제 #7
0
def create_app():
    app = Flask(__name__)
    app.config.from_pyfile("config.py")
    bcrypt.init_app(app)
    db.init_app(app)
    migrate.init_app(app, db)
    controllers.init_app(app)
    return app
예제 #8
0
def register_extensions(app):
    bcrypt.init_app(app)
    db.init_app(app)
    csrf_protect.init_app(app)
    login.init_app(app)
    migrate.init_app(app, db)
    moment.init_app(app)
    return None
예제 #9
0
def register_extensions(app):
    db.init_app(app)
    lm.init_app(app)
    mail.init_app(app)
    bcrypt.init_app(app)
    celery.config_from_object(app.config)
    assets.init_app(app)
    babel.init_app(app)
예제 #10
0
def register_extensions(app):
    db.init_app(app)
    ma.init_app(app)
    bcrypt.init_app(app)
    jwt.init_app(app)
    initialize_routes(api)
    api.init_app(app)
    return None
예제 #11
0
def create_app(script_info=None):
    """Application factory."""
    # instantiate the app
    app = Flask(__name__)

    # enable cors
    CORS(app)

    # set config
    app_settings = os.getenv("APP_SETTINGS")
    app.config.from_object(app_settings)

    # set up extensions
    db.init_app(app)
    bcrypt.init_app(app)
    migrate.init_app(app, db)
    jwt.init_app(app)
    graphql_client.init_app(app)

    if app.config["TESTING"]:
        redis_store = FlaskRedis.from_custom_provider(FakeStrictRedis)
    else:
        redis_store = redis_client
    redis_store.init_app(app)

    # register blueprints
    from app.api.rest.users import users_blueprint
    app.register_blueprint(users_blueprint)
    from app.api.rest.topics import topics_blueprint
    app.register_blueprint(topics_blueprint)
    from app.api.rest.messages import messages_blueprint
    app.register_blueprint(messages_blueprint)

    if app.debug:

        @app.route("/graphql", methods=["GET"])
        def gql_playground():
            """User interface for writing graphql queries."""
            return PLAYGROUND_HTML, 200

    # shell context for flask cli
    @app.shell_context_processor
    def ctx():
        return {
            "app": app,
            "db": db,
            "User": User,
            "Topic": Topic,
            "Message": Message,
            "redis_store": redis_store
        }

    @app.before_first_request
    def create_tables():
        """Create all tables in the database, if not existing."""
        db.create_all()

    return app
예제 #12
0
def register_extensions(app, db):
    """Register Flask extensions."""
    # cache.init_app(app)
    db.init_app(app)
    migrate.init_app(app, db)
    jwt.init_app(app)
    login_manager.init_app(app)
    bcrypt.init_app(app)
    ma.init_app(app)
예제 #13
0
def register_extensions(app):
    bcrypt.init_app(app)
    db.init_app(app)
    csrf_protect.init_app(app)
    login.init_app(app)
    migrate.init_app(app, db)
    moment.init_app(app)
    configure_uploads(app, images)
    patch_request_class(app)
    return None
예제 #14
0
def register_extensions(app):
    """register Flask extensions."""
    bcrypt.init_app(app)
    csrf_protect.init_app(app)
    login_manager.init_app(app)
    db.init_app(app)
    migrate.init_app(app, db)
    cache.init_app(app)
    debug_toolbar.init_app(app)
    flask_static_digest.init_app(app)
예제 #15
0
파일: app.py 프로젝트: msaizar/flask-test
def register_extensions(app):
    """Register Flask extensions."""
    bcrypt.init_app(app)
    cache.init_app(app)
    db.init_app(app)
    csrf_protect.init_app(app)
    login_manager.init_app(app)
    debug_toolbar.init_app(app)
    migrate.init_app(app, db)
    return None
예제 #16
0
def register_extensions(app):
    heroku.init_app(app)
    travis.init_app(app)
    db.init_app(app)
    api.init_app(app)
    lm.init_app(app)
    mail.init_app(app)
    bcrypt.init_app(app)
    celery.config_from_object(app.config)
    assets.init_app(app)
예제 #17
0
def register_extensions(app):
    """Register Flask extensions."""
    assets.init_app(app)
    bcrypt.init_app(app)
    cache.init_app(app)
    db.init_app(app)
    csrf_protect.init_app(app)
    login_manager.init_app(app)
    debug_toolbar.init_app(app)
    migrate.init_app(app, db)
    return None
예제 #18
0
def register_extensions(app):
    """Register extensions with the Flask application."""
    travis.init_app(app)
    db.init_app(app)
    lm.init_app(app)
    mail.init_app(app)
    bcrypt.init_app(app)
    assets.init_app(app)
    babel.init_app(app)
    rq.init_app(app)
    migrate.init_app(app, db)
예제 #19
0
def register_extensions(app):
    babel.init_app(app)
    bcrypt.init_app(app)
    bootstrap.init_app(app)
    cache.init_app(app)
    db.init_app(app)
    csrf_protect.init_app(app)
    login_manager.init_app(app)
    debug_toolbar.init_app(app)
    migrate.init_app(app, db)
    mail.init_app(app)
    moment.init_app(app)
예제 #20
0
def register_extensions(app):
    heroku.init_app(app)
    travis.init_app(app)
    db.init_app(app)
    api.init_app(app)
    lm.init_app(app)
    mail.init_app(app)
    bcrypt.init_app(app)
    celery.config_from_object(app.config)
    assets.init_app(app)
    babel.init_app(app)
    csrf.init_app(app)
예제 #21
0
def register_extensions(app):
    """Register extensions with the Flask application."""
    travis.init_app(app)
    db.init_app(app)
    lm.init_app(app)
    mail.init_app(app)
    bcrypt.init_app(app)
    assets.init_app(app)
    babel.init_app(app)
    rq.init_app(app)
    migrate.init_app(app, db)
    limiter.init_app(app)
예제 #22
0
파일: app.py 프로젝트: 1111mp/flask_init
def register_extensions(app):
    """给Flask注册扩展功能"""
    bcrypt.init_app(app)
    cache.init_app(app)
    db.init_app(app)
    xtredis.init_app(app)
    # csrf_protect.init_app(app)
    login_manager.init_app(app)
    cors.init_app(app, resources=r'/*', supports_credentials=True)
    migrate.init_app(app, db)
    flask_static_digest.init_app(app)
    socketio.init_app(app, cors_allowed_origins='*',
                      logger=True, engineio_logger=True)
    return None
예제 #23
0
def create_app():
    flask_app = Flask(__name__, instance_relative_config=True)
    AdminLTE(flask_app)

    config_name = os.getenv('FLASK_CONFIG', 'default')
    flask_app.config.from_object(config[config_name])
    flask_app.config.from_pyfile('app.cfg', silent=True)

    upload_path = Path(flask_app.instance_path) / 'upload'
    if not Path(flask_app.instance_path).exists():
        Path(flask_app.instance_path).mkdir()
    if not upload_path.exists():
        upload_path.mkdir()

    flask_app.config['UPLOAD_FOLDER'] = str(upload_path)

    login_manager.session_protection = 'AdminPassword4Me'
    login_manager.login_view = 'auth.login'
    login_manager.login_message = 'Unauthorized User.'
    login_manager.login_message_category = "info"

    login_manager.init_app(flask_app)
    db.init_app(flask_app)
    bcrypt.init_app(flask_app)
    migrate.init_app(flask_app, db)

    for bp in all_blueprints:
        import_module(bp.import_name)
        flask_app.register_blueprint(bp)
    flask_app.register_blueprint(api_bp)

    user_cli = AppGroup('user')

    @user_cli.command('create-admin')
    @click.argument('email')
    @click.argument('name')
    @click.argument('password')
    def create_admin(email, name, password):
        user = User(email=email,
                    email_confirmed=True,
                    name=name,
                    role=UserRole.ADMIN)
        user.password = password

        db.session.add(user)
        db.session.commit()

    flask_app.cli.add_command(user_cli)

    return flask_app
예제 #24
0
def extensions(app):
    """
    Register 0 or more extensions (mutates the app passed in).

    :param app: Flask application instance
    :return: None
    """
    mail.init_app(app)
    csrf.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)
    bootstrap.init_app(app)  # initialize bootstrap
    bcrypt.init_app(app)

    return None
예제 #25
0
def create_app(object_name):
    """Create the app instance via `Factory Method`"""

    app = Flask(__name__)
    # Set the app config
    app.config.from_object(object_name)

    # Will be load the SQLALCHEMY_DATABASE_URL from config.py to db object
    db.init_app(app)

    # Init the Flask-Bcrypt via app object
    bcrypt.init_app(app)

    # Init the Flask-Login via app object
    login_manager.init_app(app)

    # Init the Flask-Prinicpal via app object
    principals.init_app(app)

    @app.route('/')
    def index():
        # Redirect the Request_url '/' to '/blog/'
        return redirect(url_for('blog.home'))

    @identity_loaded.connect_via(app)
    def on_identity_loaded(sender, identity):
        """Change the role via add the Need object into Role.

                   Need the access the app object.
                """

        # Set the identity user object
        identity.user = current_user

        # Add the UserNeed to the identity user object
        if hasattr(current_user, 'id'):
            identity.provides.add(UserNeed(current_user.id))

        # Add each role to the identity user object
        if hasattr(current_user, 'roles'):
            for role in current_user.roles:
                identity.provides.add(RoleNeed(role.name))

    # Register the Blueprint into app object
    app.register_blueprint(blog.blog_blueprint)
    app.register_blueprint(main.main_blueprint)

    return app
예제 #26
0
def register_extensions(app):
    bcrypt.init_app(app)
    db.init_app(app)
    csrf_protect.init_app(app)
    login.init_app(app)
    migrate.init_app(app, db)
    KVSessionExtension(store, app)
    babel = Babel(app)
    mail.init_app(app)

    @babel.localeselector
    def get_locale():
        # return 'ja'
        return request.accept_languages \
            .best_match(current_app.config['LANGUAGES'])

    return None
예제 #27
0
def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config_name)
    db.init_app(app)
    bcrypt.init_app(app)
    login_manager.init_app(app)
    principal.init_app(app)

    #upload
    configure_uploads(app, file_result)
    patch_request_class(app)

    @identity_loaded.connect_via(app)
    def on_identity_loaded(sender, identity):
        # 设置当前用户身份为login登录对象
        identity.user = current_user

        # 添加UserNeed到identity user对象
        if hasattr(current_user, 'id'):
            identity.provides.add(UserNeed(current_user.id))

        # 每个Role添加到identity user对象,roles是User的多对多关联
        if hasattr(current_user, 'roles'):
            for role in current_user.roles:
                identity.provides.add(RoleNeed(role.name))

    @app.route('/')
    def index():
        return redirect(url_for('result_bp.index_re'))

    from app.report.report import report_bp
    from app.report.user import user_bp
    from app.report.result import result_bp
    from app.report.admin import admin_bp

    app.register_blueprint(report_bp)
    app.register_blueprint(user_bp)
    app.register_blueprint(result_bp)
    app.register_blueprint(admin_bp)

    return app
예제 #28
0
def create_app(config=None):

    app = Flask(__name__)

    if config:
        app.config.from_object(config)
    else:
        app.config.from_object(os.environ['APP_SETTINGS'])

    # Init logger
    handler = RotatingFileHandler(app.config['LOGGING_LOCATION'],
                                  maxBytes=10000,
                                  backupCount=1)
    handler.setLevel(app.config['LOGGING_LEVEL'])
    app.logger.addHandler(handler)

    # Init routes
    from app.home.views import home
    app.register_blueprint(home)

    from app.home.api import TestApi
    api.add_resource(TestApi, '/api/protected')

    from app.user.api import UserApi
    api.add_resource(UserApi, '/api/user/register')

    # Init extensions
    db.init_app(app)
    api.init_app(app)
    bcrypt.init_app(app)

    from app.user.auth import authenticate, identity, payload_handler
    jwt.authentication_handler(authenticate)
    jwt.identity_handler(identity)
    jwt.jwt_payload_handler(payload_handler)
    jwt.init_app(app)

    return app
예제 #29
0
def create_app(config=None):
    
    app = Flask(__name__)

    if config:
        app.config.from_object(config)
    else:
        app.config.from_object(os.environ['APP_SETTINGS'])

    # Init logger
    handler = RotatingFileHandler(app.config['LOGGING_LOCATION'], maxBytes=10000, backupCount=1)
    handler.setLevel(app.config['LOGGING_LEVEL'])
    app.logger.addHandler(handler)

    # Init routes
    from app.home.views import home
    app.register_blueprint(home)

    from app.home.api import TestApi
    api.add_resource(TestApi, '/api/protected')

    from app.user.api import UserApi
    api.add_resource(UserApi, '/api/user/register')

    # Init extensions
    db.init_app(app)
    api.init_app(app)
    bcrypt.init_app(app)

    from app.user.auth import authenticate, identity, payload_handler
    jwt.authentication_handler(authenticate)
    jwt.identity_handler(identity)
    jwt.jwt_payload_handler(payload_handler)
    jwt.init_app(app)

    return app
예제 #30
0
def create_app(environment=None):
    """Create and bootstrap app."""
    # Instantiate the app
    app = FlaskAPI(__name__)

    # Enable CORS
    CORS(app)

    # Set config
    if not environment:
        environment = os.getenv('APP_SETTINGS', 'development')
    config_object = app_config[environment]
    app.config.from_object(config_object)

    # Set up extensions
    db.init_app(app)
    bcrypt.init_app(app)
    migrate.init_app(app, db)

    # Register application components
    register_blueprints(app)
    register_error_handlers(app)

    return app
예제 #31
0
def create_app(environment="dev"):
    app = Flask(__name__)

    # Configuration
    app.config.from_object(configurations[environment])

    # Initialize extensions
    db.init_app(app)
    migrate.init_app(app, db)
    bcrypt.init_app(app)
    login_manager.init_app(app)
    csrf.init_app(app)
    debug_toolbar.init_app(app)
    mail.init_app(app)

    # Register blueprint
    app.register_blueprint(users_bp)
    app.register_blueprint(auth_bp)

    # register macros autoloader
    macros_folder = os.path.join(APP_FOLDER, "templates/macros")
    autoload_macros(app.jinja_env, macros_folder)

    return app
예제 #32
0
파일: app.py 프로젝트: ynrfin/starter-flask
def register_extensions(app):
    db.init_app(app)
    migrate.init_app(app, db)
    login_manager.init_app(app)
    bcrypt.init_app(app)
    mail.init_app(app)
예제 #33
0
def register_extensions(app):
    bcrypt.init_app(app)
예제 #34
0
import os
import sys

import config

from app.extensions import (bcrypt, csrf_protect, db, login, mail)

from flask import (Flask)

app = Flask(__name__)

app.config.from_object('config.Development')

app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

bcrypt.init_app(app)
db.init_app(app)
csrf_protect.init_app(app)
login.init_app(app)
mail.init_app(app)

from app.admin.admin import admin
from app.api import api
from app.blog.blog import blog
from app.main.main import intro
from app.commer.commer import commer
from app.disp.disp import disp
from app.employ.employ import employ
from app.priv.priv import priv
from app.prop.prop import prop
from app.team.team import team
예제 #35
0
파일: __init__.py 프로젝트: cghall/EasyCRM
def register_extensions(app):
    bcrypt.init_app(app)
    login_manager.init_app(app)
    db.init_app(app)
예제 #36
0
def register_extensions(app):
    """Register the Flask app with various extensions."""
    bcrypt.init_app(app)
    ma.init_app(app)
    socketio.init_app(app)
예제 #37
0
def register_extensions(app):
    heroku.init_app(app)
    db.init_app(app)
    lm.init_app(app)
    bcrypt.init_app(app)