update copyright notice
[matthijs/upstream/django-ldapdb.git] / ldapdb / __init__.py
index 7dde301da3532915ec9e0a099a8b881026038f6c..44d4974e9148d9c5ba9738be42531ef361c854ad 100644 (file)
@@ -1,7 +1,7 @@
 # -*- coding: utf-8 -*-
 # 
 # django-ldapdb
-# Copyright (c) 2009-2010, BollorĂ© telecom
+# Copyright (c) 2009-2011, BollorĂ© telecom
 # All rights reserved.
 # 
 # See AUTHORS file for a full list of contributors.
@@ -33,7 +33,6 @@
 #
 
 from django.conf import settings
-from django.db import connections
 
 def escape_ldap_filter(value):
     value = unicode(value)
@@ -43,11 +42,17 @@ def escape_ldap_filter(value):
                 .replace(')', '\\29') \
                 .replace('\0', '\\00')
 
-# Add the LDAP backend to the configured databases
-settings.DATABASES['ldap'] = {
-    'ENGINE': 'ldapdb.backends.ldap',
-    'NAME': settings.LDAPDB_SERVER_URI,
-    'USER': settings.LDAPDB_BIND_DN,
-    'PASSWORD': settings.LDAPDB_BIND_PASSWORD}
-connection = connections['ldap']
+# Legacy single database support
+if hasattr(settings, 'LDAPDB_SERVER_URI'):
+    from django import db
+    from ldapdb.router import Router
 
+    # 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}
+
+    # Add the LDAP router
+    db.router.routers.append(Router())