コード例 #1
0
ファイル: __init__.py プロジェクト: crypex/unifispot-free
def create_app(mode="development"):
    """Create webapp instance."""
    app = Flask(__name__)
    #Initilise DB
    from bluespot.extensions import db
    db.init_app(app)
    # Load the default configuration
    app.config.from_object('config.default')
    #Load user specified config
    app.config.from_yaml(os.path.join(app.root_path,'..','config.yaml'))
    #initlize assets
    assets = Environment(app)
    assets.register(bundles)    
    # simple load all blueprint settings, enabled in config
    load_blueprint_settings(app,blueprint_path='bluespot')
    # simple load all blueprints, enabled in config
    load_blueprints(app,blueprint_path='bluespot')
    # Enable DebugToolbar on debug
    # Enable error handler on productive mode
    if app.config['DEBUG']:
        from flask_debugtoolbar import DebugToolbarExtension
        DebugToolbarExtension(app)
        app.logger.error( "DEV")

    else:
        # add errorhandler
        #error_handler(app)
        app.logger.error( "PROD")


    @app.route("/")
    def home():
        return "OK"

    return app
コード例 #2
0
def create_app(mode="development"):
    """Create webapp instance."""
    app = Flask(__name__)
    #Initilise DB
    from bluespot.extensions import db
    db.init_app(app)
    # Load the default configuration
    app.config.from_object('config.default')
    #Load user specified config
    app.config.from_yaml(os.path.join(app.root_path, '..', 'config.yaml'))
    #initlize assets
    assets = Environment(app)
    assets.register(bundles)
    # simple load all blueprint settings, enabled in config
    load_blueprint_settings(app, blueprint_path='bluespot')
    # simple load all blueprints, enabled in config
    load_blueprints(app, blueprint_path='bluespot')
    # Enable DebugToolbar on debug
    # Enable error handler on productive mode
    if app.config['DEBUG']:
        from flask_debugtoolbar import DebugToolbarExtension
        DebugToolbarExtension(app)
        app.logger.error("DEV")

    else:
        # add errorhandler
        #error_handler(app)
        app.logger.error("PROD")

    @app.route("/")
    def home():
        return "OK"

    return app
コード例 #3
0
ファイル: __init__.py プロジェクト: danbruegge/flaskeleton
def create_app(settings):
    app = Flask(__name__)

    # jinja settings
    app.jinja_env.trim_blocks = True
    app.jinja_env.lstrip_blocks = True

    # load base settings at first
    app.config.from_pyfile('settings.py')

    # simple load all blueprint settings, enabled in settings
    load_blueprint_settings(app)

    # load development or production settings at last
    app.config.from_pyfile(settings)

    # Setup assets
    assets.init_app(app)

    # simple load all blueprints, enabled in settings
    load_blueprints(app)

    # load all context_processors from utils.template
    load_context_processors(app)

    # Enable DebugToolbar on debug
    # Enable error handler on productive mode
    if app.debug:
        from flask_debugtoolbar import DebugToolbarExtension
        DebugToolbarExtension(app)
    else:
        # add errorhandler
        error_handler(app)

    @app.before_request
    def before_request():
        g.user = current_user

    @app.errorhandler(404)
    def page_not_found(e):
        return render_template('404.html'), 404

    @app.route('/robots.txt')
    @app.route('/favicon.ico')
    # @app.route('/sitemap.xml')
    # @app.route('/google-webmaster-tools-auth.html')
    def static_from_root():
        return send_from_directory(app.static_folder, request.path[1:])

    app.add_url_rule('/media/<path:filename>', endpoint='media',
                     view_func=send_file)

    return app
コード例 #4
0
ファイル: __init__.py プロジェクト: vlf1991/poppet-1
def create_app(mode="development"):
    """Create webapp instance."""
    app = Flask(__name__, instance_relative_config=True)
    #Load database

    #Initilise DB

    from unifispot.models import user_datastore
    db.init_app(app)

    # Load the default configuration
    app.config.from_object('config.default')

    # Load the configuration from the instance folder
    app.config.from_pyfile('config.py')

    # Load the file specified by the config_filename environment variable
    # Variables defined here will override those in the default configuration
    if mode is not None:
        app.config.from_object('config.' + mode)
        # Load test database config
        if mode == 'testing':
            app.config.from_pyfile('config_test.py')
        elif mode == 'e2e_testing':
            app.config.from_pyfile('config_e2e_test.py')
    #Setup Flask-Security before loading any blueprints
    security = Security(app, user_datastore)
    #initilise mail,celery and redis

    mail.init_app(app)
    celery.init_app(app)
    redis.init_app(app)
    ##not going to use server side sessions
    #sess.init_app(app)

    #initlize assets
    assets = Environment(app)
    assets.register(bundles)
    # simple load all blueprint settings, enabled in config
    load_blueprint_settings(app, blueprint_path='unifispot')

    # simple load all blueprints, enabled in config
    load_blueprints(app, blueprint_path='unifispot')

    #check for default values required before starting app
    with app.app_context():
        from importlib import import_module
        import_module('unifispot.middleware')

    @app.route("/")
    @login_required
    def home():
        if current_user.type == 'admin':
            return redirect(url_for('admin.admin_index'))
        elif current_user.type == 'client':
            return redirect(url_for('client.client_index'))
        else:
            app.logger.error("Unknown User Type!! for ID:%s" % current_user.id)
            abort(400)

    return app
コード例 #5
0
ファイル: __init__.py プロジェクト: vinchu/poppet
def create_app(mode="development"):
    """Create webapp instance."""
    app = Flask(__name__, instance_relative_config=True)
    # Load database

    # Initilise DB

    from unifispot.models import user_datastore

    db.init_app(app)

    # Load the default configuration
    app.config.from_object("config.default")

    # Load the configuration from the instance folder
    app.config.from_pyfile("config.py")

    # Load the file specified by the config_filename environment variable
    # Variables defined here will override those in the default configuration
    if mode is not None:
        app.config.from_object("config." + mode)
        # Load test database config
        if mode == "testing":
            app.config.from_pyfile("config_test.py")
        elif mode == "e2e_testing":
            app.config.from_pyfile("config_e2e_test.py")
    # Setup Flask-Security before loading any blueprints
    security = Security(app, user_datastore)
    # initilise mail,celery and redis

    mail.init_app(app)
    celery.init_app(app)
    redis.init_app(app)
    ##not going to use server side sessions
    # sess.init_app(app)

    # initlize assets
    assets = Environment(app)
    assets.register(bundles)
    # simple load all blueprint settings, enabled in config
    load_blueprint_settings(app, blueprint_path="unifispot")

    # simple load all blueprints, enabled in config
    load_blueprints(app, blueprint_path="unifispot")

    # check for default values required before starting app
    with app.app_context():
        from importlib import import_module

        import_module("unifispot.middleware")

    @app.route("/")
    @login_required
    def home():
        if current_user.type == "admin":
            account = Account.query.filter_by(id=current_user.account_id).first()
            if not account:
                app.logger.error("No account found!! Something is wrong")
                abort(404)
            elif account.firstrun != 0:
                # First time running
                return redirect(url_for("superadmin.firstrun"))
            return redirect(url_for("admin.admin_index"))
        elif current_user.type == "client":
            return redirect(url_for("client.client_index"))
        else:
            app.logger.error("Unknown User Type!! for ID:%s" % current_user.id)
            abort(400)

    return app