Ticket #5454: user_backend_r6186.patch

File user_backend_r6186.patch, 3.1 KB (added by George Vilches <gav@…>, 17 years ago)

Adds support for specifying a user backend against r6186.

  • django/db/__init__.py

     
    88    settings.DATABASE_ENGINE = 'dummy'
    99
    1010try:
    11     backend = __import__('django.db.backends.%s.base' % settings.DATABASE_ENGINE, {}, {}, [''])
     11    import_path = 'django.db.backends.'
     12    backend = __import__('%s%s.base' % (import_path, settings.DATABASE_ENGINE), {}, {}, [''])
    1213except ImportError, e:
    13     # The database backend wasn't found. Display a helpful error message
    14     # listing all possible database backends.
    15     from django.core.exceptions import ImproperlyConfigured
    16     import os
    17     backend_dir = os.path.join(__path__[0], 'backends')
    18     available_backends = [f for f in os.listdir(backend_dir) if not f.startswith('_') and not f.startswith('.') and not f.endswith('.py') and not f.endswith('.pyc')]
    19     available_backends.sort()
    20     if settings.DATABASE_ENGINE not in available_backends:
    21         raise ImproperlyConfigured, "%r isn't an available database backend. Available options are: %s" % \
    22             (settings.DATABASE_ENGINE, ", ".join(map(repr, available_backends)))
    23     else:
    24         raise # If there's some other error, this must be an error in Django itself.
     14    try:
     15        import_path = ''
     16        backend = __import__('%s%s.base' % (import_path, settings.DATABASE_ENGINE), {}, {}, [''])
     17    except ImportError, e_user:
     18        # The database backend wasn't found. Display a helpful error message
     19        # listing all possible database backends.
     20        from django.core.exceptions import ImproperlyConfigured
     21        import os
     22        backend_dir = os.path.join(__path__[0], 'backends')
     23        available_backends = [f for f in os.listdir(backend_dir) if not f.startswith('_') and not f.startswith('.') and not f.endswith('.py') and not f.endswith('.pyc')]
     24        available_backends.sort()
     25        if settings.DATABASE_ENGINE not in available_backends:
     26            raise ImproperlyConfigured, "%r isn't an available database backend. Available options are: %s" % \
     27                (settings.DATABASE_ENGINE, ", ".join(map(repr, available_backends)))
     28        else:
     29            raise # If there's some other error, this must be an error in Django itself.
    2530
    26 get_introspection_module = lambda: __import__('django.db.backends.%s.introspection' % settings.DATABASE_ENGINE, {}, {}, [''])
    27 get_creation_module = lambda: __import__('django.db.backends.%s.creation' % settings.DATABASE_ENGINE, {}, {}, [''])
    28 runshell = lambda: __import__('django.db.backends.%s.client' % settings.DATABASE_ENGINE, {}, {}, ['']).runshell()
     31get_introspection_module = lambda: __import__('%s%s.introspection' % (import_path, settings.DATABASE_ENGINE), {}, {}, [''])
     32get_creation_module = lambda: __import__('%s%s.creation' % (import_path, settings.DATABASE_ENGINE), {}, {}, [''])
     33runshell = lambda: __import__('%s%s.client' % (import_path, settings.DATABASE_ENGINE), {}, {}, ['']).runshell()
    2934
    3035connection = backend.DatabaseWrapper(**settings.DATABASE_OPTIONS)
    3136DatabaseError = backend.DatabaseError
Back to Top