From c196564132a351549245a5d795391ad1ea56195c Mon Sep 17 00:00:00 2001 From: Ramiro Morales Date: Fri, 28 Jun 2013 15:13:06 -0300 Subject: [PATCH] Removed custom profile model functionality as per deprecation TL. --- django/contrib/auth/models.py | 32 ------------------- django/contrib/auth/tests/test_models.py | 39 +----------------------- docs/ref/contrib/auth.txt | 14 --------- docs/ref/settings.txt | 16 ---------- docs/releases/1.5-alpha-1.txt | 8 ++--- docs/releases/1.5-beta-1.txt | 8 ++--- docs/releases/1.5.txt | 8 ++--- docs/topics/auth/customizing.txt | 34 --------------------- tests/multiple_database/tests.py | 21 ------------- 9 files changed, 13 insertions(+), 167 deletions(-) diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py index 5fec99a783..16c6357c40 100644 --- a/django/contrib/auth/models.py +++ b/django/contrib/auth/models.py @@ -413,38 +413,6 @@ class AbstractUser(AbstractBaseUser, PermissionsMixin): """ send_mail(subject, message, from_email, [self.email]) - def get_profile(self): - """ - Returns site-specific profile for this user. Raises - SiteProfileNotAvailable if this site does not allow profiles. - """ - warnings.warn("The use of AUTH_PROFILE_MODULE to define user profiles has been deprecated.", - DeprecationWarning, stacklevel=2) - if not hasattr(self, '_profile_cache'): - from django.conf import settings - if not getattr(settings, 'AUTH_PROFILE_MODULE', False): - raise SiteProfileNotAvailable( - 'You need to set AUTH_PROFILE_MODULE in your project ' - 'settings') - try: - app_label, model_name = settings.AUTH_PROFILE_MODULE.split('.') - except ValueError: - raise SiteProfileNotAvailable( - 'app_label and model_name should be separated by a dot in ' - 'the AUTH_PROFILE_MODULE setting') - try: - model = models.get_model(app_label, model_name) - if model is None: - raise SiteProfileNotAvailable( - 'Unable to load the profile model, check ' - 'AUTH_PROFILE_MODULE in your project settings') - self._profile_cache = model._default_manager.using( - self._state.db).get(user__id__exact=self.id) - self._profile_cache.user = self - except (ImportError, ImproperlyConfigured): - raise SiteProfileNotAvailable - return self._profile_cache - class User(AbstractUser): """ diff --git a/django/contrib/auth/tests/test_models.py b/django/contrib/auth/tests/test_models.py index b0a4559b42..cd3a13b76d 100644 --- a/django/contrib/auth/tests/test_models.py +++ b/django/contrib/auth/tests/test_models.py @@ -1,46 +1,9 @@ -import warnings - -from django.conf import settings from django.contrib.auth import get_user_model -from django.contrib.auth.models import (Group, User, SiteProfileNotAvailable, - UserManager) +from django.contrib.auth.models import (Group, User, UserManager) from django.contrib.auth.tests.utils import skipIfCustomUser from django.db.models.signals import post_save from django.test import TestCase from django.test.utils import override_settings -from django.utils import six - - -@skipIfCustomUser -@override_settings(USE_TZ=False, AUTH_PROFILE_MODULE='') -class ProfileTestCase(TestCase): - - def test_site_profile_not_available(self): - user = User.objects.create(username='testclient') - - # calling get_profile without AUTH_PROFILE_MODULE set - del settings.AUTH_PROFILE_MODULE - with warnings.catch_warnings(): - warnings.simplefilter("ignore", DeprecationWarning) - with six.assertRaisesRegex(self, SiteProfileNotAvailable, - "You need to set AUTH_PROFILE_MODULE in your project"): - user.get_profile() - - # Bad syntax in AUTH_PROFILE_MODULE: - settings.AUTH_PROFILE_MODULE = 'foobar' - with warnings.catch_warnings(): - warnings.simplefilter("ignore", DeprecationWarning) - with six.assertRaisesRegex(self, SiteProfileNotAvailable, - "app_label and model_name should be separated by a dot"): - user.get_profile() - - # module that doesn't exist - settings.AUTH_PROFILE_MODULE = 'foo.bar' - with warnings.catch_warnings(): - warnings.simplefilter("ignore", DeprecationWarning) - with six.assertRaisesRegex(self, SiteProfileNotAvailable, - "Unable to load the profile model"): - user.get_profile() @skipIfCustomUser diff --git a/docs/ref/contrib/auth.txt b/docs/ref/contrib/auth.txt index afbc6ec048..dfda8add4b 100644 --- a/docs/ref/contrib/auth.txt +++ b/docs/ref/contrib/auth.txt @@ -218,20 +218,6 @@ Methods Sends an email to the user. If ``from_email`` is ``None``, Django uses the :setting:`DEFAULT_FROM_EMAIL`. - .. method:: get_profile() - - .. deprecated:: 1.5 - With the introduction of :ref:`custom User models `, - the use of :setting:`AUTH_PROFILE_MODULE` to define a single profile - model is no longer supported. See the - :doc:`Django 1.5 release notes` for more information. - - Returns a site-specific profile for this user. Raises - ``django.contrib.auth.models.SiteProfileNotAvailable`` if the - current site doesn't allow profiles, or - :exc:`django.core.exceptions.ObjectDoesNotExist` if the user does not - have a profile. - Manager methods --------------- diff --git a/docs/ref/settings.txt b/docs/ref/settings.txt index 215931768c..736edbb826 100644 --- a/docs/ref/settings.txt +++ b/docs/ref/settings.txt @@ -2049,22 +2049,6 @@ A tuple of authentication backend classes (as strings) to use when attempting to authenticate a user. See the :ref:`authentication backends documentation ` for details. -.. setting:: AUTH_PROFILE_MODULE - -AUTH_PROFILE_MODULE -------------------- - -.. deprecated:: 1.5 - With the introduction of :ref:`custom User models `, - the use of :setting:`AUTH_PROFILE_MODULE` to define a single profile - model is no longer supported. See the - :doc:`Django 1.5 release notes` for more information. - -Default: Not defined - -The site-specific user profile model used by this site. See -:ref:`User profiles `. - .. setting:: AUTH_USER_MODEL AUTH_USER_MODEL diff --git a/docs/releases/1.5-alpha-1.txt b/docs/releases/1.5-alpha-1.txt index 2588b85306..9ff4ca44db 100644 --- a/docs/releases/1.5-alpha-1.txt +++ b/docs/releases/1.5-alpha-1.txt @@ -575,8 +575,8 @@ Miscellaneous Features deprecated in 1.5 ========================== -:setting:`AUTH_PROFILE_MODULE` -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``AUTH_PROFILE_MODULE`` setting +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ With the introduction of :ref:`custom User models `, there is no longer any need for a built-in mechanism to store user profile data. @@ -584,8 +584,8 @@ no longer any need for a built-in mechanism to store user profile data. You can still define user profiles models that have a one-to-one relation with the User model - in fact, for many applications needing to associate data with a User account, this will be an appropriate design pattern to follow. However, -the :setting:`AUTH_PROFILE_MODULE` setting, and the -:meth:`~django.contrib.auth.models.User.get_profile()` method for accessing +the ``AUTH_PROFILE_MODULE`` setting, and the +``django.contrib.auth.models.User.get_profile()`` method for accessing the user profile model, should not be used any longer. Streaming behavior of :class:`~django.http.HttpResponse` diff --git a/docs/releases/1.5-beta-1.txt b/docs/releases/1.5-beta-1.txt index a1c9edd890..9c3b9e78e6 100644 --- a/docs/releases/1.5-beta-1.txt +++ b/docs/releases/1.5-beta-1.txt @@ -627,8 +627,8 @@ Features deprecated in 1.5 .. _simplejson-deprecation-beta-1: -:setting:`AUTH_PROFILE_MODULE` -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``AUTH_PROFILE_MODULE`` +~~~~~~~~~~~~~~~~~~~~~~~ With the introduction of :ref:`custom User models `, there is no longer any need for a built-in mechanism to store user profile data. @@ -636,8 +636,8 @@ no longer any need for a built-in mechanism to store user profile data. You can still define user profiles models that have a one-to-one relation with the User model - in fact, for many applications needing to associate data with a User account, this will be an appropriate design pattern to follow. However, -the :setting:`AUTH_PROFILE_MODULE` setting, and the -:meth:`~django.contrib.auth.models.User.get_profile()` method for accessing +the ``AUTH_PROFILE_MODULE`` setting, and the +``django.contrib.auth.models.User.get_profile()`` method for accessing the user profile model, should not be used any longer. Streaming behavior of :class:`~django.http.HttpResponse` diff --git a/docs/releases/1.5.txt b/docs/releases/1.5.txt index 2bb3095297..3948c867a3 100644 --- a/docs/releases/1.5.txt +++ b/docs/releases/1.5.txt @@ -732,8 +732,8 @@ deprecation schedule. Direct use of python markup libraries or 3rd party tag libraries is preferred to Django maintaining this functionality in the framework. -:setting:`AUTH_PROFILE_MODULE` -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ +``AUTH_PROFILE_MODULE`` +~~~~~~~~~~~~~~~~~~~~~~~ With the introduction of :ref:`custom User models `, there is no longer any need for a built-in mechanism to store user profile data. @@ -741,8 +741,8 @@ no longer any need for a built-in mechanism to store user profile data. You can still define user profiles models that have a one-to-one relation with the User model - in fact, for many applications needing to associate data with a User account, this will be an appropriate design pattern to follow. However, -the :setting:`AUTH_PROFILE_MODULE` setting, and the -:meth:`~django.contrib.auth.models.User.get_profile()` method for accessing +the ``AUTH_PROFILE_MODULE`` setting, and the +``django.contrib.auth.models.User.get_profile()`` method for accessing the user profile model, should not be used any longer. Streaming behavior of :class:`~django.http.HttpResponse` diff --git a/docs/topics/auth/customizing.txt b/docs/topics/auth/customizing.txt index ee1aedbd8c..24c622f77f 100644 --- a/docs/topics/auth/customizing.txt +++ b/docs/topics/auth/customizing.txt @@ -354,40 +354,6 @@ model and adding the related fields may be your better option. However existing links to the default User model within your project's apps may justify the extra database load. -.. _auth-profiles: - -.. deprecated:: 1.5 - With the introduction of :ref:`custom User models `, - the use of :setting:`AUTH_PROFILE_MODULE` to define a single profile - model is no longer supported. See the - :doc:`Django 1.5 release notes` for more information. - -Prior to 1.5, a single profile model could be specified site-wide with the -setting :setting:`AUTH_PROFILE_MODULE` with a string consisting of the -following items, separated by a dot: - -1. The name of the application (case sensitive) in which the user - profile model is defined (in other words, the - name which was passed to :djadmin:`manage.py startapp ` to create - the application). - -2. The name of the model (not case sensitive) class. - -For example, if the profile model was a class named ``UserProfile`` and was -defined inside an application named ``accounts``, the appropriate setting would -be:: - - AUTH_PROFILE_MODULE = 'accounts.UserProfile' - -When a user profile model has been defined and specified in this manner, each -:class:`~django.contrib.auth.models.User` object will have a method -- -:class:`~django.contrib.auth.models.User.get_profile()` -- which returns the -instance of the user profile model associated with that -:class:`~django.contrib.auth.models.User`. - -The method :class:`~django.contrib.auth.models.User.get_profile()` -does not create a profile if one does not exist. - .. _auth-custom-user: Substituting a custom User model diff --git a/tests/multiple_database/tests.py b/tests/multiple_database/tests.py index a0d937ce81..12a6379ca0 100644 --- a/tests/multiple_database/tests.py +++ b/tests/multiple_database/tests.py @@ -3,9 +3,7 @@ from __future__ import absolute_import, unicode_literals import datetime import pickle from operator import attrgetter -import warnings -from django.conf import settings from django.contrib.auth.models import User from django.contrib.contenttypes.models import ContentType from django.core import management @@ -1626,25 +1624,6 @@ class AuthTestCase(TestCase): command_output = new_io.getvalue().strip() self.assertTrue('"email": "alice@example.com"' in command_output) - -@override_settings(AUTH_PROFILE_MODULE='multiple_database.UserProfile') -class UserProfileTestCase(TestCase): - - def test_user_profiles(self): - alice = User.objects.create_user('alice', 'alice@example.com') - bob = User.objects.db_manager('other').create_user('bob', 'bob@example.com') - - alice_profile = UserProfile(user=alice, flavor='chocolate') - alice_profile.save() - - bob_profile = UserProfile(user=bob, flavor='crunchy frog') - bob_profile.save() - - with warnings.catch_warnings(): - warnings.simplefilter("ignore", DeprecationWarning) - self.assertEqual(alice.get_profile().flavor, 'chocolate') - self.assertEqual(bob.get_profile().flavor, 'crunchy frog') - class AntiPetRouter(object): # A router that only expresses an opinion on syncdb, # passing pets to the 'other' database