Exemple #1
0
def create_app():
    app = Flask(__name__)

    load_config(app)

    app.debug = app.config['DEBUG']
    app.secret_key = app.config['SECRET_KEY']

    try:
        locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')
    except locale.Error:
        logging.warning('Could not set locale')

    # init flask extensions
    mail.init_app(app)
    login.init_app(app)

    # init my modules
    models.init_app(app)
    upload.init_app(app)
    filters.init_app(app)
    views.init_app(app)
    algorithm.init_app(app)

    # register routes
    map(app.register_blueprint, views.all_blueprints)

    return app
Exemple #2
0
def create_app():
    app = Flask(__name__)

    load_config(app)

    app.debug = app.config['DEBUG']
    app.secret_key = app.config['SECRET_KEY']

    try:
        locale.setlocale(locale.LC_ALL, 'fr_FR.UTF-8')
    except locale.Error:
        logging.warning('Could not set locale')

    # init flask extensions
    mail.init_app(app)
    login.init_app(app)

    # init my modules
    models.init_app(app)
    upload.init_app(app)
    filters.init_app(app)
    views.init_app(app)
    algorithm.init_app(app)

    # register routes
    map(app.register_blueprint, views.all_blueprints)

    return app
Exemple #3
0
def create_app():
    app = Flask(__name__)
    cors = CORS(app)

    basedir = os.path.abspath(__file__)

    app.config.update(
        dict(
            SECRET_KEY="powerful secretkey",
            WTF_CSRF_SECRET_KEY="a csrf secret key",
            # SQLALCHEMY_DATABASE_URI='mysql+mysqlconnector://root:test@notification_db/notification',
            SQLALCHEMY_DATABASE_URI=
            f'mysql+mysqlconnector://root:test@flexigym-notification-api-db/notification',
            #SQLALCHEMY_DATABASE_URI="sqlite:///" + os.path.join(basedir + 'flexigym-notification_api.db'),
            SQLALCHEMY_TRACK_MODIFICATIONS=False,
            JSON_SORT_KEYS=False))

    models.init_app(app)
    models.create_tables(app)

    app.register_blueprint(notification_api_blueprint)

    swagger_ui_blueprint = get_swaggerui_blueprint(
        SWAGGER_URL,
        API_URL,
    )
    app.register_blueprint(swagger_ui_blueprint, url_prefix=SWAGGER_URL)

    return app
Exemple #4
0
def create_app(config=None):
    app = Flask(__name__)

    # 加载配置
    app.config.from_object('config.settings')
    app.config.from_object('config.secure')

    # 加载环境配置
    if 'FLASK_CONF' in os.environ:
        app.config.from_envvar('FLASK_CONF')

    # 加载具体的配置
    if config is not None:
        if isinstance(config, dict):
            app.config.update(config)
        elif config.endswith('.py'):
            app.config.from_pyfile(config)

    # 将序列、数据库、路由挂载到app
    import serializer, models, router, mail
    serializer.init_app(app)
    models.init_app(app)
    router.init_app(app)
    mail.init_app(app)

    return app
Exemple #5
0
def create_app(name, config_name):
    app = Flask(name)
    app.config.from_object(config[config_name])
    config[config_name].init_app(app)
    models.init_app(app)

    return app
Exemple #6
0
def create_app():
    import models, routers
    app = Flask(__name__)
    app.config.from_pyfile("conf/config.py")
    models.init_app(app)
    routers.init_app(app)
    # services.init_app(app)
    return app
Exemple #7
0
def create_app():
    app = Flask(__name__)
    CORS(app)
    app.config.from_object(config.Config)
    resources.init_app(app)
    models.init_app(app)
    services.init_app(app)
    return app
Exemple #8
0
def create_app():
    my_app = Flask(__name__)
    my_app.config.from_pyfile('conf.py')
    models.init_app(my_app)
    services.init_app(my_app)
    routes.init_app(my_app)

    return my_app
def create_app():
    app = Flask(os.getenv('APPLICATION_NAME'), instance_relative_config=True)
    app.config.from_envvar('SETTINGS')
    CORS(app, resources={r"/*": {"origins": "*"}})

    models.init_app(app)
    views.init_app(app)

    return app
Exemple #10
0
def create_app():
    import models
    import controllers
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI
    CORS(app)
    models.init_app(app)
    controllers.init_app(app)

    return app
Exemple #11
0
def create_app():
    app = Flask(__name__)

    app.config.from_mapping('SQLALCHEMY_DATABASE_URI', 'sqlite:///data/dat.db')

    models.init_app(app)

    @app.before_first_request
    def create_tables():
        db.create_all()

    return app
Exemple #12
0
def init_app(app):
    with app.app_context():
        config.init_app(app)
        models.init_app(app)
        routes.init_app(app)
        services.init_app(app)

        # -- <testing user> -----------------------------------------------
        admin_user = services.user_service.getByUsername('admin')
        if admin_user is None:
            services.user_service.insert('admin', 'admin')
        # -- </testing user> ----------------------------------------------

    app.run(debug=True, port=3000)
Exemple #13
0
def create_app():
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
    app.config['SECRET_KEY'] = 'replace_me'

    from models import db

    import models
    models.init_app(app)

    import auth
    auth.init_app(app, db)
    app.register_blueprint(auth.blueprint)

    return app
Exemple #14
0
 def resetDB(self):
     self.db.session.remove()
     self.db.drop_all()
     
     models.create_tables(self.app)
     fixtures.install(self.app, *fixtures.all_data)
     self.db = models.init_app(self.app)
Exemple #15
0
def create_app():
    from flask import Flask
    app = Flask(__name__)

    from flask_cors import CORS
    CORS(app, support_credentials=True)

    from configs import Config
    app.config.from_object(Config)

    import utils, models, user, auth
    utils.init_app(app)
    models.init_app(app)
    user.init_app(app)
    auth.init_app(app)

    return app
Exemple #16
0
def create_app():
    app = Flask(__name__)

    app.config.update(
        dict(SECRET_KEY="",
             WTF_CSRF_SECRET_KEY="",
             SQLALCHEMY_DATABASE_URI=
             'mysql+mysqlconnector://root:test@product_db/product',
             SQLALCHEMY_TRACK_MODIFICATIONS=False))

    models.init_app(app)
    models.create_tables(app)

    app.register_blueprint(product_api_blueprint)

    swaggerui_blueprint = get_swaggerui_blueprint(SWAGGER_URL, API_URL)

    app.register_blueprint(swaggerui_blueprint, url_prefix=SWAGGER_URL)
Exemple #17
0
def create_app(config=None):
    app = Flask(__name__)
    # 配置跨域资源共享
    cors = CORS(app,
                resources={r'/*': {
                    'origins': '*'
                }},
                allow_headers='Content-Type')
    logging.getLogger('flask_cors').level = logging.DEBUG
    handler = logging.FileHandler('flask.log')
    app.logger.addHandler(handler)
    # load default configuration
    app.config.from_object('config.settings')
    # app.config.from_object('config.secure')

    # load environment configuration
    # FLASK_CONF="/path/to/config_dev.py"
    # FLASK_CONF="/path/to/config_prod.py"
    # 也可以根据系统环境变量,加载不同的配置文件
    if 'FLASK_CONF' in os.environ:
        app.config.from_envvar('FLASK_CONF')

    # load app specified configuration
    if config is not None:
        if isinstance(config, dict):
            app.config.update(config)
        elif config.endswith('.py'):
            app.config.from_pyfile(config)

    app.app_context().push()
    import router
    import models
    import serializer
    router.init_app(app)
    serializer.init_app(app)
    models.init_app(app)
    login_manager = LoginManager()
    login_manager.init_app(app)

    # Register cli commands
    register_commands(app)
    return app
Exemple #18
0
def create_app():
    import models, routes, services, database

    app = Flask(__name__)
    app.config['SQLALCHEMY_TRACK_MODIFICARIONS'] = False
    app.config[
        'SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database/upforgoodDB.sqlite3'
    app.config['SECRET_KEY'] = 'super-secret'
    CORS(app)
    #cors = CORS(app, resources={r"/api/*": {"origins": "*"}})

    models.init_app(app)
    routes.init_app(app)
    services.init_app(app)
    database.init_app(app)

    if __name__ == "__main__":
        app.run(debug=True)

    return app
Exemple #19
0
def create_app(config=None):
    # 创建app
    # 实例化一个app
    # Flask("字符串")
    # 字符串用来Flask对象标识,通常用__name__
    # Flask函数可以接收功能多参数,来配置静态模板中js/css/png等的解析方法
    app = Flask(__name__)
    CORS(app, resources={'*': {'origins': '*'}})

    # load default configuration
    # 加载配置: config.settings和config.secure是模块路径
    app.config.from_object('config.settings')
    app.config.from_object('config.secure')
    # load environment configuration
    # FLASK_CONF="/path/to/config_dev.py"
    # FLASK_CONF="/path/to/config_prod.py"
    # 也可以根据系统环境变量,加载不同的配置文件
    if 'FLASK_CONF' in os.environ:
        app.config.from_envvar('FLASK_CONF')
    # load app sepcified configuration
    if config is not None:
        if isinstance(config, dict):
            app.config.update(config)
        elif config.endswith('.py'):
            app.config.from_pyfile(config)

    # 注册蓝图
    import router, models, serializer
    router.init_app(app)

    # 将model注册到app
    models.init_app(app)

    # 将序列化器注册到app
    serializer.init_app(app)
    # 返回核心对象
    return app
Exemple #20
0
def create_app():
    app = Flask(__name__)

    app.config.update(dict(
        SECRET_KEY="powerful secretkey",
        WTF_CSRF_SECRET_KEY="a csrf secret key",
        #SQLALCHEMY_DATABASE_URI='mysql+mysqlconnector://root:test@product_db/product',
        SQLALCHEMY_DATABASE_URI='mysql+mysqlconnector://root:101091Root@mb3-db-product.ciiwt8d1nmks.ca-central-1.rds.amazonaws.com:3306/product',
        #SQLALCHEMY_DATABASE_URI='mysql+mysqlconnector://root:101091Root@mb3-db-product.ccrz0cn5l7sv.us-east-1.rds.amazonaws.com:3306/product',
        SQLALCHEMY_TRACK_MODIFICATIONS=False
    ))

    models.init_app(app)
    models.create_tables(app)

    app.register_blueprint(product_api_blueprint)

    swaggerui_blueprint = get_swaggerui_blueprint(
        SWAGGER_URL,
        API_URL,
    )
    app.register_blueprint(swaggerui_blueprint, url_prefix=SWAGGER_URL)

    return app
def create_app():
    logging.debug('create_app()')
    app = Flask(__name__)

    app.config.update({
        'SECRET_KEY': "powerful secretkey",
        'WTF_CSRF_SECRET_KEY': "a csrf secret key",
        'SQLALCHEMY_DATABASE_URI':
        'mysql+mysqlconnector://root:test@product_db/product',
        'SQLALCHEMY_TRACK_MODIFICATIONS': False
    })

    models.init_app(app)
    models.create_tables(app)

    app.register_blueprint(product_api_blueprint)

    swaggerui_blueprint = get_swaggerui_blueprint(
        SWAGGER_URL,
        API_URL,
    )
    app.register_blueprint(swaggerui_blueprint, url_prefix=SWAGGER_URL)

    return app
Exemple #22
0
from flask import Flask, render_template, request, redirect, url_for, abort, session, jsonify, json, flash, Response
from ESA import app, login_manager, login_required, login_user, current_user, logout_user
from flask.ext.testing import TestCase

import config
import models
import controllers
import events as controller_events
import controller_privileges
import shifts_controller
import shiftperson_controller


app.config.from_object(config)

db = models.init_app(app)
app.db = db

# helper method to check if request header contain json
# source http://flask.pocoo.org/snippets/45/
def is_request_json():
    if hasattr(request, 'accept_mimetypes'):
        best = request.accept_mimetypes.best_match(['application/json', 'text/html'])
        return best == 'application/json' and request.accept_mimetypes[best] > request.accept_mimetypes['text/html']
    else:
        return False

# user loader callback
@login_manager.user_loader
def load_user(id):
    return controllers.getPersonById(int(id), db)
Exemple #23
0
import random
from flask import Flask, request, make_response, render_template
from models import Game, PrivateWord, init_app

app = Flask(__name__)
app.config.setdefault('SQLALCHEMY_TRACK_MODIFICATIONS', False)
#app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////home/gunnar/Backend/hangman/test.db'
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////home/gunnar/botti/test.db'

init_app(app)


@app.route("/")
def hello():
    return render_template('index.html')


@app.route("/image/<image_id>")
def get_image(image_id):
    return app.send_static_file("Hangman-{}.png".format(image_id))


@app.route("/newgame")
def new_game():

    game_id = request.args.get('game_id')
    word = None
    try:
        word = PrivateWord.query.filter_by(
            id=game_id).first().word if game_id else get_random_word()
    except AttributeError:
Exemple #24
0
 def setUpClass(self):
     models.create_tables(self.app)
     fixtures.install(self.app, *fixtures.all_data)
     self.db = models.init_app(self.app)
Exemple #25
0
def create_app():
    app = Flask(__name__)
    models.init_app(app)
    routes.init_app(app)
    services.init_app(app)
    return app
Exemple #26
0
def create_app_models_only():
    import models
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI
    models.init_app(app)
    return app
 def setUpClass(self):
     models.create_tables(self.app)
     fixtures.install(self.app, *fixtures.organization_test_data)
     self.db = models.init_app(self.app)
Exemple #28
0
def create_app(config, debug=False, testing=False, config_overrides=None):
    app = Flask(__name__)
    app.config.from_object(config)

    app.debug = debug
    app.testing = testing

    # Load configs
    if config_overrides:
        app.config.update(config_overrides)

    # Configure logging
    if not app.testing:
        logging.basicConfig(level=logging.INFO)

    # Setup the data model.
    with app.app_context():
        import models 
        models.init_app(app)

    ## Flask-login init
    login_manager = LoginManager()
    login_manager.init_app(app)
    login_manager.login_view = "/login"

    # Register blueprints
    from controllers.auth import auth
    from controllers.customer_admin import customer_admin
    from controllers.users import users
    from controllers.groups import groups
    from controllers.search import search
    from controllers.sms import sms

    app.register_blueprint(auth)
    app.register_blueprint(customer_admin, url_prefix='/a')
    app.register_blueprint(users, url_prefix='/users')
    app.register_blueprint(groups, url_prefix='/groups')
    app.register_blueprint(search, url_prefix='/search')
    app.register_blueprint(sms, url_prefix='/sms')

    # flask-login implementation
    @login_manager.user_loader
    def load_user_with_id(user_id):
        return User.query.get(user_id)

    # Add a default root route.
    @app.route("/")
    def index():
        return redirect(url_for('customer_admin.home'))

    # Add an error handler. This is useful for debugging the live application,
    # however, you should disable the output of the exception for production
    # applications.
    @app.errorhandler(500)
    def server_error(e):
        return """
        An internal error occurred: <pre>{}</pre>
        See logs for full stacktrace.
        """.format(e), 500

    return app
        True,
        'EMAIL_TIMEOUT':
        5,
    })


@app.errorhandler(404)
def not_found(e):
    if request.path.startswith('/api/v1'):
        return jsonify({'message': 'Not found'}), 404

    return render_template('404.html'), 404


api = Api(app, prefix='/api/v1')
models.init_app(app)
auth.jwt.init_app(app)
validation.init_app(app)
limiter.init_app(app)
tasks.init_app(app)

from tasks import celery


def db_ok():
    return User.query.count() >= 0, "database ok"


def tasks_ok():
    # Convert to int, Redis always returns bytes
    succeeded = int(celery_redis.get('succeeded'))
Exemple #30
0
#!/usr/bin/python3
# -*- coding:utf-8 -*-
# Author:Linany
from flask import Flask
from config import Config
import routes
import static
import models


# 实例化配置
config = Config()

# 创建Flash核心对象
app = Flask(__name__)

# 创建数据库Sqlalchemy实例
db = models.init_app(app)

# 绑定各模块到核心对象
static.init_app(app)
routes.init_app(app)

if __name__ == '__main__':
    APP_HOST = config.get("app_host")
    PORT = config.get("app_port")
    DEBUG = config.get("debug")
    app.run(host=APP_HOST, port=PORT, debug=DEBUG)