Commits

Peter Sanchez committed 3fdf0aa

Adding greater Django 1.5 custom user support.

Comments (0)

Files changed (5)

impersonate/decorators.py

 from django.shortcuts import redirect
 from django.utils.http import urlquote
 from django.contrib.auth import REDIRECT_FIELD_NAME
-from impersonate.helpers import get_redir_path, check_allow_impersonate
+from .helpers import get_redir_path, check_allow_impersonate
 
 
 def allowed_user_required(view_func):

impersonate/helpers.py

 import re
 from django.conf import settings
-from django.contrib.auth.models import User
 from django.utils.safestring import mark_safe
 from django.core.paginator import Paginator, EmptyPage
 
+try:
+    # Django 1.5 check
+    from django.contrib.auth import get_user_model
+except ImportError:
+    from django.contrib.auth.models import User
+else:
+    User = get_user_model()
+
 
 def get_redir_path(request=None):
     next = None

impersonate/middleware.py

 from django.conf import settings
-from impersonate.helpers import check_allow_for_user, check_allow_for_uri
+from .helpers import check_allow_for_user, check_allow_for_uri
 
 
 class ImpersonateMiddleware(object):

impersonate/urls.py

-from django.conf.urls.defaults import *
+from django.conf.urls.defaults import patterns, url
 
 
 urlpatterns = patterns('impersonate.views',

impersonate/views.py

 from django.db.models import Q
 from django.conf import settings
 from django.template import RequestContext
-from django.contrib.auth.models import User
-from decorators import allowed_user_required
 from django.shortcuts import get_object_or_404, redirect, render
-from impersonate.helpers import (
+from .decorators import allowed_user_required
+from .helpers import (
     get_redir_path, get_redir_arg, get_paginator, get_redir_field,
     check_allow_for_user, users_impersonable
 )
 
+try:
+    # Django 1.5 check
+    from django.contrib.auth import get_user_model
+except ImportError:
+    from django.contrib.auth.models import User
+else:
+    User = get_user_model()
+
 
 @allowed_user_required
 def impersonate(request, uid):