rework router
authorjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Mon, 11 Apr 2011 12:57:03 +0000 (12:57 +0000)
committerjlaine <jlaine@e071eeec-0327-468d-9b6a-08194a12b294>
Mon, 11 Apr 2011 12:57:03 +0000 (12:57 +0000)
git-svn-id: https://svn.bolloretelecom.eu/opensource/django-ldapdb/trunk@1038 e071eeec-0327-468d-9b6a-08194a12b294

ldapdb/router.py

index 38dfdb06b64ab16143da31189665a2bebcde47d8..7e3ff4ace93112d8b7d2c38b27f7d31d99282a5d 100644 (file)
 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
 
 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 #
 
+def is_ldap_model(model):
+    # FIXME: there is probably a better check than testing 'base_dn'
+    return hasattr(model, 'base_dn')
+
 class Router(object):
     """A router to control all database operations on models in
     the myapp application"""
 
     def db_for_read(self, model, **hints):
         "Point all operations on LDAP models to 'ldap'"
 class Router(object):
     """A router to control all database operations on models in
     the myapp application"""
 
     def db_for_read(self, model, **hints):
         "Point all operations on LDAP models to 'ldap'"
-        from ldapdb.models import Model
-        if Model in model.__bases__:
+        if is_ldap_model(model):
             return 'ldap'
         return None
 
     def db_for_write(self, model, **hints):
         "Point all operations on LDAP models to 'ldap'"
             return 'ldap'
         return None
 
     def db_for_write(self, model, **hints):
         "Point all operations on LDAP models to 'ldap'"
-        from ldapdb.models import Model
-        if Model in model.__bases__:
+        if is_ldap_model(model):
             return 'ldap'
         return None
 
             return 'ldap'
         return None