示例#1
0
def create_app(env):
    configure_app(app, env)
    # setup Blueprint
    app.register_blueprint(webapi)
    # init_db()
    configure_bundle(app)

    return app
示例#2
0
def create_app(config_name):
    """
    Returns a new Flask app with all proper configurations ready.
    """
    app = Flask(__name__)
    configure_app(app, config_name)
    configure_db(app, db)
    configure_api(app)
    configure_external_apis(app)
    return app
示例#3
0
def init_app(app, config_type):
    configure_app(app, config_type)
    app.url_map.strict_slashes = False
    db.init_app(app)

    api.init_app(app)
    api.add_namespace(ns)

    if config_type == "testing":
        with app.app_context():
            db.drop_all()
            db.create_all()
示例#4
0
def create_app(test_config=None):
    # create and configure the app
    app = FlaskAPI(__name__, instance_relative_config=True)
    app.config.from_mapping(SECRET_KEY='dev')

    if test_config is None:
        # Load the default configuration
        configure_app(app)
    else:
        # load the test config if passed in
        app.config.from_mapping(test_config)

    app.register_blueprint(api, url_prefix='/api')

    return app
示例#5
0
def create_app() -> Flask:
    # Flask app initialization
    app = Flask(__name__)

    from config import configure_app

    # Configure app
    configure_app(app)

    app.url_map.strict_slashes = False

    from app.api.auth.auth import auth
    app.register_blueprint(auth, url_prefix='/api/auth')

    from app.api.employee.controllers import employee
    app.register_blueprint(employee, url_prefix='/api/employees')
    
    db.init_app(app)
    bcrypt.init_app(app)

    return app
示例#6
0
from flask import Flask
from flask import render_template
from flask import session
from flask import request
from flask import g
from flask import redirect, flash
from flask_wtf.csrf import CSRFProtect, CSRFError
from flask_session import Session

from utils import LoginForm, APIConnector, APIResponseError
from config import configure_app
from views import *

app = Flask(__name__, static_folder="./static")
csrf = CSRFProtect(app)
configure_app(app, 'default')
Session(app)

# Add blueprint
with app.app_context():
    app.register_blueprint(auth.mod, url_prefix='/auth')
    app.register_blueprint(login.mod, url_prefix='/users')
    app.register_blueprint(mypage.mod, url_prefix='/mypage')
    app.register_blueprint(service.mod, url_prefix='/service')
    app.register_blueprint(order.mod, url_prefix='/order')
    app.register_blueprint(ask.mod, url_prefix='/ask')


@app.before_request
def init_app():
    g.backend_url = app.config['BACKEND_URL']
示例#7
0
import os
from flask import Flask
from flask_caching import Cache
from dotenv import load_dotenv
from config import configure_app, get_cache_config

basedir = os.path.abspath(os.path.dirname(__file__))
load_dotenv(os.path.join(basedir, '.env'))

app = configure_app(Flask(__name__))
cache = Cache(app, config=get_cache_config(app))

from fib import controllers

if __name__ == '__main__':
    app.run()
示例#8
0
from flask import Flask, render_template
from flask.ext.sqlalchemy import SQLAlchemy
from config import configure_app

# Create app
app = Flask(__name__)

configure_app(app)

# Create database connection object
db = SQLAlchemy(app)

from security import configure_security

import views

@app.before_first_request
def main_start():
    print('main start')
    configure_security()
示例#9
0
from config import configure_app
from flask import Flask, render_template
from models import Luggage, db
from routes import luggage
from sqlalchemy import create_engine

flask_app = Flask(__name__, template_folder='templates')

configure_app(flask_app)
db.init_app(flask_app)

flask_app.register_blueprint(luggage, url_prefix='/luggage')

@flask_app.teardown_appcontext
def close_db(error=None):
    """Closes the database again at the end of the request."""
    # Flask does .remove() automatically at the end of each HTTP request ("view" functions), 
    # so the session is released by the current thread.
    pass
    
engine = create_engine('sqlite:///./Luggage.db')
db.metadata.create_all(bind=engine)      
示例#10
0
import config

from flask import Flask
from flask_bcrypt import Bcrypt
from flask_sqlalchemy import SQLAlchemy
from flask_restful import Api
from flask_cors import CORS
from flask_jwt_extended import JWTManager

from app.videos.resources import Videos
from app.authentication.resources import Login, Register, RefreshToken, LogoutAccess, LogoutRefresh, Account, ApiKey

flask_app = Flask(__name__)
bcrypt = Bcrypt(flask_app)
config.configure_app(flask_app)
db = SQLAlchemy(flask_app)
jwt = JWTManager(flask_app)
CORS(flask_app)
recaptcha = ReCaptcha(app=flask_app)

api = Api(flask_app, catch_all_404s=True)

api.add_resource(Videos, '/videos')
api.add_resource(Login, '/login')
api.add_resource(Account, '/account')
api.add_resource(LogoutAccess, '/logout-access')
api.add_resource(LogoutRefresh, '/logout-refresh')
api.add_resource(RefreshToken, '/refresh-token')
api.add_resource(Register, '/register')
api.add_resource(ApiKey, '/api-key')
示例#11
0
#!/bin/python3

import os

from config import configure_app

app = configure_app()

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8080)
示例#12
0
from flask import Flask
from flask_cors import CORS
from flask_migrate import Migrate
from flask_sqlalchemy import SQLAlchemy

from config import configure_app

app = Flask(__name__)
configure_app(app, 'dev')
db = SQLAlchemy()
migrate = Migrate(db)
cors = CORS(app, resources={
    r'/api/*': {
        'origins': app.config['ORIGINS']
    }
})

from app import routes
示例#13
0
#####################################################
#           Config                                  #
#####################################################

# Initiate the app
app = Flask(__name__)
# Connect the db to the app
# db.init_app(app)
# Set the run_mode of the app - one of "local" or "prod"
if sys.platform == "win32":
    run_mode = "local"
else:
    run_mode = "prod"
# Configure the app
configure_app(app, run_mode)

if run_mode == "prod":
    requests_toolbelt.adapters.appengine.monkeypatch()

#####################################################
#           Views                                   #
#####################################################


@app.route("/")
@app.route("/index/")
def playoffs_widget():
    # r = requests.get("https://data.nba.com/data/v2015/json/mobile_teams/nba/2017/scores/00_playoff_bracket.json")
    # return json.dumps(json.loads(r.text))
    return render_template("index.html")
示例#14
0
def create_app(minimal=False, config_file="config.ini", test=False):
    config = load_config(config_file)
    app = Flask(__name__, static_folder="./dist")
    # configure the app
    configure_app(app, config, test)

    if __name__ != '__main__' and test is False:
        gunicorn_logger = logging.getLogger('gunicorn.error')
        app.logger.handlers = gunicorn_logger.handlers
        app.logger.setLevel(gunicorn_logger.level)

    # logging.basicConfig(level=logging.DEBUG, format='%(threadName)s %(message)s')

    if not minimal:
        CORS(app)
        logManager.init_app(app)
        logManager.info("Started roseguarden: " + version)
        jwt.init_app(app)
        workspaceManager.discoverModels()
        bcrypt.init_app(app)

    from core import app_bp  # noqa: F401
    app.register_blueprint(app_bp)

    from core.actions import actions_bp, models  # noqa: F401, F811
    app.register_blueprint(actions_bp)

    from core.users import auth_bp, models  # noqa: F401, F811
    app.register_blueprint(auth_bp)

    from core.logs import logs_bp  # noqa: F401, F811
    app.register_blueprint(logs_bp)

    from core.jobs import jobs_bp  # noqa: F401, F811
    app.register_blueprint(jobs_bp)

    from core.messages import messages_bp  # noqa: F401, F811
    app.register_blueprint(messages_bp)

    from core.files import files_bp  # noqa: F401, F811
    app.register_blueprint(files_bp)

    from core.nodes import nodes_bp  # noqa: F401, F811
    app.register_blueprint(nodes_bp)

    # import workspace blueprint and models
    from core.workspaces import workspaces_bp, models  # noqa: F401, F811
    app.register_blueprint(workspaces_bp)

    from api import api_bp  # noqa: F401, F811
    app.register_blueprint(api_bp)

    is_database_new = not database_exists(
        app.config['SQLALCHEMY_DATABASE_URI'])
    db.init_app(app)

    with app.app_context():
        db.create_all()

    if not minimal:
        migrate.init_app(app, db)
        jobManager.init_manager(app, db, config)
        workspaceManager.init_app(app, db)
        userManager.init_manager(app, db, workspaceManager, config)
        nodeManager.init_manager(app, db, workspaceManager)
        messageManager.init_manager(app, db, workspaceManager, config)
        menuBuilder.init_builder(app, db, userManager, workspaceManager)
        actionManager.init_manager(app, db, userManager, menuBuilder,
                                   workspaceManager, nodeManager, config)
        fileManager.init_manager(app, db, workspaceManager, config)

    with app.app_context():
        nodeManager.init_nodes()

    return app, is_database_new
示例#15
0
def create_app():
    flask_app = Flask(__name__)
    config.configure_app(flask_app)
    elasticsearch_url = flask_app.config['ELASTICSEARCH_URL']
    flask_app.elasticsearch = Elasticsearch(hosts=[elasticsearch_url])
    return flask_app
示例#16
0
def create_app():
    flask_app = Flask(__name__)
    config.configure_app(flask_app)
    elasticsearch_url = flask_app.config['ELASTICSEARCH_URL']
    flask_app.elasticsearch = Elasticsearch(hosts=[elasticsearch_url])
    return flask_app
示例#17
0
from flask_restplus import Api
from flask_sqlalchemy import SQLAlchemy
from flask_socketio import SocketIO
from functools import wraps
from sqlalchemy.exc import SQLAlchemyError

from app.exceptions import AuthError

from sqlalchemy import event
from sqlalchemy.engine import Engine

application = Flask(__name__, instance_relative_config=True)

# Make sure we 404 when the trailing slash is not present on ALL routes
application.url_map.strict_slashes = True
configure_app(application)

db = SQLAlchemy(application)
db.init_app(application)

cache = Cache(config={'CACHE_TYPE': 'simple'})
cache.init_app(application)

ma = Marshmallow(application)

socketio = SocketIO(engineio_logger=True)

if application.config['ACTIVE_MQ_URL'] is not None:
    socketio.init_app(application,
                      async_mode='eventlet',
                      message_queue=application.config['ACTIVE_MQ_URL'],
示例#18
0
def application():
    """ Create and configure a new app instance for each test. """

    configure_app(app)
    yield app
示例#19
0
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_script import Manager
from flask_migrate import Migrate, MigrateCommand
from flask_bootstrap import Bootstrap
from flask_login import LoginManager
from config import configure_app

app = Flask(__name__, static_url_path="/static")
configure_app(app)
bootstrap = Bootstrap(app)
db = SQLAlchemy(app)
# migrate = Migrate(app, db)
# manager = Manager(app)
# manager.add_command('db', MigrateCommand)
login = LoginManager(app)
login.login_view = "login"

from app import routes, models

# if __name__ == '__main__':
#     app.run()
    def _get_year(self, date):
        return date.split("-")[0]


if __name__ == "__main__":
    parser = argparse.ArgumentParser()

    parser.add_argument("--csv", help="the file path to the crime data csv")
    parser.add_argument("--zip",
                        help="the file path to a zip containing crime"
                        " report csvs, in dated directories")
    args = parser.parse_args()

    with app.app_context():
        if os.environ.get("USING_DOCKER"):
            configure_app(app, "docker")
            db.init_app(app)
            db.drop_all()
            db.create_all()
        else:
            configure_app(app, "default")
            db.init_app(app)

        ingestor = CrimeDataIngestor(db=db)

        if args.csv:
            ingestor.ingest_csv(args.csv)
        elif args.zip:
            ingestor.import_data(args.zip)