示例#1
0
def app(app_before_init_db):
    """Create the Flask app with an intialized database."""
    app, conf_obj = app_before_init_db
    cache.clear()

    if conf_obj.database.engine == "PostgresqlDatabase":
        db.execute_sql("DROP SCHEMA public CASCADE;")
        db.execute_sql("CREATE SCHEMA public;")
        db.execute_sql("GRANT ALL ON SCHEMA public TO public;")

    db.create_tables(BaseModel.__subclasses__())
    add_config_to_site_metadata(conf_obj)

    yield app

    if conf_obj.auth.provider != "LOCAL":
        for user in User.select():
            try:
                auth_provider.actually_delete_user(user)
            except Exception as err:
                print(f"Error trying to clean up {user.name} in Keycloak realm:", err)
                raise err

    if conf_obj.database.engine == "Sqlitedatabase":
        db.detach(conf_obj.database.name)
示例#2
0
def create_app(*config_cls) -> Flask:
    print('[INFO] Flask application initialized with {}'.format(
        [config.__name__ for config in config_cls]))

    app_ = Flask(__name__)

    for config in config_cls:
        app_.config.from_object(config)

    JWTManager().init_app(app_)
    Router().init_app(app_)

    from app.models import db, user, tweet
    db.create_tables([user.UserModel, user.FollowModel, tweet.TweetModel])

    return app_
示例#3
0
def app(test_config):
    """Create the Flask app."""
    db_fd, db_name = tempfile.mkstemp()

    config_filename = os.environ.get('TEST_CONFIG', None)

    # Start with the defaults in config.py.
    config = Config(config_filename=config_filename,
                    use_environment=False)

    # Set some things that make sense for testing.
    # TODO set Redis database number to different than dev-server
    config['app']['testing'] = True
    config['app']['debug'] = False
    config['app']['development'] = False
    config['cache']['type'] = 'simple'
    config['database']['engine'] = 'SqliteDatabase'
    config['database']['name'] = db_name
    config['app']['languages'] = ['en']
    config['mail']['server'] = 'smtp.example.com'
    config['mail']['port'] = 8025
    config['mail']['default_from'] = '*****@*****.**'
    config['ratelimit']['enabled'] = False

    recursively_update(config, test_config)

    app = create_app(config)
    app_context = app.app_context()
    app_context.push()
    db.create_tables(BaseModel.__subclasses__())

    yield app

    if config.auth.provider != 'LOCAL':
        for user in User.select():
            try:
                auth_provider.actually_delete_user(user)
            except Exception as err:
                print(f'Error trying to clean up {user.name} in Keycloak realm:', err)
                raise err


    app_context.pop()
    os.close(db_fd)
    os.unlink(db_name)
示例#4
0
def app(test_config):
    """Create the Flask app."""
    db_fd, db_name = tempfile.mkstemp()

    config_filename = os.environ.get("TEST_CONFIG", None)

    # Start with the defaults in config.py.
    config = Config(config_filename=config_filename, use_environment=False)

    # Set some things that make sense for testing.
    # TODO set Redis database number to different than dev-server
    config["app"]["testing"] = True
    config["app"]["debug"] = False
    config["app"]["development"] = False
    config["cache"]["type"] = "simple"
    config["database"]["engine"] = "SqliteDatabase"
    config["database"]["name"] = db_name
    config["app"]["languages"] = ["en"]
    config["mail"]["server"] = "smtp.example.com"
    config["mail"]["port"] = 8025
    config["mail"]["default_from"] = "*****@*****.**"
    config["ratelimit"]["enabled"] = False
    recursively_update(config, test_config)

    conf_obj = Config(config_dict=config)
    app = create_app(conf_obj)
    app_context = app.app_context()
    app_context.push()
    db.create_tables(BaseModel.__subclasses__())

    yield app

    if config.auth.provider != "LOCAL":
        for user in User.select():
            try:
                auth_provider.actually_delete_user(user)
            except Exception as err:
                print(f"Error trying to clean up {user.name} in Keycloak realm:", err)
                raise err

    app_context.pop()
    os.close(db_fd)
    os.unlink(db_name)
示例#5
0
def create_table():
    db.connect()
    db.create_tables([User, Secret, SubSecret, ResetPassword])
    db.close()
示例#6
0
    n_c_contact_10 = FloatField(default=0.0)
    n_yys_report_404 = IntegerField(default=0)
    n_tongdun_125 = IntegerField(default=0)
    n_high_ind3 = IntegerField(default=0)
    n_yys_report_793 = IntegerField(default=0)
    n_c_tongdun_18 = FloatField(default=0.0)
    n_call_record_452 = IntegerField(default=0)
    n_monthly_income_ind = IntegerField(default=0)
    n_tongdun_85 = IntegerField(default=0)
    n_tongdun_152 = IntegerField(default=0)


if __name__ == '__main__':
    from app.models import db

    db.create_tables([ScorecardLargeModel], safe=True)
    vals = {
        'biz_flow_number': '201802281823441093387',
        'mobile': 1000013,
        'active_time': '2018-02-28 18:23:44',

        'call_record_2': None,
        'call_record_452': None,
        'contact_10': 7,
        'gender': 0,
        'hj_1y_xfnl_5': 4,
        'id_card_number': 1000012,
        'jd_market_persona_3': None,
        'jd_shop_persona_9': None,
        'monthly_income': '>=6,000',
        'phone_number_province': '山西',
示例#7
0
def data_init():
    """数据初始化"""
    db.create_tables(models)
    if Admin.select().count() == 0:
        Admin.new('admin', 'zhuzhuangqi')
    return 'Success'