Example #1
0
def create_app():
    app = Flask(__name__)
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    from docassemble.base.config import daconfig
    import docassemble.webapp.database
    connect_string = docassemble.webapp.database.connection_string()
    alchemy_connect_string = docassemble.webapp.database.alchemy_connection_string()
    app.config['SQLALCHEMY_DATABASE_URI'] = alchemy_connect_string
    app.secret_key = daconfig.get('secretkey', '38ihfiFehfoU34mcq_4clirglw3g4o87')
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    db = SQLAlchemy(app)
    #app.wsgi_app = ProxyFix(app.wsgi_app)
    socketio = SocketIO(app, async_mode='eventlet', verify=False)
    return app, db, socketio
Example #2
0
def create_app():
    app = Flask(__name__,template_folder = 'templates',static_folder = 'static',)
    app.url_map.converters['regex'] = RegexConverter
    basedir = os.path.abspath(os.path.dirname(__file__))
    app.config['SQLALCHEMY_DATABASE_URI']='mysql://root:123456@127.0.0.1/flask'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS']=True
    login_manager.init_app(app)
    db.init_app(app)

    from auth import auth
    from main import main

    app.register_blueprint(auth)
    app.register_blueprint(main)
    app.config['SECRET_KEY'] = 'A0Zr98j/3yX R~XHH!jmN]LWX/,?RT'


    @app.template_filter('sunyang')
    def reverse_filter(s):
        if s == 'sunyang':
            return u"大神你好!"
        else:
            return s

    return app
Example #3
0
def create_app(app_db, db_url):
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = db_url
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
    app_db.app = app
    app_db.init_app(app)
    return app
Example #4
0
def init_app():
    db_path = 'db1.sqlite'

    # 初始化并配置 flask
    app = Flask(__name__)
    # 这一行 加了就没 warning
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
    # 设置你的加密 key
    app.secret_key = 'TODO fixme'
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///{}'.format(db_path)
    # 初始化 db
    db.init_app(app)
    db.app = app

    # 必须在函数中 import 蓝图
    # 否则循环引用(因为蓝图中 import 了 model, model 引用了这个文件里面目的 db)
    # from .auth import blue as auth
    from .controllers import main as controllers
    from .api import main as api1

    # 注册蓝图
    # app.register_blueprint(auth)
    app.register_blueprint(controllers)
    app.register_blueprint(api1, url_prefix='/api')

    # 把 app 引用返回
    return app
Example #5
0
def create_app():

    # Create a flask app.
    app = Flask(__name__)

    # Set debug true for catching the errors.
    app.config['DEBUG'] = True

    # Set database url.
    app.config['SQLALCHEMY_DATABASE_URI'] = SQLALCHEMY_DATABASE_URI

    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True

    # Database initialize with app.
    db.init_app(app)

    # Check if there is no database.
    if not os.path.exists(SQLALCHEMY_DATABASE_URI):

        # New db app if no database.
        db.app = app

        # Create all database tables.
        db.create_all()

    # Return app.
    return app
Example #6
0
def init_app():
    db_path = 'db.sqlite'

    # 初始化并配置 flask
    app = Flask(__name__)
    app.jinja_env.filters['formatted_time'] = formatted_time
    # 这一行 加了就没 warning
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
    # 设置你的加密 key
    app.secret_key = 'TODO fixme'
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///{}'.format(db_path)
    # 初始化 db,套路 xx.init_app()就是flask扩展框架的一种注册套路
    db.init_app(app)
    db.app = app

    # 必须在函数中 import 蓝图
    # 否则循环引用(因为蓝图中 import 了 model, model 引用了这个文件里面目的 db)
    from .auth import blue as auth
    from .controllers import main as controllers
    from .api import main as api

    # 注册蓝图
    app.register_blueprint(auth)
    app.register_blueprint(controllers)
    app.register_blueprint(api, url_prefix='/api')

    return app
Example #7
0
def create_app(config=None):
    """Return a Flask application according to application factory design pattern function.

    Create app object. Configure it. Initialize Flask extensions. Register Blueprints.

    :type config: dict
    :param config: Additional configuration that'll override default values
    """
    app = Flask(__name__)

    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///app.db'  # sqlite://<nohostname>/<path>
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.config['TEMPLATES_AUTO_RELOAD'] = True
    app.config.from_pyfile('secret.py', silent=True)
    if config is not None:
        app.config.update(config)

    misaka.init_app(app)
    login_manager.init_app(app)
    db.init_app(app)

    app.register_blueprint(login)
    app.register_blueprint(static_pages)
    app.register_blueprint(blog, url_prefix='/blog')
    app.register_blueprint(simple_routes)
    app.register_blueprint(tags_api, url_prefix='/blog')

    return app
Example #8
0
def create_app(config_name):
    app = Flask(__name__)



    # Creating the app configurations
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    app.config['SQLALCHEMY_DATABASE_URI'] = 'postgres://hzdjuymgaykvle:4079958f7180f18102b516a8f427e0794e8f22080047c631e44d39f929359d5a@ec2-54-235-240-126.compute-1.amazonaws.com:5432/di59qlb6lan20'

   # Creating the app configurations

    app.config.from_object(config_options[config_name])
    config_options[config_name].init_app(app)

    # Initializing flask extensions
    bootstrap.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)

    # Registering the blueprint
    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)

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

    
    return app
Example #9
0
def create_app():
    app = Flask(__name__)
    app.config.from_object(Conf)
    print('create_app')
    # redis
    app.redis_store = redis.Redis(host=app.config["REDIS_HOST"], port=app.config["REDIS_PORT"], decode_responses=True)

    app.config['SQLALCHEMY_DATABASE_URI'] = Conf.MYSQL_INFO
    app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    # Mail
    app.config['MAIL_SERVER'] = Conf.MAIL_SERVER
    app.config['MAIL_PORT'] = Conf.MAIL_PORT
    app.config['MAIL_USE_TLS'] = Conf.MAIL_USE_TLS


    # 蓝图
    from app.admin import admin_api as admin_api_blueprint
    app.register_blueprint(admin_api_blueprint, url_prefix='/api/admin')

    from app.api.v1_0_0 import api_v1_0_0 as api_1_0_blueprint
    app.register_blueprint(api_1_0_blueprint, url_prefix='/api/v1.0.0')

    from app.api.v1_0_1 import api_v1_0_1 as api_1_1_blueprint
    app.register_blueprint(api_1_1_blueprint, url_prefix='/api/v1.0.1')

    # init
    db.init_app(app)
    return app
Example #10
0
def create_app(config):
    app = Flask(__name__)

    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    # app.config['SQLALCHEMY_ECHO'] = True
    # app.config['DEBUG'] = True
    if config == 'Test':
        app.config['TEST'] = True
    app.secret_key = 'only-testing'

    from webgrid_ta.model import db
    db.init_app(app)
    webgrid.init_db(db)
    default_registry.locales = app.config.get('DEFAULT_LOCALE', 'en')
    configure_jinja_environment(app.jinja_env, translation_manager)
    Bootstrap(app)
    webgrid.init_app(app)

    from .views import main
    app.register_blueprint(main)

    @app.before_request
    def set_language():
        default_registry.locales = str(flask.request.accept_languages)
        configure_jinja_environment(app.jinja_env, translation_manager)

    return app
Example #11
0
def create_app(config_name):
	app = Flask(__name__)
	app.config.from_object(config[config_name])
	app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True

	config[config_name].init_app(app)

	db.init_app(app)
	login_manager.init_app(app)
	bootstrap.init_app(app)
	moment.init_app(app)
	mail.init_app(app)
	pagedown.init_app(app)
	admin.init_app(app)

	from .api_1_0 import api as api_1_0_blueprint
	app.register_blueprint(api_1_0_blueprint, url_prefix='/api/v1.0')

	from .main import main as main_blueprint
	app.register_blueprint(main_blueprint)
	from .auth import auth as auth_blueprint
	app.register_blueprint(auth_blueprint, url_prefix='/auth')

	with app.app_context():
		db.create_all()
	return app
Example #12
0
def create_app():
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///intent.db'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    babel = Babel(app)
    db.init_app(app)
    return app
Example #13
0
def init_app():
    # db_path = '/Users/linmingwang/twitter/db.sqlite'
    # db_path = '/var/www/twitter/db.sqlite'
    db_path = '/home/lin/twitter.db.sqlite'

    # 初始化并配置 flask
    app = Flask(__name__)
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
    app.config['MAX_CONTENT_LENGTH'] = 2 * 1024 * 1024
    app.secret_key = 'TODO fixme'
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///{}'.format(db_path)
    # 初始化 db
    db.init_app(app)
    db.app = app

    @app.template_filter('formatted_time')
    def formatted_time(timestamp):
        t = timestamp
        format = '%Y/%m/%d %H:%M'
        t = time.localtime(timestamp)
        ft = time.strftime(format, t)
        return ft

    # 必须在函数中 import 蓝图
    # 否则循环引用(因为蓝图中 import 了 model, model 引用了这个文件里面目的 db)
    from .api import api as api
    # 注册蓝图
    app.register_blueprint(api)
    # 把 app 引用返回
    return app
def create_app(config):
    app = Flask(__name__)

    app.config['SQLALCHEMY_DATABASE_URI'] = get_meta_db_config_path(config)
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.config['BUNDLE_ERRORS'] = True
    app_config = get_application_config(config)

    for key in app_config:
        app.config[key.upper()] = int(app_config[key]) if key.upper() in INT_OPTIONS else app_config[key]
    app.config['SENTRY_INCLUDE_PATHS'] = [
        'postgraas_server',
    ]
    app.config['SENTRY_RELEASE'] = postgraas_server.__version__
    sentry.init_app(app)

    restful_api = Api(app)
    restful_api.add_resource(DBInstanceResource, "/api/v2/postgraas_instances/<int:id>")
    restful_api.add_resource(DBInstanceCollectionResource, "/api/v2/postgraas_instances")
    db.init_app(app)
    app.postgraas_backend = get_backend(config)

    @app.route('/health')
    def health():
        return "ok"

    return app
def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS']=True
    config[config_name].init_app(app)

    bootstrap.init_app(app)
    mail.init_app(app)
    moment.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)
    pagedown.init_app(app)

    if not app.debug and not app.testing and not app.config['SSL_DISABLE']:
        from flask_sslify import SSLify
        sslify = SSLify(app)

    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)

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

    from .api_1_0 import api as api_1_0_blueprint
    app.register_blueprint(api_1_0_blueprint, url_prefix='/api/v1.0')

    app.sms=SMS_sender(appid=app.config['BMOB_APPID'],appkey=app.config['BMOB_APPKEY'])
    
    return app
Example #16
0
def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    config[config_name].init_app(app)

    # register extensions

    moment.init_app(app)
    mail.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)

    # register blueprints

    from authentication import authentication as authentication_blueprint
    app.register_blueprint(authentication_blueprint)

    from customers import customers as customers_blueprint
    app.register_blueprint(customers_blueprint)

    from main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    from orders import orders as orders_blueprint
    app.register_blueprint(orders_blueprint)

    from resturants import resturants as resturants_blueprint
    app.register_blueprint(resturants_blueprint)

    return app
Example #17
0
 def create_app(self):
     app = Flask(__name__)
     app.config['SQLALCHEMY_DATABASE_URI'] = "sqlite://"
     app.config['TESTING'] = True
     # app.config['SQLALCHEMY_ECHO'] = True
     app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
     db.init_app(app)
     return app
Example #18
0
def create_app():
	app = Flask(__name__)
	app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///stress.db'
	app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
	db.init_app(app)
	with app.app_context():
		db.create_all()
	return app
Example #19
0
def create_test_app(db_file):
  app = Flask(__name__)
  app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + db_file
  app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

  trips_models.db.init_app(app)
  app.app_context().push()

  return app
Example #20
0
def create_app():
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root@localhost/bucketlist'
    app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
    app.config['SECRET'] = "some secret"
    app.config['ECHO'] = True
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
    db.init_app(app)
    db.app = app
    return app
Example #21
0
    def create_app(self):
        tmp_dir = tempfile.mkdtemp()

        app = Flask(__name__)

        app.config['WHOOSH_BASE'] = os.path.join(tmp_dir, 'whoosh')
        # TODO: Use SQLAlchemy event system instead
        app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True

        return app
Example #22
0
def create_flask_app():
  '''Creates a configured flask app.'''
  app = Flask(__name__, template_folder='templates')
  app.debug = True
  app.secret_key = 'secret'
  app.config['DEBUG'] = True
  app.config['SQLALCHEMY_DATABASE_URI'] = _get_db_url()
  app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
  trips_models.db.init_app(app)

  return app
Example #23
0
def create_app():
    app = Flask(__name__)
    app.debug = True
    app.config['SQLALCHEMY_DATABASE_URI'] = config.DB_URI
    app.config['ALLOWED_EXTENSIONS'] = set(['xls'])
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
    app.secret_key = 'songchao'

    bootstrap.init_app(app)
    db.init_app(app)
    return app
Example #24
0
def create_app(config_file=None):
    app = Flask('poff')
    if config_file:
        app.config.from_pyfile(config_file)
    else:
        app.config.from_envvar('POFF_CONFIG_FILE')

    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    db.init_app(app)

    from . import views

    app.register_blueprint(views.mod)

    @app.teardown_appcontext
    def teardown_appcontext(error):
        """ Commits the session if no error has occured, otherwise rollbacks. """
        if error is None:
            try:
                db.session.commit()
            except Exception: # pylint: disable=broad-except
                # Whoopsie! We can't
                db.session.rollback()
                _logger.exception('Exception happened during teardown commit.')
        else:
            # We have an exception, but it has probably already been handled by the modroriate handlers,
            # so just rollback the session and ignore the error
            db.session.rollback()
        db.session.remove()

    @app.errorhandler(500)
    def server_error(error):
        generic_error_handler(error)
        # Don't rely on any special mechanisms such as template loading or other resources,
        # as we don't know where the error is.
        return textwrap.dedent('''\
        <!doctype html>
        <title>Internal Server Error</title>
        <h1>Internal Server Error</h1>
        <p>
            I'm very sorry to report this, but something has gone wrong on the server.
            If you have administrator access, check the logs for more details, otherwise
            you should probably gently notify your sysadmin of the failure.
        ''')

    @app.context_processor
    def default_context():
        return {
            'version': __version__,
        }

    return app
def test_flask_sqlalchemy():
    from flask_sqlalchemy import SQLAlchemy
    from flask import Flask
    from eralchemy.main import all_to_intermediary
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = True
    db = SQLAlchemy(app)
    model = db.Model
    model.metadata = Base.metadata
    tables, relationships = all_to_intermediary(db.Model)
    check_intermediary_representation_simple_all_table(tables, relationships)
Example #26
0
def setup():
    app = Flask(__name__)
    app.config['SECRET_KEY'] = '1'
    app.config['CSRF_ENABLED'] = False
    app.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://localhost/flask_admin_test'
    app.config['SQLALCHEMY_ECHO'] = True
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    db = SQLAlchemy(app)
    admin = Admin(app)

    return app, db, admin
Example #27
0
def create_app(config_path):
    app = Flask(__name__)
    config = Config(config_path)
    app.config['SQLALCHEMY_DATABASE_URI'] = config.db_path
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.config['APP_LOGFILE'] = config.log_path
    db.init_app(app)

    initialize_logger(app)

    app.errorhandler(404)(error_handlers.page_not_found)
    return app
Example #28
0
def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    app.config['SQLALCHEMY_COMMIT_ON_TEARDOWN'] = True
    config[config_name].init_app(app)

    db.init_app(app)

    from .api.v1 import api as api_blueprint
    app.register_blueprint(api_blueprint, url_prefix='/api/v1')

    return app
Example #29
0
def create_app(config_name):
    app = Flask(__name__)
    app.config.from_object(config[config_name])
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
    # not using sqlalchemy event system, hence disabling it

    config[config_name].init_app(app)

    # Set up extensions
    mail.init_app(app)
    db.init_app(app)
    login_manager.init_app(app)
    csrf.init_app(app)
    compress.init_app(app)
    RQ(app)

    # Register Jinja template functions
    from .utils import register_template_utils
    register_template_utils(app)

    # Set up asset pipeline
    assets_env = Environment(app)
    dirs = ['assets/styles', 'assets/scripts']
    for path in dirs:
        assets_env.append_path(os.path.join(basedir, path))
    assets_env.url_expire = True

    assets_env.register('app_css', app_css)
    assets_env.register('app_js', app_js)
    assets_env.register('vendor_css', vendor_css)
    assets_env.register('vendor_js', vendor_js)

    # Configure SSL if platform supports it
    if not app.debug and not app.testing and not app.config['SSL_DISABLE']:
        from flask.ext.sslify import SSLify
        SSLify(app)

    # Create app blueprints
    from .main import main as main_blueprint
    app.register_blueprint(main_blueprint)

    from .account import account as account_blueprint
    app.register_blueprint(account_blueprint, url_prefix='/account')

    from .admin import admin as admin_blueprint
    app.register_blueprint(admin_blueprint, url_prefix='/admin')

    from .participant import participant as participant_blueprint
    app.register_blueprint(participant_blueprint, url_prefix='/participant')

    return app
def create_app():
    """Config for the app"""
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = \
        'postgresql://docker:{}@{}:{}/{}'.format(
            os.environ['DATABASE_PASSWORD'],
            os.environ['DATABASE_PORT_5432_TCP_ADDR'],
            os.environ['DATABASE_PORT_5432_TCP_PORT'],
            os.environ['POSTGRES_DB'])
    app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False

    db.init_app(app)

    app.register_blueprint(APP)
    app.register_blueprint(FEEDBACK, url_prefix='/feedback')
    app.register_blueprint(TOURNAMENT, url_prefix='/tournament')
    app.register_blueprint(TOURNAMENT_ROUND,
                           url_prefix='/tournament/<tournament_id>/rounds')
    app.register_blueprint(ENTRY,
                           url_prefix='/tournament/<tournament_id>/entry')
    app.register_blueprint(USER, url_prefix='/user/<username>')

    @app.errorhandler(PermissionDeniedException)
    # pylint: disable=unused-variable
    def permission_denied(err):
        """Permission denied (as opposed to auth failed)"""
        print '{}: {}'.format(type(err).__name__, err)
        return make_response(str(err), 403)

    @app.errorhandler(RuntimeError)
    @app.errorhandler(ValueError)
    @app.errorhandler(TypeError)
    # pylint: disable=unused-variable
    def input_error(err):
        """Input errors"""
        print '{}: {}'.format(type(err).__name__, err)
        import traceback
        traceback.print_exc()
        return make_response(str(err), 400)

    @app.errorhandler(Exception)
    # pylint: disable=unused-variable
    def unknown_error(err):
        """All other exceptions are essentially just raised with logging"""
        print '{}: {}'.format(type(err).__name__, err)
        import traceback
        traceback.print_exc()
        return make_response(str(err), 500)

    return app