Commits

Bertrand Bordage  committed 39415ef

Replaces every User with get_user_model() or AUTH_USER_MODEL.

  • Participants
  • Parent commits b3c41b3

Comments (0)

Files changed (7)

File registration/backends/simple/views.py

 from django.conf import settings
-from django.contrib.auth import authenticate
-from django.contrib.auth import login
-from django.contrib.auth.models import User
+from django.contrib.auth import authenticate, login, get_user_model
 
 from registration import signals
 from registration.views import RegistrationView as BaseRegistrationView
     
     """
     def register(self, request, **cleaned_data):
+        User = get_user_model()
+
         username, email, password = cleaned_data['username'], cleaned_data['email'], cleaned_data['password1']
         User.objects.create_user(username, email, password)
 

File registration/forms.py

 """
 
 
-from django.contrib.auth.models import User
+from django.contrib.auth import get_user_model
 from django import forms
 from django.utils.translation import ugettext_lazy as _
 
         in use.
         
         """
+        User = get_user_model()
         existing = User.objects.filter(username__iexact=self.cleaned_data['username'])
         if existing.exists():
             raise forms.ValidationError(_("A user with that username already exists."))
         site.
         
         """
+        User = get_user_model()
         if User.objects.filter(email__iexact=self.cleaned_data['email']):
             raise forms.ValidationError(_("This email address is already in use. Please supply a different email address."))
         return self.cleaned_data['email']

File registration/models.py

 import re
 
 from django.conf import settings
-from django.contrib.auth.models import User
-from django.db import models
-from django.db import transaction
+from django.contrib.auth import get_user_model
+from django.db import models, transaction
 from django.template.loader import render_to_string
 from django.utils.translation import ugettext_lazy as _
 
         be deleted.
         
         """
+        User = get_user_model()
         for profile in self.all():
             try:
                 if profile.activation_key_expired():
     """
     ACTIVATED = u"ALREADY_ACTIVATED"
     
-    user = models.ForeignKey(User, unique=True, verbose_name=_('user'))
+    user = models.ForeignKey(settings.AUTH_USER_MODEL, unique=True,
+                             verbose_name=_('user'))
     activation_key = models.CharField(_('activation key'), max_length=40)
     
     objects = RegistrationManager()

File registration/tests/default_backend.py

 import datetime
 
 from django.conf import settings
-from django.contrib.auth.models import User
+from django.contrib.auth import get_user_model
 from django.contrib.sites.models import Site
 from django.core import mail
 from django.core.urlresolvers import reverse
 from django.test import TestCase
 
-from registration import signals
-from registration.admin import RegistrationAdmin
 from registration.forms import RegistrationForm
-from registration.backends.default.views import RegistrationView
 from registration.models import RegistrationProfile
 
 
                                       'password2': 'secret'})
         self.assertRedirects(resp, reverse('registration_complete'))
 
+        User = get_user_model()
         new_user = User.objects.get(username='bob')
 
         self.failUnless(new_user.check_password('secret'))
                                       'password2': 'secret'})
         self.assertEqual(302, resp.status_code)
 
+        User = get_user_model()
         new_user = User.objects.get(username='bob')
 
         self.failUnless(new_user.check_password('secret'))

File registration/tests/forms.py

-from django.contrib.auth.models import User
+from django.contrib.auth import get_user_model
 from django.test import TestCase
 
 from registration import forms
         """
         # Create a user so we can verify that duplicate usernames aren't
         # permitted.
+        User = get_user_model()
         User.objects.create_user('alice', 'alice@example.com', 'secret')
 
         invalid_data_dicts = [
         """
         # Create a user so we can verify that duplicate addresses
         # aren't permitted.
+        User = get_user_model()
         User.objects.create_user('alice', 'alice@example.com', 'secret')
 
         form = forms.RegistrationFormUniqueEmail(data={'username': 'foo',

File registration/tests/models.py

 import re
 
 from django.conf import settings
-from django.contrib.auth.models import User
+from django.contrib.auth import get_user_model
 from django.contrib.sites.models import Site
 from django.core import mail
 from django.core import management
         activation key.
         
         """
+        User = get_user_model()
         new_user = User.objects.create_user(**self.user_info)
         profile = RegistrationProfile.objects.create_profile(new_user)
 
         email.
         
         """
+        User = get_user_model()
         new_user = User.objects.create_user(**self.user_info)
         profile = RegistrationProfile.objects.create_profile(new_user)
         profile.send_activation_email(Site.objects.get_current())
         profile = RegistrationProfile.objects.get(user=new_user)
         activated = RegistrationProfile.objects.activate_user(profile.activation_key)
 
+        User = get_user_model()
         self.failIf(isinstance(activated, User))
         self.failIf(activated)
 
 
         RegistrationProfile.objects.delete_expired_users()
         self.assertEqual(RegistrationProfile.objects.count(), 1)
+        User = get_user_model()
         self.assertRaises(User.DoesNotExist, User.objects.get, username='bob')
 
     def test_management_command(self):
 
         management.call_command('cleanupregistration')
         self.assertEqual(RegistrationProfile.objects.count(), 1)
+        User = get_user_model()
         self.assertRaises(User.DoesNotExist, User.objects.get, username='bob')

File registration/tests/simple_backend.py

 from django.conf import settings
-from django.contrib.auth.models import User
+from django.contrib.auth import get_user_model
 from django.core.urlresolvers import reverse
 from django.test import TestCase
 
                                       'password1': 'secret',
                                       'password2': 'secret'})
 
+        User = get_user_model()
         new_user = User.objects.get(username='bob')
         self.assertEqual(302, resp.status_code)
         self.failUnless(new_user.get_absolute_url() in resp['Location'])