当前位置: 首页>>代码示例>>Python>>正文


Python connection_created.connect方法代码示例

本文整理汇总了Python中django.db.backends.signals.connection_created.connect方法的典型用法代码示例。如果您正苦于以下问题:Python connection_created.connect方法的具体用法?Python connection_created.connect怎么用?Python connection_created.connect使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django.db.backends.signals.connection_created的用法示例。


在下文中一共展示了connection_created.connect方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ready

# 需要导入模块: from django.db.backends.signals import connection_created [as 别名]
# 或者: from django.db.backends.signals.connection_created import connect [as 别名]
def ready(self):
        # Connections may already exist before we are called.
        for conn in connections.all():
            if conn.vendor == 'postgresql':
                conn.introspection.data_types_reverse.update({
                    3802: 'django.contrib.postgresql.fields.JSONField',
                    3904: 'django.contrib.postgresql.fields.IntegerRangeField',
                    3906: 'django.contrib.postgresql.fields.FloatRangeField',
                    3910: 'django.contrib.postgresql.fields.DateTimeRangeField',
                    3912: 'django.contrib.postgresql.fields.DateRangeField',
                    3926: 'django.contrib.postgresql.fields.BigIntegerRangeField',
                })
                if conn.connection is not None:
                    register_type_handlers(conn)
        connection_created.connect(register_type_handlers)
        CharField.register_lookup(Unaccent)
        TextField.register_lookup(Unaccent)
        CharField.register_lookup(SearchLookup)
        TextField.register_lookup(SearchLookup)
        CharField.register_lookup(TrigramSimilar)
        TextField.register_lookup(TrigramSimilar) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:23,代码来源:apps.py

示例2: config

# 需要导入模块: from django.db.backends.signals import connection_created [as 别名]
# 或者: from django.db.backends.signals.connection_created import connect [as 别名]
def config():
    service_name = os.getenv('DATABASE_SERVICE_NAME', '').upper().replace('-', '_')
    if service_name:
        engine = engines.get(os.getenv('DATABASE_ENGINE'), engines['sqlite'])
    else:
        engine = engines['sqlite']
    name = os.getenv('DATABASE_NAME')
    if not name and engine == engines['sqlite']:
        name = os.path.join(settings.BASE_DIR, 'db.sqlite3')

    if bool(os.getenv('FIX_BROKEN_SQLITE', 'False').lower() in ['true', 1]):
        connection_created.connect(activate_legacy_table_fix)

    return {
            'ENGINE': engine,
            'NAME': name,
            'USER': os.getenv('DATABASE_USER'),
            'PASSWORD': os.getenv('DATABASE_PASSWORD'),
            'HOST': os.getenv('{}_SERVICE_HOST'.format(service_name)),
            'PORT': os.getenv('{}_SERVICE_PORT'.format(service_name)),
            'ATOMIC_REQUESTS': True
        } 
开发者ID:bcgov,项目名称:tfrs,代码行数:24,代码来源:database.py

示例3: ready

# 需要导入模块: from django.db.backends.signals import connection_created [as 别名]
# 或者: from django.db.backends.signals.connection_created import connect [as 别名]
def ready(self):
        # Connections may already exist before we are called.
        for conn in connections.all():
            if conn.vendor == 'postgresql':
                conn.introspection.data_types_reverse.update({
                    3802: 'django.contrib.postgres.fields.JSONField',
                    3904: 'django.contrib.postgres.fields.IntegerRangeField',
                    3906: 'django.contrib.postgres.fields.FloatRangeField',
                    3910: 'django.contrib.postgres.fields.DateTimeRangeField',
                    3912: 'django.contrib.postgres.fields.DateRangeField',
                    3926: 'django.contrib.postgres.fields.BigIntegerRangeField',
                })
                if conn.connection is not None:
                    register_type_handlers(conn)
        connection_created.connect(register_type_handlers)
        CharField.register_lookup(Unaccent)
        TextField.register_lookup(Unaccent)
        CharField.register_lookup(SearchLookup)
        TextField.register_lookup(SearchLookup)
        CharField.register_lookup(TrigramSimilar)
        TextField.register_lookup(TrigramSimilar) 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:23,代码来源:apps.py

示例4: ensure_sql_instrumented

# 需要导入模块: from django.db.backends.signals import connection_created [as 别名]
# 或者: from django.db.backends.signals.connection_created import connect [as 别名]
def ensure_sql_instrumented():
    global sql_instrumented
    if sql_instrumented:
        return
    sql_instrumented = True

    if django.VERSION >= (2, 0):
        for connection in connections.all():
            install_db_execute_hook(connection=connection)
        connection_created.connect(install_db_execute_hook)
        logger.debug("Installed DB connection created signal handler")
    else:

        CursorWrapper.execute = execute_wrapper(CursorWrapper.execute)
        CursorWrapper.executemany = executemany_wrapper(CursorWrapper.executemany)

        logger.debug("Monkey patched SQL") 
开发者ID:scoutapp,项目名称:scout_apm_python,代码行数:19,代码来源:sql.py

示例5: test_nodb_connection

# 需要导入模块: from django.db.backends.signals import connection_created [as 别名]
# 或者: from django.db.backends.signals.connection_created import connect [as 别名]
def test_nodb_connection(self):
        """
        The _nodb_connection property fallbacks to the default connection
        database when access to the 'postgres' database is not granted.
        """
        def mocked_connect(self):
            if self.settings_dict['NAME'] is None:
                raise DatabaseError()
            return ''

        nodb_conn = connection._nodb_connection
        self.assertIsNone(nodb_conn.settings_dict['NAME'])

        # Now assume the 'postgres' db isn't available
        with warnings.catch_warnings(record=True) as w:
            with mock.patch('django.db.backends.base.base.BaseDatabaseWrapper.connect',
                            side_effect=mocked_connect, autospec=True):
                warnings.simplefilter('always', RuntimeWarning)
                nodb_conn = connection._nodb_connection
        self.assertIsNotNone(nodb_conn.settings_dict['NAME'])
        self.assertEqual(nodb_conn.settings_dict['NAME'], connection.settings_dict['NAME'])
        # Check a RuntimeWarning has been emitted
        self.assertEqual(len(w), 1)
        self.assertEqual(w[0].message.__class__, RuntimeWarning) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:26,代码来源:tests.py

示例6: ready

# 需要导入模块: from django.db.backends.signals import connection_created [as 别名]
# 或者: from django.db.backends.signals.connection_created import connect [as 别名]
def ready(self):
        connection_created.connect(register_hstore_handler)
        CharField.register_lookup(Unaccent)
        TextField.register_lookup(Unaccent) 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:6,代码来源:apps.py

示例7: add_database_instrumentation

# 需要导入模块: from django.db.backends.signals import connection_created [as 别名]
# 或者: from django.db.backends.signals.connection_created import connect [as 别名]
def add_database_instrumentation(self):
        if not getattr(
            settings, "DJANGO_MYSQL_REWRITE_QUERIES", False
        ):  # pragma: no cover
            return
        for _alias, connection in mysql_connections():
            install_rewrite_hook(connection)
        connection_created.connect(install_rewrite_hook) 
开发者ID:adamchainz,项目名称:django-mysql,代码行数:10,代码来源:apps.py

示例8: ready

# 需要导入模块: from django.db.backends.signals import connection_created [as 别名]
# 或者: from django.db.backends.signals.connection_created import connect [as 别名]
def ready(self):
        # Connections may already exist before we are called.
        for conn in connections.all():
            if conn.connection is not None:
                register_type_handlers(conn)
        connection_created.connect(register_type_handlers)
        CharField.register_lookup(Unaccent)
        TextField.register_lookup(Unaccent)
        CharField.register_lookup(SearchLookup)
        TextField.register_lookup(SearchLookup)
        CharField.register_lookup(TrigramSimilar)
        TextField.register_lookup(TrigramSimilar) 
开发者ID:bpgc-cte,项目名称:python2017,代码行数:14,代码来源:apps.py

示例9: test_signal

# 需要导入模块: from django.db.backends.signals import connection_created [as 别名]
# 或者: from django.db.backends.signals.connection_created import connect [as 别名]
def test_signal(self):
        data = {}

        def receiver(sender, connection, **kwargs):
            data["connection"] = connection

        connection_created.connect(receiver)
        connection.close()
        connection.cursor()
        self.assertIs(data["connection"].connection, connection.connection)

        connection_created.disconnect(receiver)
        data.clear()
        connection.cursor()
        self.assertEqual(data, {}) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:17,代码来源:tests.py


注:本文中的django.db.backends.signals.connection_created.connect方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。