Commits

Erwin Brinkman  committed a110a98

Adds django 1.5 support (custom user model)

  • Participants
  • Parent commits 1a491d8

Comments (0)

Files changed (4)

File demo/test.py

 #!/usr/bin/env python
 import os
 os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
-from django.contrib.auth.models import User
 from django.core.management import call_command
 from django.conf import settings
+from django.contrib.auth import get_user_model
+
 
 from urlauth.models import AuthKey
 
+
+User = get_user_model()
+
+
 def reproduce():
     try:
         os.unlink(settings.DATABASES['default']['NAME'])

File urlauth/middleware.py

 from django.contrib import auth
-from django.contrib.auth.models import User
 from django.conf import settings
-from django.shortcuts import redirect
+
+try:
+    from django.contrib.auth import get_user_model
+    User = get_user_model()
+except ImportError:
+    from django.contrib.auth.models import User
 
 from urlauth.util import load_key, InvalidKey
 from urlauth.models import AuthKey
 
     def process_request(self, request):
         key = request.REQUEST.get(settings.URLAUTH_AUTHKEY_NAME)
-        
         user = None
         try:
             key = load_key(key)

File urlauth/models.py

 import os
 from binascii import hexlify
-import time
 from datetime import datetime, timedelta
 
+try:
+    from django.contrib.auth import get_user_model
+    User = get_user_model()
+except ImportError:
+    from django.contrib.auth.models import User
+
 from django.db import models
 from django.conf import settings
 from django.utils import simplejson
-from django.contrib.auth.models import User
 from django.db.utils import IntegrityError
 
+
 class URLAuthError(Exception):
     pass
 
+
 class AuthKeyManager(models.Manager):
 
     def create_key(self, **kwargs):

File urlauth/tests.py

 from datetime import datetime, timedelta
-import pickle
 import cgi
 
 from django.test import TestCase
-from django.test.client import Client
 from django.conf.urls.defaults import *
 from django.http import HttpResponse
 from django.conf import settings
-from django.contrib.auth import login, authenticate
-from django.contrib.auth.models import User
-import django.dispatch
+try:
+    from django.contrib.auth import get_user_model
+    User = get_user_model()
+except ImportError:
+    from django.contrib.auth.models import User
 
 from urlauth.util import load_key, InvalidKey
 from urlauth.models import AuthKey
 from urlauth.signals import authkey_processed
 
+
+
+
+
 class UrlauthTestCase(TestCase):
     urls = 'urlauth.tests'
     test_url = '/urlauth_test_view/'