Beispiel #1
0
def init_app(app):
    # current_app.logger.info('  DB: Initialisation app')
    current_app.teardown_appcontext(
        close_db
    )  # app.teardown_appcontext() tells Flask to call that function when cleaning up after returning the response.
    current_app.cli.add_command(
        init_db_command
    )  # app.cli.add_command() adds a new command that can be called with the flask command.
Beispiel #2
0
def init_app(app):
    app.register_blueprint(bp)
    gravatar = Gravatar(app, size=150, rating='r')
    app.teardown_appcontext(_save_last_seen)

    with app.app_context():

        app.jinja_env.globals.update(
            login_link=login_link,
            get_notifications=get_notifications,
            get_flashed_messages=get_flashed_messages_override)

        app.context_processor(_get_current_user)
Beispiel #3
0
def init_db(app):
    '''
    Initializes an instance of the sqlite database and registers the
    close_db function with the @app.teardown_appcontext decorator.
    '''
    db = get_db()

    # Open and execute init script
    with app.open_resource('schema.sql') as sql_file:
        db.executescript(sql_file.read().decode('utf8'))

    # Close the database connection
    # at the end of each request
    app.teardown_appcontext(close_db)
Beispiel #4
0
    def init_app(self, app):
        self.config = app.config.get('DATABASE', {})
        self.name = self.config['db']

        self.conn_kwargs = {}
        self.engine = MySQLDatabase
        for key, value in self.config.items():
            if key not in ['engine', 'db']:
                self.conn_kwargs[key] = value

        if hasattr(app, 'teardown_appcontext'):
            app.teardown_appcontext(self.teardown)
        else:
            app.teardown_request(self.teardown)

        self.connect()
Beispiel #5
0
def init(app):
    app.teardown_appcontext(close_db)
Beispiel #6
0
def init_app(app):
    app.teardown_appcontext(close_db)
    app.cli.add_command(init_db_command)
Beispiel #7
0
def init_app(app):
    r""" Flaskin hook, jolla tietokanta yhdistetään sovellustasoon """

    app.teardown_appcontext(sulje_yhteys)
    app.cli.add_command(alusta_tietokanta)
Beispiel #8
0
def init_db():
    db = get_db()
    current_app.teardown_appcontext(close_db)

    with current_app.open_resource('sql/schema.sql') as f:
        db.executescript(f.read().decode('utf8'))
Beispiel #9
0
def init_app(app):
    app.teardown_appcontext(close_db)
    app.cli.add_command(init_db_command)
    app.cli.add_command(update_db_command)
    app.cli.add_command(add_post_command)
    app.cli.add_command(add_photo_command)
Beispiel #10
0
def init_app(app):
    # close_db se invoca tras cada request
    app.teardown_appcontext(close_db)
    # Llamamos al método init_db_command()
    app.cli.add_command(init_db_command)