rename LdapConnection to DatabaseWrapper and accept configuration as a dict
authorjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Mon, 11 Apr 2011 05:56:05 +0000 (05:56 +0000)
committerjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Mon, 11 Apr 2011 05:56:05 +0000 (05:56 +0000)
git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@1010 e071eeec-0327-468d-9b6a-08194a12b294

ldapdb/__init__.py

index fc9e0ff8c2bcdaf8026166c92c85713816d8ffb2..7fec75dc41c733a6cebdddff51656ce4563c2700 100644 (file)
@@ -57,19 +57,23 @@ class DatabaseOperations(BaseDatabaseOperations):
     def quote_name(self, name):
         return name
 
-class LdapConnection(object):
-    def __init__(self):
+class DatabaseWrapper(object):
+    def __init__(self, settings_dict={}, alias='ldap'):
+        self.settings_dict = settings_dict
         self.connection = None
         self.charset = "utf-8"
         self.features = DatabaseFeatures(self)
         self.ops = DatabaseOperations()
 
+    def close(self):
+        pass
+
     def _cursor(self):
         if self.connection is None:
-            self.connection = ldap.initialize(settings.LDAPDB_SERVER_URI)
+            self.connection = ldap.initialize(self.settings_dict['NAME'])
             self.connection.simple_bind_s(
-                settings.LDAPDB_BIND_DN,
-                settings.LDAPDB_BIND_PASSWORD)
+                self.settings_dict['USER'],
+                self.settings_dict['PASSWORD'])
         return DatabaseCursor(self.connection)
 
     def add_s(self, dn, modlist):
@@ -97,5 +101,8 @@ class LdapConnection(object):
         return output
 
 # FIXME: is this the right place to initialize the LDAP connection?
-connection = LdapConnection()
+connection = DatabaseWrapper({
+    'NAME': settings.LDAPDB_SERVER_URI,
+    'USER': settings.LDAPDB_BIND_DN,
+    'PASSWORD': settings.LDAPDB_BIND_PASSWORD})