flask_common.py
def init_app(self, app):
        """Initializes the Flask application with Common."""
        if not hasattr(app, 'extensions'):
            app.extensions = {}

        if 'common' in app.extensions:
            raise RuntimeError("Flask-Common extension already initialized")

        app.extensions['common'] = self
        self.app = app

        if 'COMMON_FILESERVER_DISABLED' not in app.config:
            with app.test_request_context():

                # Configure WhiteNoise.
                app.wsgi_app = WhiteNoise(app.wsgi_app, root=url_for('static', filename='')[1:])

        self.cache = Cache(app, config={'CACHE_TYPE': app.config.get("COMMON_CACHE_TYPE", 'simple')})

        @app.before_request
        def before_request_callback():
            request.start_time = maya.now()

        @app.after_request
        def after_request_callback(response):
            if 'COMMON_POWERED_BY_DISABLED' not in current_app.config:
                response.headers['X-Powered-By'] = 'Flask'
            if 'COMMON_PROCESSED_TIME_DISABLED' not in current_app.config:
                response.headers['X-Processed-Time'] = maya.now().epoch - request.start_time.epoch
            return response

        @app.route('/favicon.ico')
        def favicon():
            return redirect(url_for('static', filename='favicon.ico'), code=301)
def init_app(self, app):
        """Initializes the Flask application with Common."""
        if not hasattr(app, 'extensions'):
            app.extensions = {}

        if 'common' in app.extensions:
            raise RuntimeError("Flask-Common extension already initialized")

        app.extensions['common'] = self
        self.app = app

        if 'COMMON_FILESERVER_DISABLED' not in app.config:
            with app.test_request_context():

                # Configure WhiteNoise.
                app.wsgi_app = WhiteNoise(app.wsgi_app, root=url_for('static', filename='')[1:])

        self.cache = Cache(app, config={'CACHE_TYPE': app.config.get("COMMON_CACHE_TYPE", 'simple')})

        @app.before_request
        def before_request_callback():
            request.start_time = maya.now()

        @app.after_request
        def after_request_callback(response):
            if 'COMMON_POWERED_BY_DISABLED' not in current_app.config:
                response.headers['X-Powered-By'] = 'Flask'
            if 'COMMON_PROCESSED_TIME_DISABLED' not in current_app.config:
                response.headers['X-Processed-Time'] = maya.now().epoch - request.start_time.epoch
            return response

        @app.route('/favicon.ico')
        def favicon():
            return redirect(url_for('static', filename='favicon.ico'), code=301)
def init_app ( self , app ) : if not hasattr ( app , 'extensions' ) : app . extensions = { } if 'common' in app . extensions : raise RuntimeError ( "Flask-Common extension already initialized" ) app . extensions [ 'common' ] = self self . app = app if 'COMMON_FILESERVER_DISABLED' not in app . config : with app . test_request_context ( ) : # Configure WhiteNoise. app . wsgi_app = WhiteNoise ( app . wsgi_app , root = url_for ( 'static' , filename = '' ) [ 1 : ] ) self . cache = Cache ( app , config = { 'CACHE_TYPE' : app . config . get ( "COMMON_CACHE_TYPE" , 'simple' ) } ) @ app . before_request def before_request_callback ( ) : request . start_time = maya . now ( ) @ app . after_request def after_request_callback ( response ) : if 'COMMON_POWERED_BY_DISABLED' not in current_app . config : response . headers [ 'X-Powered-By' ] = 'Flask' if 'COMMON_PROCESSED_TIME_DISABLED' not in current_app . config : response . headers [ 'X-Processed-Time' ] = maya . now ( ) . epoch - request . start_time . epoch return response @ app . route ( '/favicon.ico' ) def favicon ( ) : return redirect ( url_for ( 'static' , filename = 'favicon.ico' ) , code = 301 )
Initializes the Flask application with Common.
Initializes the Flask application with Common .