only use legacy db parameters if available
[matthijs/upstream/django-ldapdb.git] / ldapdb / __init__.py
index 521188cea9a0abe183e1b4bb7e547985c86ea701..4d6f8cf8a8a98eb20d4ab3e9cb910b13e68e54ff 100644 (file)
@@ -45,14 +45,16 @@ def escape_ldap_filter(value):
                 .replace(')', '\\29') \
                 .replace('\0', '\\00')
 
-# Add the LDAP backend
-settings.DATABASES['ldap'] = {
-    'ENGINE': 'ldapdb.backends.ldap',
-    'NAME': settings.LDAPDB_SERVER_URI,
-    'USER': settings.LDAPDB_BIND_DN,
-    'PASSWORD': settings.LDAPDB_BIND_PASSWORD,
-    'SUPPORTS_TRANSACTIONS': False}
-connection = db.connections['ldap']
+# Legacy single database support
+if hasattr(settings, 'LDAPDB_SERVER_URI'):
+    # Add the LDAP backend
+    settings.DATABASES['ldap'] = {
+        'ENGINE': 'ldapdb.backends.ldap',
+        'NAME': settings.LDAPDB_SERVER_URI,
+        'USER': settings.LDAPDB_BIND_DN,
+        'PASSWORD': settings.LDAPDB_BIND_PASSWORD,
+        'SUPPORTS_TRANSACTIONS': False}
+    connection = db.connections['ldap']
 
-# Add the LDAP router
-db.router.routers.append(Router())
+    # Add the LDAP router
+    db.router.routers.append(Router())