Esempio n. 1
0
def _load_extensions(app):
    from extensions import db
    from extensions import migrate
    db.init_app(app)
    migrate.init_app(app, db)

    _load_extension_sentry(app)
Esempio n. 2
0
def create_app():
    app = Flask(__name__)

    if app.config["ENV"] == "development":
        app.config.from_object("config.DevelopmentConfig")
    else:
        app.config.from_object("config.ProductionConfig")

    app.register_blueprint(json_return)
    app.register_blueprint(main_page)
    app.register_blueprint(account_page)
    app.register_blueprint(register_login_page)
    app.register_blueprint(general_page)
    app.register_blueprint(about_page)
    app.register_blueprint(experience_page)
    app.register_blueprint(education_page)
    app.register_blueprint(skills_page)
    app.register_blueprint(project_page)

    from extensions import db, login_manager, cors, migrate

    db.init_app(app)
    login_manager.init_app(app)
    cors.init_app(app)
    migrate.init_app(app, db)

    @login_manager.user_loader
    def load_user(user_id):
        return General.query.get(int(user_id))

    with app.app_context():
        db.create_all()

    return app
Esempio n. 3
0
def init_extensions(app):
    # Init database
    from extensions import db
    db.init_app(app)

    # Init migration
    from extensions import migrate
    migrate.init_app(app, db)

    # Init bcrypt
    from extensions import bcrypt
    bcrypt.init_app(app)

    # Init Login manager
    from extensions import login_mgr
    login_mgr.login_view = 'auth.login'
    login_mgr.init_app(app)

    # Init mail
    from extensions import mail
    mail.init_app(app)

    # Init jwt
    from extensions import jwt
    jwt.init_app(app)
Esempio n. 4
0
def create_app(config_obj='intersentia.config.DevelopmentConfig'):
    """
    Returns an app Flask object configurated with the given config_obj.
    """
    # TODO: avoid hardcoded paths.
    app = Flask(__name__,
                static_folder='../static/dist',
                template_folder='../static/public')
    app.config.from_object(config_obj)

    from extensions import db
    from extensions import migrate
    # TODO: command to create database and context db_models.
    # understand the concept of session and scoped_session.
    # Create makemigrations and migrate.
    db.init_app(app)
    migrate.init_app(app, db=db, render_as_batch=True)

    from v1.blueprint import api_bp
    app.register_blueprint(api_bp, url_prefix='/api')

    from flask_cors import CORS
    CORS(app)

    return app
Esempio n. 5
0
def register_extensions(app):

    # ..config
    config.init_app(app)

    # ..bcrypt
    bcrypt.init_app(app)

    # ..db
    db.init_app(app)

    # ..csrf
    csrf_protect.init_app(app)

    # ...login_manager
    login_manager.init_app(app)
    login_manager.login_view = 'accounts.login'
    login_manager.login_message = None

    @login_manager.user_loader
    def load_user(user_id):
        from accounts.models import User
        return User.get_by_id(user_id)

    # ..migrate
    migrate.init_app(app, db)

    # ..webpack
    if not app.config['MIGRATION_MODE']:
        webpack.init_app(app)

    # ...
    return None
Esempio n. 6
0
def extensions_load(app):
    db.init_app(app)
    migrate.init_app(app, db)
    JWTManager(app)
    redis_store = FlaskRedis()
    redis_store.init_app(app)
    app.config['JWT_BLACKLIST_STORE'] = RedisStore(redis_store)
Esempio n. 7
0
def register_extensions(app):
    db.init_app(app)
    mail.init_app(app)
    debug_toolbar.init_app(app)
    migrate.init_app(app, db)
    api.init_app(app)
    return None
Esempio n. 8
0
def configure_extensions(app):

    db.init_app(app)

    migrate.init_app(app, db, directory="_migrations", render_as_batch=True)

    CORS(app)
Esempio n. 9
0
def register_extensions(app):
    """
    扩展实例化
    :param app:
    :return:
    """
    db.init_app(app)
    moment.init_app(app)
    migrate.init_app(app=app, db=db)
    cache.init_app(app)

    login_manager.init_app(app)
    # 登录过滤保护
    login_manager.exempt_views((user_bp, demo_bp, audio_bp, img_api_bp, ocr_api_bp))

    session.init_app(app)

    csrf.init_app(app)
    # csrf过滤保护
    csrf.exempt_views((demo_bp, audio_bp, img_api_bp, ocr_api_bp))

    # 定时任务 解决FLASK DEBUG模式定时任务执行两次
    if os.environ.get('FLASK_DEBUG', '0') == '0':
        scheduler.init_app(app)
        scheduler.start()
    elif os.environ.get('WERKZEUG_RUN_MAIN') == 'true':
        scheduler.init_app(app)
        scheduler.start()
Esempio n. 10
0
def extension(app):
    csrf.init_app(app)
    moment.init_app(app)
    migrate.init_app(app)
    bootstrap.init_app(app)
    login_manager.init_app(app)
    db.init_app(app)
    return None
Esempio n. 11
0
def config_extensions(app):
    """
    用于初始化:第三方模块及自己写的模块对象
    :param app: flask主对象
    :return: 没有返回值
    """
    db.init_app(app)
    migrate.init_app(app)
Esempio n. 12
0
def register_extensions(app):
    assets.init_app(app)
    bcrypt.init_app(app)
    cache.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)
    debug_toolbar.init_app(app)
    migrate.init_app(app, db)
    return None
Esempio n. 13
0
def register_extensions(app):
    db.init_app(app)
    bcrypt.init_app(app)
    lm.init_app(app)
    lm.login_view = 'auth.login'
    toolbar.init_app(app)
    mail.init_app(app)
    migrate.init_app(app, db)
    return None
Esempio n. 14
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(Config)

    db.init_app(app)
    migrate.init_app(app, db)

    main.configure(app)

    return app
Esempio n. 15
0
def register_extensions(app):
    bootstrap.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)
    csrf.init_app(app)
    ckeditor.init_app(app)
    mail.init_app(app)
    moment.init_app(app)
    toolbar.init_app(app)
    migrate.init_app(app, db)
Esempio n. 16
0
def register_extensions(app):
    """Register Flask extensions."""
    db.init_app(app)
    migrate.init_app(app, db)
    login_manager.init_app(app)
    bcrypt.init_app(app)
    if not scheduler.running:
        scheduler.init_app(app)
        scheduler.start()
    jwt.init_app(app)
Esempio n. 17
0
def create_app(config_object=ProdConfig):
    app = Flask(__name__)
    app.config.from_object(config_object)

    app.register_blueprint(api_blueprint)

    cors.init_app(app)
    db.init_app(app)
    migrate.init_app(app, db)
    return app
Esempio n. 18
0
    def configure_extensions(self):
        # flask-migrate
        migrate.init_app(self, db)

        # flask_cors
        from flask_cors import CORS
        CORS(self, resources={r'/api/*': {'origins': '*'}})

        # flask-security
        security.init_app(self, datastore=user_datastore, register_blueprint=True)
Esempio n. 19
0
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)
    flask_static_digest.init_app(app)
    return None
Esempio n. 20
0
def create_app():
    app_init = Flask(__name__)
    app_init.config.from_object('config')
    db.init_app(app_init)
    db.app = app_init
    bootstrap.init_app(app_init)
    migrate.init_app(app_init, db)
    if app_init.config['DEBUG'] is True:
        app_init.config['DEBUG_TB_INTERCEPT_REDIRECTS'] = False
        debug_toolbar.init_app(app_init)
    return app_init
Esempio n. 21
0
def register_extensions(app):
    from extensions import login_manager
    from extensions import migrate
    from extensions import db

    login_manager.init_app(app)
    login_manager.app = app
    db.init_app(app)
    db.app = app
    migrate.init_app(app, db)
    migrate.app = app
Esempio n. 22
0
def register_extensions(app):
    """Register Flask extensions."""
    bcrypt.init_app(app)
    # cache.init_app(app)
    db.init_app(app)
    ma.init_app(app)
    migrate.init_app(app, db)
    jwt.init_app(app)
    # redis_store.init_app(app)
    logging.config.dictConfig(app.config["LOGGING"])
    return app
Esempio n. 23
0
def create_app(script_info=None):

    app = Flask(__name__)

    load_dotenv(".env", verbose=True)
    app_settings = os.environ.get("APP_SETTINGS")
    if not app_settings:
        raise ValueError(
            'APP_SETTINGS environment variable is not set. Aborting.')
    app.config.from_object(app_settings)

    # Migration purposes
    from models import user, remaining_employee, company, address  # NOQA

    jwt.init_app(app)
    db.init_app(app)
    api.init_app(app)
    ma.init_app(app)
    migrate.init_app(app, db)
    init_celery(app)
    mail.init_app(app)

    api.add_resource(UserLogin, "/login")
    api.add_resource(UserRegister, "/register")
    api.add_resource(UserRegister, "/register/<string:confirmation_token>")
    api.add_resource(User, "/user")
    api.add_resource(UserList, "/users")
    api.add_resource(UserInvite, "/invite")

    @app.route('/ping')
    def pong():
        return 'pong'

    @api.errorhandler(Unauthorized)
    def unauthorized_page(error):
        return {"message": "401, change this on prod."}, 401

    @api.errorhandler(Forbidden)
    def forbidden_page(error):
        return {"message": "403, change this on prod."}, 403

    @api.errorhandler(NotFound)
    def page_not_found(error):
        return {"message": "404, change this on prod."}, 404

    @api.errorhandler(MethodNotAllowed)
    def method_not_allowed(error):
        return {"message": "405, change this on prod."}, 405

    @api.errorhandler(InternalServerError)
    def server_error_page(error):
        return {"message": "500, change this on prod."}, 500

    return app
Esempio n. 24
0
def configure_extensions(app):
    cors = CORS(app)
    jwt.init_app(app)
    # cors.init_app(app)

    db.init_app(app)

    migrate.init_app(app, db)
    global printer
    printer = Printer(app.config['PRINTER_IP'], app.config['PRINTER_PORT'])
    printer.setDaemon(True)
    printer.start()
Esempio n. 25
0
    def configure_extensions(self):
        # flask-migrate
        migrate.init_app(self, db)

        # flask_cors
        from flask_cors import CORS
        CORS(self, resources={r'/api/*': {'origins': '*'}})

        # flask-security
        security.init_app(self,
                          datastore=user_datastore,
                          register_blueprint=True)
Esempio n. 26
0
def extensions(app):
    """
    Register 0 or more extensions (mutates the app passed in).

    :param app: Flask application instance
    :return: None
    """

    migrate.init_app(app, db)
    cors.init_app(app)
    bcrypt.init_app(app)
    api.init_app(app)
Esempio n. 27
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(Config)

    db.init_app(app)
    migrate.init_app(app, db)
    api.init_app(app)
    dynaconf.init_app(app)

    api.add_resource(ClientResource, '/client', '/client/<int:id_client>')
    api.add_resource(BookResource, '/book', '/book/<int:id_book>')
    return app
Esempio n. 28
0
def create_app(config_class=Config):
    app = Flask(__name__)
    app.config.from_object(config_class)

    db.init_app(app)
    migrate.init_app(app, db)
    login.init_app(app)
    mail.init_app(app)
    bootstrap.init_app(app)
    moment.init_app(app)
    celery.init_app(app)

    from app.errors import bp as errors_bp
    app.register_blueprint(errors_bp)

    from app.auth import bp as auth_bp
    app.register_blueprint(auth_bp, url_prefix='/auth')

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

    from app.scraping import bp as scraping_bp
    from app.scraping.scraper import Scraper
    from app.scraping import tasks

    app.register_blueprint(scraping_bp, url_prefix='/scraping')
    app.scrapers = {
        "rechem": tasks.rechem_routine_task,
        "test_task": tasks.test_task
    }

    if not app.debug and not app.testing:
        if app.config['LOG_TO_STDOUT']:
            stream_handler = logging.StreamHandler()
            stream_handler.setLevel(logging.INFO)
            app.logger.addHandler(stream_handler)
        else:
            if not os.path.exists('logs'):
                os.mkdir('logs')
            file_handler = RotatingFileHandler('logs/DNMS.log',
                                               maxBytes=10240,
                                               backupCount=10)
            file_handler.setFormatter(
                logging.Formatter('%(asctime)s %(levelname)s: %(message)s '
                                  '[in %(pathname)s:%(lineno)d]'))
            file_handler.setLevel(logging.INFO)
            app.logger.addHandler(file_handler)

            app.logger.setLevel(logging.INFO)
            app.logger.info('DNMS startup')

    return app
Esempio n. 29
0
def create_app(config_name='dev'):
    app = Flask(__name__)

    app.config.from_object(config_factory[config_name])
    db.init_app(app)
    api.init_app(app)
    cors.init_app(app)
    migrate.init_app(app, db)
    ma.init_app(app)

    router_register(app)

    return app
Esempio n. 30
0
def create_app(env='dev'):
    app = Flask(__name__)
    app.config.from_object(get_config(env))
    db.init_app(app)
    mail.init_app(app)

    app.register_blueprint(user_blueprint)
    app.register_blueprint(book_blueprint)
    app.register_blueprint(library_blueprint)
    app.register_blueprint(home_page)
    db.create_all(app=app)
    migrate.init_app(app, db)
    return app
Esempio n. 31
0
def register_extensions(app):
    db.init_app(app)
    migrate.init_app(app, db)

    cors.init_app(app, supports_credentials=True)

    api.init_app(app, version='1.0', title='Swagger API',
                 description='API для сервиса интерактовной карты благоустройства г. Москва')

    api.add_namespace(ns_map)
    api.add_namespace(ns_data_set)
    api.add_namespace(ns_reports)
    api.add_namespace(ns_dictionary)
Esempio n. 32
0
def create_app():
    app = Flask(__name__)
    app.config.update({
        'DEBUG':
        True,
        'SQLALCHEMY_DATABASE_URI':
        'postgresql://*****:*****@localhost/sqlaworkshop'
    })
    db.init_app(app)
    migrate.init_app(app, db)
    app.add_url_rule('/orders', view_func=orders, methods=['get'])
    app.cli.command()(populate)
    app.cli.command()(query)
    return app
Esempio n. 33
0
def register_extensions(server):
    from extensions import db
    from models.model import User
    from extensions import login_manager
    from extensions import migrate

    db.init_app(server)
    login_manager.init_app(server)
    login_manager.login_view = 'login.login'
    migrate.init_app(server, db)

    # Connect users to their cookies
    @login_manager.user_loader
    def load_user(user_id):
        return User.query.get(int(user_id))
Esempio n. 34
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(Config)

    db.init_app(app)
    marshmallow.init_app(app)
    migrate.init_app(app, db)
    login.init_app(app)
    dynaconf.init_app(app)
    mail.init_app(app)
    moment.init_app(app)

    # configurando os blueprints
    accounts.configure(app)
    errors.configure(app)
    feed.configure(app)
    users.configure(app)
    #image.configure(app)
    email.configure(app)

    return app
Esempio n. 35
0
def register_extensions(app):
    socketio.init_app(app)
    db.init_app(app)
    arduino.init_app(app)
    migrate.init_app(app, db)
Esempio n. 36
0
def register_db(app):
    db.init_app(app)
    app.db = db
    migrate.init_app(app, db)
    return None
Esempio n. 37
0
def register_extensions(app):
    db.init_app(app)
    migrate.init_app(app, db)
    return None