コード例 #1
0
ファイル: __init__.py プロジェクト: 08haozi/uliweb
def after_init_apps(sender):
    from uliweb import orm
    from uliweb.utils.common import import_attr
    from uliweb.core.SimpleFrame import __app_alias__
    
    orm.set_debug_query(settings.get_var('ORM/DEBUG_LOG'))
    orm.set_auto_create(settings.get_var('ORM/AUTO_CREATE'))
    orm.set_pk_type(settings.get_var('ORM/PK_TYPE'))
    orm.set_auto_set_model(False)
    orm.set_lazy_model_init(True)
    orm.set_check_max_length(settings.get_var('ORM/CHECK_MAX_LENGTH'))
    orm.set_nullable(settings.get_var('ORM/NULLABLE'))
    orm.set_server_default(settings.get_var('ORM/SERVER_DEFAULT'))
    orm.set_manytomany_index_reverse(settings.get_var('ORM/MANYTOMANY_INDEX_REVERSE'))
    convert_path = settings.get_var('ORM/TABLENAME_CONVERTER')
    convert = import_attr(convert_path) if convert_path else None
    orm.set_tablename_converter(convert)
    
    #judge if transaction middle has not install then set
    #AUTO_DOTRANSACTION is False
    if 'transaction' in settings.MIDDLEWARES:
        orm.set_auto_dotransaction(False)
    else:
        orm.set_auto_dotransaction(settings.get_var('ORM/AUTO_DOTRANSACTION'))
    
    d = {'connection_string':settings.get_var('ORM/CONNECTION'),
        'connection_type':settings.get_var('ORM/CONNECTION_TYPE'),
        'debug_log':settings.get_var('ORM/DEBUG_LOG'),
        'connection_args':settings.get_var('ORM/CONNECTION_ARGS'),
        'strategy':settings.get_var('ORM/STRATEGY'),
        }
    orm.engine_manager.add('default', d)
    
    for name, d in settings.get_var('ORM/CONNECTIONS').items():
        x = {'connection_string':d.get('CONNECTION', ''),
            'debug_log':d.get('DEBUG_LOG', None),
            'connection_args':d.get('CONNECTION_ARGS', {}),
            'strategy':d.get('STRATEGY', 'threadlocal'),
            'connection_type':d.get('CONNECTION_TYPE', 'long')
        }
        orm.engine_manager.add(name, x)

    if 'MODELS' in settings:
        for name, model_path in settings.MODELS.items():
            if not model_path: continue
            if isinstance(model_path, (str, unicode)):
                path = model_path
                engine_name = 'default'
            else:
                path, engine_name = model_path
            for k, v in __app_alias__.iteritems():
                if path.startswith(k):
                    path = v + path[len(k):]
                    break
            orm.set_model(path, name, engine_name=engine_name)

    if 'MODELS_CONFIG' in settings:
        for name, v in settings.MODELS_CONFIG.items():
            orm.set_model_config(name, v)
コード例 #2
0
ファイル: __init__.py プロジェクト: zhangtianyi1234/uliweb
def after_init_apps(sender):
    from uliweb import orm
    from uliweb.utils.common import import_attr
    from uliweb.core.SimpleFrame import __app_alias__

    orm.set_debug_query(settings.get_var('ORM/DEBUG_LOG'))
    orm.set_auto_create(settings.get_var('ORM/AUTO_CREATE'))
    orm.set_pk_type(settings.get_var('ORM/PK_TYPE'))
    orm.set_auto_set_model(False)
    orm.set_check_max_length(settings.get_var('ORM/CHECK_MAX_LENGTH'))
    convert_path = settings.get_var('ORM/TABLENAME_CONVERTER')
    convert = import_attr(convert_path) if convert_path else None
    orm.set_tablename_converter(convert)

    #judge if transaction middle has not install then set
    #AUTO_DOTRANSACTION is False
    if 'transaction' in settings.MIDDLEWARES:
        orm.set_auto_dotransaction(False)
    else:
        orm.set_auto_dotransaction(settings.get_var('ORM/AUTO_DOTRANSACTION'))

    d = {
        'connection_string': settings.get_var('ORM/CONNECTION'),
        'connection_type': settings.get_var('ORM/CONNECTION_TYPE'),
        'debug_log': settings.get_var('ORM/DEBUG_LOG'),
        'connection_args': settings.get_var('ORM/CONNECTION_ARGS'),
        'strategy': settings.get_var('ORM/STRATEGY'),
    }
    orm.engine_manager.add('default', d)

    for name, d in settings.get_var('ORM/CONNECTIONS').items():
        x = {
            'connection_string': d.get('CONNECTION', ''),
            'debug_log': d.get('DEBUG_LOG', None),
            'connection_args': d.get('CONNECTION_ARGS', {}),
            'strategy': d.get('STRATEGY', 'threadlocal'),
            'connection_type': d.get('CONNECTION_TYPE', 'long')
        }
        orm.engine_manager.add(name, x)

    if 'MODELS' in settings:
        for name, model_path in settings.MODELS.items():
            if isinstance(model_path, (str, unicode)):
                path = model_path
                engine_name = 'default'
            else:
                path, engine_name = model_path
            for k, v in __app_alias__.iteritems():
                if path.startswith(k):
                    path = v + path[len(k):]
                    break
            orm.set_model(path, name, engine_name=engine_name)
コード例 #3
0
ファイル: __init__.py プロジェクト: victorlv/uliweb
def after_init_apps(sender):
    from uliweb import orm
    from uliweb.core.SimpleFrame import __app_alias__
    
    orm.set_debug_query(uliweb.settings.ORM.DEBUG_LOG)
    orm.set_auto_create(uliweb.settings.ORM.AUTO_CREATE)
    orm.get_connection(uliweb.settings.ORM.CONNECTION, **uliweb.settings.ORM.CONNECTION_ARGS)

    if 'MODELS' in uliweb.settings:
        for name, path in uliweb.settings.MODELS.items():
            for k, v in __app_alias__.iteritems():
                if path.startswith(k):
                    path = v + path[len(k):]
                    break
            orm.set_model(path, name)
コード例 #4
0
ファイル: __init__.py プロジェクト: jamiesun/uliweb
def after_init_apps(sender):
    from uliweb import orm, settings
    from uliweb.core.SimpleFrame import __app_alias__
    
    orm.set_debug_query(uliweb.settings.ORM.DEBUG_LOG)
    orm.set_auto_create(uliweb.settings.ORM.AUTO_CREATE)
    orm.set_pk_type(uliweb.settings.ORM.PK_TYPE)
    orm.set_auto_set_model(False)
    
    #judge if transaction middle has not install then set
    #AUTO_DOTRANSACTION is False
    if 'transaction' in settings.MIDDLEWARES:
        orm.set_auto_dotransaction(False)
    else:
        orm.set_auto_dotransaction(uliweb.settings.ORM.AUTO_DOTRANSACTION)
    
    d = {'connection_string':uliweb.settings.ORM.CONNECTION,
        'connection_type':uliweb.settings.ORM.CONNECTION_TYPE,
        'debug_log':uliweb.settings.ORM.DEBUG_LOG,
        'connection_args':uliweb.settings.ORM.CONNECTION_ARGS,
        'strategy':uliweb.settings.ORM.STRATEGY,
        }
    orm.engine_manager.add('default', d)
    
    for name, d in uliweb.settings.ORM.CONNECTIONS.items():
        x = {'connection_string':d.get('CONNECTION', ''),
            'debug_log':d.get('DEBUG_LOG', None),
            'connection_args':d.get('CONNECTION_ARGS', {}),
            'strategy':d.get('STRATEGY', 'threadlocal'),
            'connection_type':d.get('CONNECTION_TYPE', 'long')
        }
        orm.engine_manager.add(name, x)

    if 'MODELS' in uliweb.settings:
        for name, model_path in uliweb.settings.MODELS.items():
            if isinstance(model_path, (str, unicode)):
                path = model_path
                engine_name = 'default'
            else:
                path, engine_name = model_path
            for k, v in __app_alias__.iteritems():
                if path.startswith(k):
                    path = v + path[len(k):]
                    break
            orm.set_model(path, name, engine_name=engine_name)
コード例 #5
0
ファイル: __init__.py プロジェクト: bobgao/uliweb
def after_init_apps(sender):
    from uliweb import orm, settings
    from uliweb.core.SimpleFrame import __app_alias__
    
    orm.set_debug_query(settings.ORM.DEBUG_LOG)
    orm.set_auto_create(settings.ORM.AUTO_CREATE)
    
    #if AUTO_SAE_ORM_PARA==True, then use sae to get mysql parameters
    if settings.ORM.AUTO_SAE_ORM_PARA:
        import sae.const
        CONNECTION = settings.ORM.CONNECTION.format(username=sae.const.MYSQL_USER,
        password=sae.const.MYSQL_PASS, host=sae.const.MYSQL_HOST, port=sae.const.MYSQL_PORT,
        database=sae.const.MYSQL_DB)
        settings.ORM.CONNECTION = CONNECTION
        
    if 'MODELS' in uliweb.settings:
        for name, path in uliweb.settings.MODELS.items():
            for k, v in __app_alias__.iteritems():
                if path.startswith(k):
                    path = v + path[len(k):]
                    break
            orm.set_model(path, name)
コード例 #6
0
ファイル: __init__.py プロジェクト: anyexxx/uliweb
def after_init_apps(sender):
    from uliweb import orm
    from uliweb.utils.common import import_attr
    from uliweb.core.SimpleFrame import __app_alias__

    orm.set_debug_query(settings.get_var('ORM/DEBUG_LOG'))
    orm.set_auto_create(settings.get_var('ORM/AUTO_CREATE'))
    orm.set_pk_type(settings.get_var('ORM/PK_TYPE'))
    orm.set_auto_set_model(False)
    orm.set_lazy_model_init(True)
    orm.set_check_max_length(settings.get_var('ORM/CHECK_MAX_LENGTH'))
    orm.set_nullable(settings.get_var('ORM/NULLABLE'))
    orm.set_server_default(settings.get_var('ORM/SERVER_DEFAULT'))
    orm.set_manytomany_index_reverse(
        settings.get_var('ORM/MANYTOMANY_INDEX_REVERSE'))
    convert_path = settings.get_var('ORM/TABLENAME_CONVERTER')
    convert = import_attr(convert_path) if convert_path else None
    orm.set_tablename_converter(convert)

    patch_none = settings.get_var('ORM/PATCH_NONE')
    if patch_none:
        from sqlalchemy import __version__

        if tuple(map(int, __version__.split('.')[:2])) >= (0, 9):
            import sqlalchemy.sql.elements as exp
            if patch_none == 'empty':
                exp.and_ = and_empty(exp.and_)
            elif patch_none == 'exception':
                exp.and_ = and_exception(exp.and_)

    #judge if transaction middle has not install then set
    #AUTO_DOTRANSACTION is False
    if 'transaction' in settings.MIDDLEWARES:
        orm.set_auto_transaction_in_web(True)
    else:
        orm.set_auto_transaction_in_web(
            settings.get_var('ORM/AUTO_TRANSACTION_IN_WEB'))
    orm.set_auto_transaction_in_notweb(
        settings.get_var('ORM/AUTO_TRANSACTION_IN_NOTWEB'))

    d = {
        'connection_string': settings.get_var('ORM/CONNECTION'),
        'connection_type': settings.get_var('ORM/CONNECTION_TYPE'),
        'debug_log': settings.get_var('ORM/DEBUG_LOG'),
        'connection_args': settings.get_var('ORM/CONNECTION_ARGS'),
        'strategy': settings.get_var('ORM/STRATEGY'),
    }
    orm.engine_manager.add('default', d)

    for name, d in settings.get_var('ORM/CONNECTIONS').items():
        x = {
            'connection_string': d.get('CONNECTION', ''),
            'debug_log': d.get('DEBUG_LOG', None),
            'connection_args': d.get('CONNECTION_ARGS', {}),
            'strategy': d.get('STRATEGY', 'threadlocal'),
            'connection_type': d.get('CONNECTION_TYPE', 'long'),
            'duplication': d.get('DUPLICATION', False),
        }
        orm.engine_manager.add(name, x)

    if 'MODELS_CONFIG' in settings:
        for name, v in settings.MODELS_CONFIG.items():
            orm.set_model_config(name, v)

    if 'MODELS' in settings:
        for name, model_path in settings.MODELS.items():
            if not model_path: continue
            if isinstance(model_path, (str, unicode)):
                path = model_path
            else:
                raise Exception("Model path should be a string but %r found" %
                                model_path)

            for k, v in __app_alias__.iteritems():
                if path.startswith(k):
                    path = v + path[len(k):]
                    break
            orm.set_model(path, name)
コード例 #7
0
ファイル: __init__.py プロジェクト: chenke91/uliweb
def after_init_apps(sender):
    from uliweb import orm
    from uliweb.utils.common import import_attr
    from uliweb.core.SimpleFrame import __app_alias__
    
    orm.set_debug_query(settings.get_var('ORM/DEBUG_LOG'))
    orm.set_auto_create(settings.get_var('ORM/AUTO_CREATE'))
    orm.set_pk_type(settings.get_var('ORM/PK_TYPE'))
    orm.set_auto_set_model(False)
    orm.set_lazy_model_init(True)
    orm.set_check_max_length(settings.get_var('ORM/CHECK_MAX_LENGTH'))
    orm.set_nullable(settings.get_var('ORM/NULLABLE'))
    orm.set_server_default(settings.get_var('ORM/SERVER_DEFAULT'))
    orm.set_manytomany_index_reverse(settings.get_var('ORM/MANYTOMANY_INDEX_REVERSE'))
    convert_path = settings.get_var('ORM/TABLENAME_CONVERTER')
    convert = import_attr(convert_path) if convert_path else None
    orm.set_tablename_converter(convert)
    
    patch_none = settings.get_var('ORM/PATCH_NONE')
    if patch_none:
        from sqlalchemy import __version__
        
        if tuple(map(int, __version__.split('.')[:2])) >= (0, 9):
            import sqlalchemy.sql.elements as exp
            if patch_none == 'empty':
                exp.and_ = and_empty(exp.and_)
            elif patch_none == 'exception':
                exp.and_ = and_exception(exp.and_)
    
    #judge if transaction middle has not install then set
    #AUTO_DOTRANSACTION is False
    if 'transaction' in settings.MIDDLEWARES:
        orm.set_auto_transaction_in_web(True)
    else:
        orm.set_auto_transaction_in_web(settings.get_var('ORM/AUTO_TRANSACTION_IN_WEB'))
    orm.set_auto_transaction_in_notweb(settings.get_var('ORM/AUTO_TRANSACTION_IN_NOTWEB'))
    
    d = {'connection_string':settings.get_var('ORM/CONNECTION'),
        'connection_type':settings.get_var('ORM/CONNECTION_TYPE'),
        'debug_log':settings.get_var('ORM/DEBUG_LOG'),
        'connection_args':settings.get_var('ORM/CONNECTION_ARGS'),
        'strategy':settings.get_var('ORM/STRATEGY'),
        }
    orm.engine_manager.add('default', d)
    
    for name, d in settings.get_var('ORM/CONNECTIONS').items():
        x = {'connection_string':d.get('CONNECTION', ''),
            'debug_log':d.get('DEBUG_LOG', None),
            'connection_args':d.get('CONNECTION_ARGS', {}),
            'strategy':d.get('STRATEGY', 'threadlocal'),
            'connection_type':d.get('CONNECTION_TYPE', 'long')
        }
        orm.engine_manager.add(name, x)

    if 'MODELS_CONFIG' in settings:
        for name, v in settings.MODELS_CONFIG.items():
            orm.set_model_config(name, v)
    
    if 'MODELS' in settings:
        for name, model_path in settings.MODELS.items():
            if not model_path: continue
            if isinstance(model_path, (str, unicode)):
                path = model_path
            else:
                raise Exception("Model path should be a string but %r found" % model_path)
            
            for k, v in __app_alias__.iteritems():
                if path.startswith(k):
                    path = v + path[len(k):]
                    break
            orm.set_model(path, name)