Removed legacy handing for `settings.DATABAS_*` and using short-form references to the included database backends.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@15959 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
e57cc90c16
commit
9b3aaae255
|
@ -8,59 +8,9 @@ __all__ = ('backend', 'connection', 'connections', 'router', 'DatabaseError',
|
||||||
'IntegrityError', 'DEFAULT_DB_ALIAS')
|
'IntegrityError', 'DEFAULT_DB_ALIAS')
|
||||||
|
|
||||||
|
|
||||||
# For backwards compatibility - Port any old database settings over to
|
|
||||||
# the new values.
|
|
||||||
if not settings.DATABASES:
|
|
||||||
if settings.DATABASE_ENGINE:
|
|
||||||
import warnings
|
|
||||||
warnings.warn(
|
|
||||||
"settings.DATABASE_* is deprecated; use settings.DATABASES instead.",
|
|
||||||
DeprecationWarning
|
|
||||||
)
|
|
||||||
|
|
||||||
settings.DATABASES[DEFAULT_DB_ALIAS] = {
|
|
||||||
'ENGINE': settings.DATABASE_ENGINE,
|
|
||||||
'HOST': settings.DATABASE_HOST,
|
|
||||||
'NAME': settings.DATABASE_NAME,
|
|
||||||
'OPTIONS': settings.DATABASE_OPTIONS,
|
|
||||||
'PASSWORD': settings.DATABASE_PASSWORD,
|
|
||||||
'PORT': settings.DATABASE_PORT,
|
|
||||||
'USER': settings.DATABASE_USER,
|
|
||||||
'TEST_CHARSET': settings.TEST_DATABASE_CHARSET,
|
|
||||||
'TEST_COLLATION': settings.TEST_DATABASE_COLLATION,
|
|
||||||
'TEST_NAME': settings.TEST_DATABASE_NAME,
|
|
||||||
}
|
|
||||||
|
|
||||||
if DEFAULT_DB_ALIAS not in settings.DATABASES:
|
if DEFAULT_DB_ALIAS not in settings.DATABASES:
|
||||||
raise ImproperlyConfigured("You must define a '%s' database" % DEFAULT_DB_ALIAS)
|
raise ImproperlyConfigured("You must define a '%s' database" % DEFAULT_DB_ALIAS)
|
||||||
|
|
||||||
for alias, database in settings.DATABASES.items():
|
|
||||||
if 'ENGINE' not in database:
|
|
||||||
raise ImproperlyConfigured("You must specify a 'ENGINE' for database '%s'" % alias)
|
|
||||||
if database['ENGINE'] in ("postgresql", "postgresql_psycopg2", "sqlite3", "mysql", "oracle"):
|
|
||||||
import warnings
|
|
||||||
if 'django.contrib.gis' in settings.INSTALLED_APPS:
|
|
||||||
warnings.warn(
|
|
||||||
"django.contrib.gis is now implemented as a full database backend. "
|
|
||||||
"Modify ENGINE in the %s database configuration to select "
|
|
||||||
"a backend from 'django.contrib.gis.db.backends'" % alias,
|
|
||||||
DeprecationWarning
|
|
||||||
)
|
|
||||||
if database['ENGINE'] == 'postgresql_psycopg2':
|
|
||||||
full_engine = 'django.contrib.gis.db.backends.postgis'
|
|
||||||
elif database['ENGINE'] == 'sqlite3':
|
|
||||||
full_engine = 'django.contrib.gis.db.backends.spatialite'
|
|
||||||
else:
|
|
||||||
full_engine = 'django.contrib.gis.db.backends.%s' % database['ENGINE']
|
|
||||||
else:
|
|
||||||
warnings.warn(
|
|
||||||
"Short names for ENGINE in database configurations are deprecated. "
|
|
||||||
"Prepend %s.ENGINE with 'django.db.backends.'" % alias,
|
|
||||||
DeprecationWarning
|
|
||||||
)
|
|
||||||
full_engine = "django.db.backends.%s" % database['ENGINE']
|
|
||||||
database['ENGINE'] = full_engine
|
|
||||||
|
|
||||||
connections = ConnectionHandler(settings.DATABASES)
|
connections = ConnectionHandler(settings.DATABASES)
|
||||||
|
|
||||||
router = ConnectionRouter(settings.DATABASE_ROUTERS)
|
router = ConnectionRouter(settings.DATABASE_ROUTERS)
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
import inspect
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
@ -19,38 +18,29 @@ class IntegrityError(DatabaseError):
|
||||||
|
|
||||||
|
|
||||||
def load_backend(backend_name):
|
def load_backend(backend_name):
|
||||||
|
# Look for a fully qualified database backend name
|
||||||
try:
|
try:
|
||||||
module = import_module('.base', 'django.db.backends.%s' % backend_name)
|
return import_module('.base', backend_name)
|
||||||
import warnings
|
except ImportError, e_user:
|
||||||
warnings.warn(
|
# The database backend wasn't found. Display a helpful error message
|
||||||
"Short names for DATABASE_ENGINE are deprecated; prepend with 'django.db.backends.'",
|
# listing all possible (built-in) database backends.
|
||||||
DeprecationWarning
|
backend_dir = os.path.join(os.path.dirname(__file__), 'backends')
|
||||||
)
|
|
||||||
return module
|
|
||||||
except ImportError, e:
|
|
||||||
# Look for a fully qualified database backend name
|
|
||||||
try:
|
try:
|
||||||
return import_module('.base', backend_name)
|
available_backends = [f for f in os.listdir(backend_dir)
|
||||||
except ImportError, e_user:
|
if os.path.isdir(os.path.join(backend_dir, f))
|
||||||
# The database backend wasn't found. Display a helpful error message
|
and not f.startswith('.')]
|
||||||
# listing all possible (built-in) database backends.
|
except EnvironmentError:
|
||||||
backend_dir = os.path.join(os.path.dirname(__file__), 'backends')
|
available_backends = []
|
||||||
try:
|
if backend_name.startswith('django.db.backends.'):
|
||||||
available_backends = [f for f in os.listdir(backend_dir)
|
backend_name = backend_name[19:] # See #15621.
|
||||||
if os.path.isdir(os.path.join(backend_dir, f))
|
if backend_name not in available_backends:
|
||||||
and not f.startswith('.')]
|
error_msg = ("%r isn't an available database backend. \n" +
|
||||||
except EnvironmentError:
|
"Try using django.db.backends.XXX, where XXX is one of:\n %s\n" +
|
||||||
available_backends = []
|
"Error was: %s") % \
|
||||||
if backend_name.startswith('django.db.backends.'):
|
(backend_name, ", ".join(map(repr, sorted(available_backends))), e_user)
|
||||||
backend_name = backend_name[19:] # See #15621.
|
raise ImproperlyConfigured(error_msg)
|
||||||
if backend_name not in available_backends:
|
else:
|
||||||
error_msg = ("%r isn't an available database backend. \n" +
|
raise # If there's some other error, this must be an error in Django itself.
|
||||||
"Try using django.db.backends.XXX, where XXX is one of:\n %s\n" +
|
|
||||||
"Error was: %s") % \
|
|
||||||
(backend_name, ", ".join(map(repr, sorted(available_backends))), e_user)
|
|
||||||
raise ImproperlyConfigured(error_msg)
|
|
||||||
else:
|
|
||||||
raise # If there's some other error, this must be an error in Django itself.
|
|
||||||
|
|
||||||
|
|
||||||
class ConnectionDoesNotExist(Exception):
|
class ConnectionDoesNotExist(Exception):
|
||||||
|
@ -76,13 +66,11 @@ class ConnectionHandler(object):
|
||||||
if conn['ENGINE'] == 'django.db.backends.' or not conn['ENGINE']:
|
if conn['ENGINE'] == 'django.db.backends.' or not conn['ENGINE']:
|
||||||
conn['ENGINE'] = 'django.db.backends.dummy'
|
conn['ENGINE'] = 'django.db.backends.dummy'
|
||||||
conn.setdefault('OPTIONS', {})
|
conn.setdefault('OPTIONS', {})
|
||||||
conn.setdefault('TEST_CHARSET', None)
|
|
||||||
conn.setdefault('TEST_COLLATION', None)
|
|
||||||
conn.setdefault('TEST_NAME', None)
|
|
||||||
conn.setdefault('TEST_MIRROR', None)
|
|
||||||
conn.setdefault('TIME_ZONE', settings.TIME_ZONE)
|
conn.setdefault('TIME_ZONE', settings.TIME_ZONE)
|
||||||
for setting in ('NAME', 'USER', 'PASSWORD', 'HOST', 'PORT'):
|
for setting in ['NAME', 'USER', 'PASSWORD', 'HOST', 'PORT']:
|
||||||
conn.setdefault(setting, '')
|
conn.setdefault(setting, '')
|
||||||
|
for setting in ['TEST_CHARSET', 'TEST_COLLATION', 'TEST_NAME', 'TEST_MIRROR']:
|
||||||
|
conn.setdefault(setting, None)
|
||||||
|
|
||||||
def __getitem__(self, alias):
|
def __getitem__(self, alias):
|
||||||
if alias in self._connections:
|
if alias in self._connections:
|
||||||
|
|
Loading…
Reference in New Issue