from flask import Flask
from flask.ext.bootstrap import Bootstrap
from config import config
from datetime import timedelta
from .main import main as main_blueprint
from .main.helpers.auth import requires_auth

bootstrap = Bootstrap()


def create_app(config_name):

    application = Flask(__name__,
                        static_folder='static/',
                        static_url_path=config[config_name].STATIC_URL_PATH)

    application.config.from_object(config[config_name])
    config[config_name].init_app(application)

    bootstrap.init_app(application)

    application.register_blueprint(main_blueprint)
    main_blueprint.config = application.config.copy()

    if application.config['AUTHENTICATION']:
        application.permanent_session_lifetime = timedelta(minutes=60)
        application.before_request(requires_auth)

    return application

from flask import Flask
from flask.ext.bootstrap import Bootstrap
from config import config
from datetime import timedelta
from .main import main as main_blueprint
from .main.helpers.auth import requires_auth

bootstrap = Bootstrap()


def create_app(config_name):

    application = Flask(__name__,
                        static_folder='static/',
                        static_url_path=config[config_name].STATIC_URL_PATH)

    application.config.from_object(config[config_name])
    config[config_name].init_app(application)

    bootstrap.init_app(application)

    if application.config['AUTHENTICATION']:
        application.permanent_session_lifetime = timedelta(minutes=60)
        main_blueprint.before_request(requires_auth)

    application.register_blueprint(main_blueprint, url_prefix='/admin')
    main_blueprint.config = application.config.copy()

    return application

Add '/admin' url_prefix to main blueprint
Add '/admin' url_prefix to main blueprint

Also attaches the authentication check to main blueprint instead of
the app itself. This means we can use other blueprints for status
and internal use that don't require authentication.

One important note: before_request must be added before registering
the blueprint, otherwise it won't be activated.
