# -*- 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.
#
from django.conf import settings
-from ldapdb.backends.ldap.base import DatabaseWrapper
def escape_ldap_filter(value):
value = unicode(value)
.replace(')', '\\29') \
.replace('\0', '\\00')
-# FIXME: is this the right place to initialize the LDAP connection?
-connection = DatabaseWrapper({
- 'NAME': settings.LDAPDB_SERVER_URI,
- 'USER': settings.LDAPDB_BIND_DN,
- 'PASSWORD': settings.LDAPDB_BIND_PASSWORD}, '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())