本文整理汇总了Python中django.db.connection.settings_dict方法的典型用法代码示例。如果您正苦于以下问题:Python connection.settings_dict方法的具体用法?Python connection.settings_dict怎么用?Python connection.settings_dict使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.db.connection
的用法示例。
在下文中一共展示了connection.settings_dict方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_databases
# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import settings_dict [as 别名]
def test_databases(self):
qs = Test.objects.all()
with self.settings(CACHALOT_DATABASES=SUPPORTED_ONLY):
self.assert_query_cached(qs)
invalidate(Test)
engine = connection.settings_dict['ENGINE']
SUPPORTED_DATABASE_ENGINES.remove(engine)
with self.settings(CACHALOT_DATABASES=SUPPORTED_ONLY):
self.assert_query_cached(qs, after=1)
SUPPORTED_DATABASE_ENGINES.add(engine)
with self.settings(CACHALOT_DATABASES=SUPPORTED_ONLY):
self.assert_query_cached(qs)
with self.settings(CACHALOT_DATABASES=[]):
self.assert_query_cached(qs, after=1)
示例2: changed_test_settings
# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import settings_dict [as 别名]
def changed_test_settings(self, **kwargs):
settings = connection.settings_dict['TEST']
saved_values = {}
for name in kwargs:
if name in settings:
saved_values[name] = settings[name]
for name, value in kwargs.items():
settings[name] = value
try:
yield
finally:
for name, value in kwargs.items():
if name in saved_values:
settings[name] = saved_values[name]
else:
del settings[name]
示例3: override_database_connection_timezone
# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import settings_dict [as 别名]
def override_database_connection_timezone(self, timezone):
try:
orig_timezone = connection.settings_dict['TIME_ZONE']
connection.settings_dict['TIME_ZONE'] = timezone
# Clear cached properties, after first accessing them to ensure they exist.
connection.timezone
del connection.timezone
connection.timezone_name
del connection.timezone_name
yield
finally:
connection.settings_dict['TIME_ZONE'] = orig_timezone
# Clear cached properties, after first accessing them to ensure they exist.
connection.timezone
del connection.timezone
connection.timezone_name
del connection.timezone_name
示例4: changed_test_settings
# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import settings_dict [as 别名]
def changed_test_settings(self, **kwargs):
settings = connection.settings_dict['TEST']
saved_values = {}
for name in kwargs:
if name in settings:
saved_values[name] = settings[name]
for name, value in kwargs.items():
settings[name] = value
try:
yield
finally:
for name in kwargs:
if name in saved_values:
settings[name] = saved_values[name]
else:
del settings[name]
示例5: __init__
# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import settings_dict [as 别名]
def __init__(self):
self.db_name = connection.settings_dict['NAME']
print(self.db_name)
self.team = None
self.cache = None
self.player = None
self.season = None
self.ladder = None
self.ranking = None
self.ranking_data = None
self.default_ranking_data__data = {}
self.clear_defaults()
示例6: make_dbsource
# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import settings_dict [as 别名]
def make_dbsource(**kwargs):
"""Returns a mapnik PostGIS or SQLite Datasource."""
if 'spatialite' in connection.settings_dict.get('ENGINE'):
kwargs.setdefault('file', connection.settings_dict['NAME'])
return mapnik.SQLite(wkb_format='spatialite', **kwargs)
names = (('dbname', 'NAME'), ('user', 'USER'),
('password', 'PASSWORD'), ('host', 'HOST'), ('port', 'PORT'))
for mopt, dopt in names:
val = connection.settings_dict.get(dopt)
if val:
kwargs.setdefault(mopt, val)
return mapnik.PostGIS(**kwargs)
示例7: db_type
# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import settings_dict [as 别名]
def db_type(self, connection):
if connection.settings_dict['ENGINE']\
== 'django.db.backends.postgresql_psycopg2':
return 'jsonb'
else:
return 'text'
示例8: run_for_postgres
# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import settings_dict [as 别名]
def run_for_postgres(fn):
def fn_wrap(self, *args, **kwargs):
if connection.settings_dict['ENGINE']\
== 'django.db.backends.postgresql_psycopg2':
return fn(self)
示例9: get_index_names
# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import settings_dict [as 别名]
def get_index_names(model):
# There's no easy way of getting index names in django so pull them from
# INFORMATION_SCHEMA
with connection.cursor() as cursor:
cursor.execute(
"""SELECT DISTINCT INDEX_NAME
FROM INFORMATION_SCHEMA.STATISTICS
WHERE TABLE_SCHEMA = %s AND
TABLE_NAME = %s""",
(connection.settings_dict["NAME"], model._meta.db_table),
)
index_names = [x[0] for x in cursor.fetchall()]
return index_names
示例10: handle
# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import settings_dict [as 别名]
def handle(self, *args, **options):
count = options['record_count']
if count < 50000:
print("Error: minimum of 50,000 mock records required")
exit(1)
if not options['noninteractive']:
print(TColors.WARNING + 'Running this script will result in the following database receiving junk test'
' data:')
print('Database', connection.settings_dict['NAME'], 'on host', connection.settings_dict['HOST'])
print('Are you sure you want to continue?' + TColors.RESET)
_continue = input('y/n\n').lower() == 'y'
if not _continue:
exit(0)
print('Inserting random data\n')
with Manager() as manager:
producer_finished_signal = manager.Value('i', 0)
mock_data_queue = manager.Queue()
mock_data_producer = MockDataProducer(num_results=count,
result_queue=mock_data_queue,
num_workers=4,
num_worker_images=5000,
producer_finished=producer_finished_signal)
db_pusher = DatabasePusher(mock_data_queue=mock_data_queue,
num_images_to_push=count,
producer_finished=producer_finished_signal)
mock_data_producer.start()
db_pusher.start()
db_pusher.join()
print('\nDone')
示例11: get_connection_copy
# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import settings_dict [as 别名]
def get_connection_copy(self):
# Get a copy of the default connection. (Can't use django.db.connection
# because it'll modify the default connection itself.)
test_connection = copy.copy(connections[DEFAULT_DB_ALIAS])
test_connection.settings_dict = copy.copy(connections[DEFAULT_DB_ALIAS].settings_dict)
return test_connection
示例12: test_default_name
# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import settings_dict [as 别名]
def test_default_name(self):
# A test db name isn't set.
prod_name = 'hodor'
test_connection = self.get_connection_copy()
test_connection.settings_dict['NAME'] = prod_name
test_connection.settings_dict['TEST'] = {'NAME': None}
signature = BaseDatabaseCreation(test_connection).test_db_signature()
self.assertEqual(signature[3], TEST_DATABASE_PREFIX + prod_name)
示例13: test_custom_test_name
# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import settings_dict [as 别名]
def test_custom_test_name(self):
# A regular test db name is set.
test_name = 'hodor'
test_connection = self.get_connection_copy()
test_connection.settings_dict['TEST'] = {'NAME': test_name}
signature = BaseDatabaseCreation(test_connection).test_db_signature()
self.assertEqual(signature[3], test_name)
示例14: test_custom_test_name_with_test_prefix
# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import settings_dict [as 别名]
def test_custom_test_name_with_test_prefix(self):
# A test db name prefixed with TEST_DATABASE_PREFIX is set.
test_name = TEST_DATABASE_PREFIX + 'hodor'
test_connection = self.get_connection_copy()
test_connection.settings_dict['TEST'] = {'NAME': test_name}
signature = BaseDatabaseCreation(test_connection).test_db_signature()
self.assertEqual(signature[3], test_name)
示例15: test_password_with_at_sign
# 需要导入模块: from django.db import connection [as 别名]
# 或者: from django.db.connection import settings_dict [as 别名]
def test_password_with_at_sign(self):
old_password = connection.settings_dict['PASSWORD']
connection.settings_dict['PASSWORD'] = 'p@ssword'
try:
self.assertIn('/\\"p@ssword\\"@', connection._connect_string())
with self.assertRaises(DatabaseError) as context:
connection.cursor()
# Database exception: "ORA-01017: invalid username/password" is
# expected.
self.assertIn('ORA-01017', context.exception.args[0].message)
finally:
connection.settings_dict['PASSWORD'] = old_password