Update for proxy models and Django 1.5
Only monkeypatch when using Django < 1.5 Updated testfix_request_path_info
parent
e2cfbf3898
commit
74389bb23d
|
|
@ -6,6 +6,7 @@ Copyright:
|
||||||
This code and affiliated files are (C) by Bert Constantin and individual contributors.
|
This code and affiliated files are (C) by Bert Constantin and individual contributors.
|
||||||
Please see LICENSE and AUTHORS for more information.
|
Please see LICENSE and AUTHORS for more information.
|
||||||
"""
|
"""
|
||||||
|
import django
|
||||||
from polymorphic_model import PolymorphicModel
|
from polymorphic_model import PolymorphicModel
|
||||||
from manager import PolymorphicManager
|
from manager import PolymorphicManager
|
||||||
from query import PolymorphicQuerySet
|
from query import PolymorphicQuerySet
|
||||||
|
|
@ -25,16 +26,13 @@ def get_version():
|
||||||
version += ' %s' % VERSION[3]
|
version += ' %s' % VERSION[3]
|
||||||
return version
|
return version
|
||||||
|
|
||||||
from django.contrib.contenttypes.models import ContentTypeManager
|
|
||||||
from django.utils.encoding import smart_unicode
|
|
||||||
|
|
||||||
|
# Monkey-patch Django < 1.5 to allow ContentTypes for proxy models.
|
||||||
|
if django.VERSION[:2] < (1, 5):
|
||||||
|
from django.contrib.contenttypes.models import ContentTypeManager
|
||||||
|
from django.utils.encoding import smart_unicode
|
||||||
|
|
||||||
# Monkey-patch Django to allow ContentTypes for proxy models. This is compatible with an
|
def get_for_model(self, model, for_concrete_model=True):
|
||||||
# upcoming change in Django 1.5 and should be removed when we upgrade. There is a test
|
|
||||||
# in MonkeyPatchTests that checks for this.
|
|
||||||
# https://code.djangoproject.com/ticket/18399
|
|
||||||
|
|
||||||
def get_for_model(self, model, for_concrete_model=True):
|
|
||||||
from django.utils.encoding import smart_unicode
|
from django.utils.encoding import smart_unicode
|
||||||
|
|
||||||
if for_concrete_model:
|
if for_concrete_model:
|
||||||
|
|
@ -56,6 +54,6 @@ def get_for_model(self, model, for_concrete_model=True):
|
||||||
|
|
||||||
return ct
|
return ct
|
||||||
|
|
||||||
ContentTypeManager.get_for_model__original = ContentTypeManager.get_for_model
|
ContentTypeManager.get_for_model__original = ContentTypeManager.get_for_model
|
||||||
ContentTypeManager.get_for_model = get_for_model
|
ContentTypeManager.get_for_model = get_for_model
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -750,9 +750,8 @@ class RegressionTests(TestCase):
|
||||||
self.assertQuerysetEqual(Bottom.objects.all(), [repr(r) for r in expected_queryset])
|
self.assertQuerysetEqual(Bottom.objects.all(), [repr(r) for r in expected_queryset])
|
||||||
|
|
||||||
|
|
||||||
class MonkeyPatchTests(TestCase):
|
class ProxiedModelTests(TestCase):
|
||||||
|
def test_content_types_for_proxy_models(self):
|
||||||
def test_content_types_for_proxy_models_patch(self):
|
|
||||||
from django.db.models import Model
|
from django.db.models import Model
|
||||||
from django.contrib.contenttypes.models import ContentType
|
from django.contrib.contenttypes.models import ContentType
|
||||||
|
|
||||||
|
|
@ -766,20 +765,3 @@ class MonkeyPatchTests(TestCase):
|
||||||
ct = ContentType.objects.get_for_model(Proxy, for_concrete_model=False)
|
ct = ContentType.objects.get_for_model(Proxy, for_concrete_model=False)
|
||||||
self.assertEqual(Proxy, ct.model_class())
|
self.assertEqual(Proxy, ct.model_class())
|
||||||
|
|
||||||
def test_content_types_for_proxy_models_patch_still_required(self):
|
|
||||||
"""
|
|
||||||
If this test fails then our monkey patch of ContentTypeManager.get_for_model
|
|
||||||
is no longer required and should be removed
|
|
||||||
"""
|
|
||||||
from django.db.models import Model
|
|
||||||
from django.contrib.contenttypes.models import ContentType
|
|
||||||
|
|
||||||
class MyModel(Model):
|
|
||||||
pass
|
|
||||||
|
|
||||||
self.assertRaisesMessage(
|
|
||||||
TypeError,
|
|
||||||
"get_for_model() got an unexpected keyword argument 'for_concrete_model'",
|
|
||||||
ContentType.objects.get_for_model__original,
|
|
||||||
MyModel, for_concrete_model=False
|
|
||||||
)
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue