Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

We’re showing branches in this repository, but you can also compare across forks.

base fork: django/django
...
head fork: ptone/django
  • 1 commit
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Commits on Dec 15, 2012
Preston Holmes ptone Fixed #19401 - swapped model check case insensitive
with respect to the model class, not the app_label
5c7d036
Showing with 18 additions and 3 deletions.
  1. +5 −0 django/contrib/auth/tests/basic.py
  2. +13 −3 django/db/models/options.py
5 django/contrib/auth/tests/basic.py
View
@@ -165,6 +165,11 @@ def test_swappable_user(self):
with self.assertRaises(AttributeError):
User.objects.all()
+ @override_settings(AUTH_USER_MODEL='auth.user')
+ def test_swappable_user_case(self):
+ "The model name is not case sensitive"
+ self.assertEqual(User._meta.swapped, None)
+
@override_settings(AUTH_USER_MODEL='badsetting')
def test_swappable_user_bad_setting(self):
"The alternate user setting must point to something in the format app.model"
16 django/db/models/options.py
View
@@ -215,10 +215,20 @@ def _swapped(self):
name of the replacement; otherwise, return None.
"""
if self.swappable:
- model_label = '%s.%s' % (self.app_label, self.object_name)
+ model_label = '%s.%s' % (self.app_label, self.object_name.lower())
swapped_for = getattr(settings, self.swappable, None)
- if swapped_for not in (None, model_label):
- return swapped_for
+ if swapped_for:
+ try:
+ swapped_label, swapped_object = swapped_for.split('.')
+ except ValueError:
+ # setting not in the format app_label.model_name
+ # raising ImproperlyConfigured here causes problems with
+ # test cleanup code - instead it is raised in get_user_model
+ return None
+
+ if '%s.%s' % (swapped_label, swapped_object.lower()) not in (
+ None, model_label ):
+ return swapped_for
return None
swapped = property(_swapped)

No commit comments for this range

Something went wrong with that request. Please try again.