From f226e94e9993be5bd9191f64a09fa58f687ed0c0 Mon Sep 17 00:00:00 2001 From: jlaine Date: Mon, 11 Apr 2011 05:56:05 +0000 Subject: [PATCH] rename LdapConnection to DatabaseWrapper and accept configuration as a dict git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@1010 e071eeec-0327-468d-9b6a-08194a12b294 --- ldapdb/__init__.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/ldapdb/__init__.py b/ldapdb/__init__.py index fc9e0ff..7fec75d 100644 --- a/ldapdb/__init__.py +++ b/ldapdb/__init__.py @@ -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}) -- 2.30.2