1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- def is_ldap_model(model):
-
- return hasattr(model, 'base_dn')
- class Router(object):
- """
- A router to point database operations on LDAP models to the LDAP
- database.
- NOTE: if you have more than one LDAP database, you will need to
- write your own router.
- """
- def __init__(self):
- "Find the name of the LDAP database"
- from django.conf import settings
- self.ldap_alias = None
- for alias, settings_dict in settings.DATABASES.items():
- if settings_dict['ENGINE'] == 'ldapdb.backends.ldap':
- self.ldap_alias = alias
- break
- def allow_syncdb(self, db, model):
- "Do not create tables for LDAP models"
- if is_ldap_model(model):
- return db == self.ldap_alias
- return None
- def db_for_read(self, model, **hints):
- "Point all operations on LDAP models to the LDAP database"
- if is_ldap_model(model):
- return self.ldap_alias
- return None
- def db_for_write(self, model, **hints):
- "Point all operations on LDAP models to the LDAP database"
- if is_ldap_model(model):
- return self.ldap_alias
- return None
|