本文整理汇总了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)
示例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
}
示例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)
示例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")
示例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)
示例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)
示例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)
示例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)
示例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, {})