Peter Sagerson committed e08bcac Merge

Merge from usermodel.

  • Participants
  • Parent commits e092116, a3adaab

Comments (0)

Files changed (3)

File django_auth_ldap/

 import pprint
 import copy
-import django.db
 from django.contrib.auth.models import User, Group, Permission, SiteProfileNotAvailable
 from django.core.cache import cache
 from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
     from django.contrib.auth import get_user_model
     get_user_username = lambda u: u.get_username()
 except ImportError:
-    get_user_model = lambda: User
+    get_user_model = lambda: User                                        # noqa
     get_user_username = lambda u: u.username
         return self._ldap
     ldap = property(_get_ldap)
+    def get_user_model(self):
+        """
+        By default, this will return the model class configured by
+        AUTH_USER_MODEL. Subclasses may wish to override it and return a proxy
+        model.
+        """
+        return get_user_model()
     # The Django auth backend API
         user = None
-            user = get_user_model().objects.get(pk=user_id)
+            user = self.get_user_model().objects.get(pk=user_id)
             _LDAPUser(self, user=user) # This sets user.ldap_user
         except ObjectDoesNotExist:
         username is the Django-friendly username of the user. ldap_user.dn is
         the user's DN and ldap_user.attrs contains all of their LDAP attributes.
-        model = get_user_model()
+        model = self.get_user_model()
         username_field = getattr(model, 'USERNAME_FIELD', 'username')
         kwargs = {

File docs/source/reference.rst

         the indicated Django user as if they had just logged in.
         :setting:`AUTH_LDAP_ALWAYS_UPDATE_USER` is ignored (assumed ``True``).
+    .. method:: get_user_model(self)
+        Returns the user model that
+        :meth:`~django_auth_ldap.backend.LDAPBackend.get_or_create_user` will
+        instantiate. In Django 1.5, custom user models will be respected; in
+        earlier versions, the model defaults to
+        :class:`django.contrib.auth.models.User`. Subclasses would most likely
+        override this in order to substitute a :ref:`proxy model
+        <proxy-models>`.
     .. method:: get_or_create_user(self, username, ldap_user)
         Given a username and an LDAP user object, this must return a valid
         The default implementation calls ``<model>.objects.get_or_create()``,
         using a case-insensitive query and creating new users with lowercase
-        usernames. In Django 1.5, custom user models will be respected; in
-        earlier versions, the model is always
-        :class:`django.contrib.auth.models.User`. Subclasses are welcome to
-        associate LDAP users to Django users any way they like.
+        usernames. The user model is obtained from
+        :meth:`~django_auth_ldap.backend.LDAPBackend.get_user_model`. A subclass
+        may override this to associate LDAP users to Django users any way it
+        likes.
     .. method:: ldap_to_django_username(username)

File docs/source/users.rst

 case-insensitive, the default implementation also searches for existing Django
 users with an iexact query and new users are created with lowercase usernames.
 See :meth:`~django_auth_ldap.backend.LDAPBackend.get_or_create_user` if you'd
-like to override this behavior.
+like to override this behavior. See
+:meth:`~django_auth_ldap.backend.LDAPBackend.get_user_model` if you'd like to
+substitute a proxy model.
 .. note::