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


Python connection.settings_dict方法代码示例

本文整理汇总了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) 
开发者ID:noripyt,项目名称:django-cachalot,代码行数:19,代码来源:settings.py

示例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] 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:19,代码来源:test_creation.py

示例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 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:21,代码来源:tests.py

示例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] 
开发者ID:nesdis,项目名称:djongo,代码行数:19,代码来源:test_creation.py

示例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() 
开发者ID:andersroos,项目名称:rankedftw,代码行数:14,代码来源:db.py

示例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) 
开发者ID:bkg,项目名称:django-spillway,代码行数:14,代码来源:carto.py

示例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' 
开发者ID:andela,项目名称:troupon,代码行数:8,代码来源:models.py

示例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) 
开发者ID:andela,项目名称:troupon,代码行数:7,代码来源:test_models.py

示例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 
开发者ID:adamchainz,项目名称:django-mysql,代码行数:16,代码来源:test_handler.py

示例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') 
开发者ID:cc-archive,项目名称:open-ledger,代码行数:33,代码来源:mocker.py

示例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 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:8,代码来源:test_creation.py

示例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) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:10,代码来源:test_creation.py

示例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) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:9,代码来源:test_creation.py

示例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) 
开发者ID:denisenkom,项目名称:django-sqlserver,代码行数:9,代码来源:test_creation.py

示例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 
开发者ID:nesdis,项目名称:djongo,代码行数:14,代码来源:tests.py


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