Beispiel #1
0
def create_app(object_name, env="prod"):
    # An flask application factory, as explained here:
    # http://flask.pocoo.org/docs/patterns/appfactories/

    # Arguments:
    #     object_name: the python path of the config object,
    #                  e.g. appname.settings.ProdConfig

    #     env: The name of the current environment, e.g. prod or dev

    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config["ENV"] = env

    # init the cache
    # cache.init_app(app)

    # init SQLAlchemy
    # db.init_app(app)

    # Import and register the different asset bundles
    # assets_env.init_app(app)
    # assets_loader = PythonAssetsLoader(assets)
    # for name, bundle in assets_loader.load_bundles().iteritems():
    # assets_env.register(name, bundle)

    # register our blueprints
    # from controllers.main import main
    # app.register_blueprint(main)

    return app
def create_app(object_name, env="prod"):
    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config["ENV"] = env

    # define custom errors
    @app.errorhandler(400)
    def custom_error_400(error):
        response = jsonify({"code": 400, "message": "Error 400 Bad request", "description": error.description})
        response.status_code = 400
        return response

    @app.errorhandler(500)
    def custom_error_500(error):
        response = jsonify(
            {"code": 500, "message": "Error 500 Internal server error", "description": error.description}
        )
        response.status_code = 500
        return response

    # initialize SQLAlchemy
    db.init_app(app)

    # register our blueprints
    app.register_blueprint(main)

    return app
Beispiel #3
0
def create_app(object_name, env="prod"):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. caliSurfApp.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """

    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config["ENV"] = env

    # initialize the cache
    cache.init_app(app)

    # initialize the debug tool bar
    debug_toolbar.init_app(app)

    # initialize SQLAlchemy
    # db.init_app(app)

    # login_manager.init_app(app)

    # register our blueprints
    app.register_blueprint(rest_service, url_prefix="/api")
    app.register_blueprint(main)

    return app
Beispiel #4
0
def create_app():
    app = Flask(__name__)

    # Determine current environment
    env = os.environ.get("APOLLO_ENV").capitalize() if os.environ.get("APOLLO_ENV") else "Development"
    app.config.from_object("config." + env)
    app.config["ENV"] = env

    # Are we using postgres specific features?
    assert "postgres" in app.config["SQLALCHEMY_DATABASE_URI"]

    # Set up api routes
    from app.controllers import question

    app.register_blueprint(question)

    # Set up template routes
    @app.route("/")
    def index():
        values = {}
        questions = Question.query.filter(Question.is_live == True).all()
        values["questions"] = questions
        return render_template("index.html", **values)

    # Set up connection to DB
    db.init_app(app)
    return app
Beispiel #5
0
def create_app(object_name, env="dev"):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. mobsec.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """

    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config["ENV"] = env
    # initialize the cache
    cache.init_app(app)

    # initialize the debug tool bar
    debug_toolbar.init_app(app)

    # initialize SQLAlchemy
    db.init_app(app)

    # Import and register the different asset bundles
    assets_env.init_app(app)
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().items():
        assets_env.register(name, bundle)

    # register our blueprints
    app.register_blueprint(main)

    return app
def create_app(object_name, env="prod"):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. appname.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """

    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config["ENV"] = env

    # init the cache
    cache.init_app(app)

    # init SQLAlchemy
    db.init_app(app)

    # connect to the database
    mongo.init_app(app)

    # init admin views
    import flask.ext.admin

    admin = flask.ext.admin.Admin(app, u"用户管理系统")
    babel = Babel(app)

    @babel.localeselector
    def get_locale():
        return "zh"

    with app.app_context():
        admin.add_view(OperatorView(mongo.db.operator, u"专员管理"))

    # Import and register the different asset bundles
    assets_env.init_app(app)
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().iteritems():
        assets_env.register(name, bundle)

    # register our blueprints
    from controllers.main import main

    app.register_blueprint(main)

    return app
Beispiel #7
0
def create_app(object_name, env="prod"):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. ivy_3dprint_site.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """

    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config["ENV"] = env

    # init the cache
    cache.init_app(app)

    # init SQLAlchemy
    db.init_app(app)

    # int Flask-admin
    admin = Admin(app)
    from controllers.admin import UserView, ProductView
    from models import User, Tag, Lang, Photo, Product, File, Sample, Contact, About
    from forms import CKTextAdmin

    admin.add_view(UserView(User))
    admin.add_view(ModelView(Tag))
    admin.add_view(ModelView(Lang))
    admin.add_view(ModelView(Photo))
    admin.add_view(ModelView(File))
    admin.add_view(ProductView(Product))
    admin.add_view(CKTextAdmin(Sample))
    admin.add_view(CKTextAdmin(Contact))
    admin.add_view(CKTextAdmin(About))

    # Import and register the different asset bundles
    assets_env.init_app(app)
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().iteritems():
        assets_env.register(name, bundle)

    # register our blueprints
    from controllers.main import main

    app.register_blueprint(main)

    return app
Beispiel #8
0
def create_app(object_name, env="prod"):

    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config["ENV"] = env

    app.register_blueprint(main_blueprint)

    assets = Environment(app)
    css = Bundle("css/style.scss", filters="scss", output="css/style.css")
    assets.register("base_style", css)

    return app
def create_app(config_obj, env="prod"):
    """ A Flask application factory
            (http://flask.pocoo.org/docs/patterns/appfactories/)
    """
    app = Flask(__name__)

    app.config.from_object(config_obj)
    app.config["ENV"] = env

    db.init_app(app)

    # Register blueprints for the app.
    app.register_blueprint(main)

    return app
Beispiel #10
0
def create_app(object_name, env="prod"):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. neogameserver.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """

    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config["ENV"] = env

    admin = Admin(app, name="neogameserver", template_mode="bootstrap3")
    admin.add_view(NeoModelView(User, db.session))
    admin.add_view(NeoModelView(Subscription, db.session))
    admin.add_view(NeoModelView(MinecraftProduct, db.session))
    admin.add_view(NeoModelView(VentriloProduct, db.session))
    admin.add_view(NeoModelView(OrderProduct, db.session))
    admin.add_view(NeoModelView(HostServer, db.session))
    admin.add_view(NeoModelView(Port, db.session))

    # initialize the cache
    cache.init_app(app)

    # initialize the debug tool bar
    debug_toolbar.init_app(app)

    # initialize SQLAlchemy
    db.init_app(app)

    login_manager.init_app(app)

    # Import and register the different asset bundles
    assets_env.init_app(app)
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().items():
        assets_env.register(name, bundle)

    # register our blueprints
    app.register_blueprint(main)
    app.register_blueprint(adminviews)

    return app
Beispiel #11
0
def create_app(object_name, env="prod"):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. fv_prov_es.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """

    app = Flask(__name__)

    app.wsgi_app = ReverseProxied(app.wsgi_app)

    app.config.from_object(object_name)
    app.config["ENV"] = env

    # init extensions
    cache.init_app(app)
    debug_toolbar.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)

    # Import and register the different asset bundles
    assets_env.init_app(app)
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().iteritems():
        assets_env.register(name, bundle)

    # register our blueprints
    from controllers.main import main

    app.register_blueprint(main)

    from controllers.services_v01 import services as services_v01

    app.register_blueprint(services_v01)

    from controllers.services_v02 import services as services_v02

    app.register_blueprint(services_v02)

    app.register_blueprint(apidoc.apidoc)

    return app
def create_app(object_name, env="prod"):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. appname.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """

    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config["ENV"] = env

    # initialize the cache
    cache.init_app(app)

    # initialize the debug tool bar
    debug_toolbar.init_app(app)

    # initialize SQLAlchemy
    db.init_app(app)

    mail = Mail(app)

    security = Security(app, user_datastore)

    @security.context_processor
    def security_context_processor():
        return dict(admin_base_template=admin.base_template, admin_view=admin.index_view, h=admin_helpers)

    admin.init_app(app)

    # Import and register the different asset bundles
    assets_env.init_app(app)
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().items():
        assets_env.register(name, bundle)

    # register our blueprints
    app.register_blueprint(main)

    return app
Beispiel #13
0
def create_app(config_object, env="prod"):
    app = Flask(__name__)

    app.config.from_object(config_object)
    app.config["ENV"] = env
    db.init_app(app)
    mail.init_app(app)
    security = Security(app, user_datastore)

    @security.context_processor
    def security_context_processor():
        return dict(
            admin_base_template=admin.base_template, admin_view=admin.index_view, h=admin_helpers, get_url=url_for
        )

    admin.init_app(app)

    return app
def create_app(config=main_config, env=environment):
    if not config:
        raise ConfigNotFoundError("Config is not available")
    if not env:
        raise ConfigNotFoundError("Environment is not set")

    app = Flask(__name__, template_folder=os.path.abspath("templates"), static_folder=os.path.abspath("static"))

    app.config["DEBUG"] = flask_config.get("debug")
    app.config["ASSETS_DEBUG"] = app.config["DEBUG"]

    app.config["SECRET_KEY"] = env["flask"].get("secret_key")
    app.config["ENV"] = env

    create_routes(app)
    compile_assets(app)

    return app
Beispiel #15
0
def create_app(object_name, env="prod"):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. one_server.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """

    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config["ENV"] = env

    # init the cache
    cache.init_app(app)

    # connect to the database
    mongo.init_app(app)

    api.init_app(app)
    login_manager.init_app(app)

    # Import and register the different asset bundles
    assets_env.init_app(app)
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().iteritems():
        assets_env.register(name, bundle)

    # register our blueprints
    from controllers.main import main

    app.register_blueprint(main)

    import controllers.ride
    import controllers.user

    with app.app_context():
        init_db()

    return app
def create_app(object_name, env="prod"):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. hearthstone.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """

    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config["ENV"] = env

    # init the cache
    cache.init_app(app)

    # init SQLAlchemy
    db.init_app(app)

    api.init_app(app)

    mongo.init_app(app)

    # Import and register the different asset bundles
    assets_env.init_app(app)
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().iteritems():
        assets_env.register(name, bundle)

    # register our blueprints
    from controllers.main import main

    app.register_blueprint(main)

    import controllers.restful

    controllers.restful.register(api)

    return app
Beispiel #17
0
def create_app(object_name, env):
    """
    An flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Arguments:
        object_name: the python path of the config object,
                     e.g. appname.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """

    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config["ENV"] = env

    # Initialize Jinja custom filters
    import filters

    filters.init_app(app)

    # register our blueprints
    from app.blueprints import main

    app.register_blueprint(main)

    @app.errorhandler(500)
    def error_handler_500(e):
        return render_template("500.html"), 500

    @app.errorhandler(404)
    def error_handler_404(e):
        return render_template("404.html"), 404

    return app
Beispiel #18
0
def create_app(instance_path="", env="prod"):
    """Create the app."""
    app_name = ".".join(__name__.split(".")[0:2])

    instance_path = instance_path or os.path.join(sys.prefix, "var", app_name + "-instance")
    try:
        if not os.path.exists(instance_path):
            os.makedirs(instance_path)
    except Exception:
        pass

    app = Flask(
        app_name,
        instance_path=instance_path,
        instance_relative_config=True,
        static_folder=os.path.join(instance_path, "static"),
    )

    app.config["ENV"] = env
    env_object = "iiif.base.config.{0}Config".format(env.capitalize())
    app.config.from_object(env_object)
    app.config.from_envvar("iiif_ENV_SRC", silent=True)
    app.config.from_pyfile("application.cfg", silent=True)

    # Ignore slashes
    app.url_map.strict_slashes = False

    # Add the proxies
    Registry(app=app)
    app.extensions["registry"].update(packages=PackageRegistry(app))
    app.extensions["registry"].update(
        extensions=ExtensionRegistry(app), blueprints=BlueprintAutoDiscoveryRegistry(app=app)
    )
    ConfigurationRegistry(app)
    _setup_app_errors(app)
    return app
Beispiel #19
0
from flask_oauthlib.provider import OAuth2Provider
from webassets.loaders import PythonLoader
from j4oauth import assets
from j4oauth.utils import ReverseProxied

app = Flask(__name__)

app.wsgi_app = ReverseProxied(app.wsgi_app)

# The environment variable, either 'prod' or 'dev'
env = os.environ.get("J4OAUTH_ENV", "dev")

# Use the appropriate environment-specific settings
app.config.from_object("j4oauth.settings.{env}Config".format(env=env.capitalize()))

app.config["ENV"] = env

# Set up logging
file_handler = RotatingFileHandler(app.config["LOG_FILE"])
file_handler.setLevel(logging.INFO)
file_handler.setFormatter(Formatter("%(asctime)s %(levelname)s: %(message)s " "[in %(pathname)s:%(lineno)d]"))
app.logger.addHandler(file_handler)

if "SENTRY_DSN" in app.config:
    from raven.contrib.flask import Sentry

    sentry = Sentry(app)

CsrfProtect(app)

db = SQLAlchemy(app)
from flask import Flask
import os


__all__ = ["app"]


app = Flask(__name__)
app.config["ENV"] = os.environ.get("FLASK_ENV", "prod")
app.config.from_object("amzstorefront.settings.%sConfig" % app.config["ENV"].capitalize())


import views
Beispiel #21
0
def create_app(object_name, env="prod"):
    """
    A flask application factory, as explained here:
    http://flask.pocoo.org/docs/patterns/appfactories/

    Inputs:  ::\n
        object_name: the python path of the config object,
                     e.g. appname.settings.ProdConfig

        env: The name of the current environment, e.g. prod or dev
    """

    app = Flask(__name__)

    app.config.from_object(object_name)
    app.config["ENV"] = env

    # Init the cache
    cache.init_app(app)

    # Init debug toolbar
    debug_toolbar.init_app(app)

    # Init Mongo engine
    # mongoengine.connect(config.MONGODB_FRONTEND_DB_NAME, host=config.MONGODB_HOST, port=config.MONGODB_PORT)
    app.config["MONGODB_DB"] = config.MONGODB_FRONTEND_DB_NAME
    app.config["MONGODB_HOST"] = config.MONGODB_HOST
    app.config["MONGODB_PORT"] = config.MONGODB_PORT
    db.init_app(app)

    # Init login_manager
    login_manager.init_app(app)
    login_manager.login_view = "main.login"
    login_manager.refresh_view = "main.login"
    # Init current to track current project/experiment
    current.init_app(app)

    # Import and register the different asset bundles
    assets_env.init_app(app)
    assets_loader = PythonAssetsLoader(assets)
    for name, bundle in assets_loader.load_bundles().iteritems():
        assets_env.register(name, bundle)

    # register all the  blueprints
    from controllers import (
        main,
        error,
        dashboard,
        new_experiment,
        new_project,
        account_settings,
        project,
        experiment,
        targets,
        setup,
    )

    app.register_blueprint(main)
    app.register_blueprint(error, url_prefix="/error")
    app.register_blueprint(dashboard, url_prefix="/dashboard")
    app.register_blueprint(new_experiment, url_prefix="/new_experiment")
    app.register_blueprint(new_project, url_prefix="/new_project")
    app.register_blueprint(account_settings, url_prefix="/account_settings")
    app.register_blueprint(project, url_prefix="/project")
    app.register_blueprint(experiment, url_prefix="/experiment")
    app.register_blueprint(targets, url_prefix="/targets")
    app.register_blueprint(setup, url_prefix="/setup")

    return app
Beispiel #22
0
def create_app(config="dev"):
    """ Flask application factory
    :param str config: type of app to build, either "prod" or "dev"
    """
    # Create flask application
    app = Flask(__name__)
    app.config.from_object("settings")
    app.config["ENV"] = config
    app.jinja_env.trim_blocks = True

    # Debug toolbar (when debug=true)
    debug_toolbar = DebugToolbarExtension(app)
    app.config["DEBUG_TB_PROFILER_ENABLED"] = True
    app.config["DEBUG_TB_INTERCEPT_REDIRECTS"] = False

    # Register Blueprints
    app.register_blueprint(views_base.base)
    app.register_blueprint(views_blog.blog)

    # Flask-Assets; bundles all css/js files in minifed file
    assets = Environment(app)
    css_all = Bundle(
        "css/bootstrap-flatly.min.css",
        "css/highlightjs.min.css",
        "css/font-awesome.css",
        "css/main.css",
        filters="cssmin",
        output="gen/style.css",
    )
    js_all = Bundle(
        "js/vendor/jquery.min.js",
        "js/vendor/bootstrap.min.js",
        "js/vendor/showdown-gfm.min.js",
        "js/vendor/highlight.min.js",
        "js/main.js",
        filters="jsmin",
        output="gen/libs.js",
    )
    assets.register("css_all", css_all)
    assets.register("js_all", js_all)
    if app.config["DEBUG"]:
        assets.debug = True
        app.config["ASSETS_DEBUG"] = True

    # Set up Flask-User
    babel = Babel(app)
    db_adapter = SQLAlchemyAdapter(db, User)
    user_manager = UserManager(db_adapter, app)  # Init Flask-User and bind to app

    # Init the cache
    cache.init_app(app)

    Moment(app)  # moment.js
    Misaka(
        app,
        autolink=True,  # Misaka Markdown
        fenced_code=True,
        lax_html=True,
        strikethrough=True,
        superscript=True,
        tables=True,
        wrap=True,
    )

    # Init Admin page
    admin = Admin(app, index_view=AdminMain(endpoint="admin"))
    admin.add_view(PostAdminView())
    admin.add_view(NewPostView())
    admin.add_view(ModelView(Comment, db.session))
    static_path = os.path.join(BASE_DIR, "app", "static")
    admin.add_view(FileAdminView(static_path, "/static/", name="Static Files"))

    # Initialize DB
    db.init_app(app)

    return app
@app.route("/email/", methods=["POST"])
def email():
    emailHandler = EmailRequestHandler(config)
    response = emailHandler.process(request)
    return response


# For Dev purpose only
@app.route("/test/", methods=["GET"])
def test():
    if app.config["ENV"] == "dev":
        f = open("./test/test.html", "r")
        content = f.read()
        return Response(content, status=200, mimetype="text/html")
    else:
        return Response('{"message": "Page not allowed to access"}', status=404)


# Main Service
if __name__ == "__main__":
    config = ConfigLoader()
    if config.isLoaded():
        # get environment
        app.config["ENV"] = config.getEnv()
        print "Environment: " + app.config["ENV"].upper()
        if app.config["ENV"].lower() == "prod":
            app.run(host="0.0.0.0")
        elif app.config["ENV"].lower() == "dev":
            app.run(debug=True)
    else:
        print "Failed to load the config. Can't start the Service."