This reverts commit 20799cc0a6
.
This commit is contained in:
parent
b5acb9db75
commit
04e87e79a0
|
@ -11,7 +11,7 @@ from django.template.response import TemplateResponse
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils.decorators import classonlymethod
|
from django.utils.decorators import classonlymethod
|
||||||
from django.utils.deprecation import RemovedInDjango40Warning
|
from django.utils.deprecation import RemovedInDjango40Warning
|
||||||
from django.utils.functional import lazy
|
from django.utils.functional import SimpleLazyObject
|
||||||
|
|
||||||
logger = logging.getLogger('django.request')
|
logger = logging.getLogger('django.request')
|
||||||
|
|
||||||
|
@ -169,6 +169,7 @@ def _wrap_url_kwargs_with_deprecation_warning(url_kwargs):
|
||||||
context_kwargs = {}
|
context_kwargs = {}
|
||||||
for key, value in url_kwargs.items():
|
for key, value in url_kwargs.items():
|
||||||
# Bind into function closure.
|
# Bind into function closure.
|
||||||
|
@SimpleLazyObject
|
||||||
def access_value(key=key, value=value):
|
def access_value(key=key, value=value):
|
||||||
warnings.warn(
|
warnings.warn(
|
||||||
'TemplateView passing URL kwargs to the context is '
|
'TemplateView passing URL kwargs to the context is '
|
||||||
|
@ -177,7 +178,7 @@ def _wrap_url_kwargs_with_deprecation_warning(url_kwargs):
|
||||||
RemovedInDjango40Warning, stacklevel=2,
|
RemovedInDjango40Warning, stacklevel=2,
|
||||||
)
|
)
|
||||||
return value
|
return value
|
||||||
context_kwargs[key] = lazy(access_value, type(value))()
|
context_kwargs[key] = access_value
|
||||||
return context_kwargs
|
return context_kwargs
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -26,10 +26,6 @@ Bugfixes
|
||||||
related fields pointing to a proxy model in the ``of`` argument, the
|
related fields pointing to a proxy model in the ``of`` argument, the
|
||||||
corresponding model was not locked (:ticket:`31866`).
|
corresponding model was not locked (:ticket:`31866`).
|
||||||
|
|
||||||
* Fixed a regression in Django 3.1 that caused a crash when passing deprecated
|
|
||||||
keyword arguments to a queryset in ``TemplateView.get_context_data()``
|
|
||||||
(:ticket:`31877`).
|
|
||||||
|
|
||||||
* Fixed a data loss possibility, following a regression in Django 2.0, when
|
* Fixed a data loss possibility, following a regression in Django 2.0, when
|
||||||
copying model instances with a cached fields value (:ticket:`31863`).
|
copying model instances with a cached fields value (:ticket:`31863`).
|
||||||
|
|
||||||
|
|
|
@ -3,8 +3,7 @@ import time
|
||||||
from django.core.exceptions import ImproperlyConfigured
|
from django.core.exceptions import ImproperlyConfigured
|
||||||
from django.http import HttpResponse
|
from django.http import HttpResponse
|
||||||
from django.test import (
|
from django.test import (
|
||||||
RequestFactory, SimpleTestCase, TestCase, ignore_warnings,
|
RequestFactory, SimpleTestCase, ignore_warnings, override_settings,
|
||||||
override_settings,
|
|
||||||
)
|
)
|
||||||
from django.test.utils import require_jinja2
|
from django.test.utils import require_jinja2
|
||||||
from django.urls import resolve
|
from django.urls import resolve
|
||||||
|
@ -12,7 +11,6 @@ from django.utils.deprecation import RemovedInDjango40Warning
|
||||||
from django.views.generic import RedirectView, TemplateView, View
|
from django.views.generic import RedirectView, TemplateView, View
|
||||||
|
|
||||||
from . import views
|
from . import views
|
||||||
from .models import Artist
|
|
||||||
|
|
||||||
|
|
||||||
class SimpleView(View):
|
class SimpleView(View):
|
||||||
|
@ -573,9 +571,7 @@ class SingleObjectTemplateResponseMixinTest(SimpleTestCase):
|
||||||
|
|
||||||
|
|
||||||
@override_settings(ROOT_URLCONF='generic_views.urls')
|
@override_settings(ROOT_URLCONF='generic_views.urls')
|
||||||
class DeprecationTests(TestCase):
|
class DeprecationTests(SimpleTestCase):
|
||||||
rf = RequestFactory()
|
|
||||||
|
|
||||||
@ignore_warnings(category=RemovedInDjango40Warning)
|
@ignore_warnings(category=RemovedInDjango40Warning)
|
||||||
def test_template_params(self):
|
def test_template_params(self):
|
||||||
"""A generic template view passes kwargs as context."""
|
"""A generic template view passes kwargs as context."""
|
||||||
|
@ -607,17 +603,3 @@ class DeprecationTests(TestCase):
|
||||||
str(response.context['foo2'])
|
str(response.context['foo2'])
|
||||||
self.assertEqual(response.context['key'], 'value')
|
self.assertEqual(response.context['key'], 'value')
|
||||||
self.assertIsInstance(response.context['view'], View)
|
self.assertIsInstance(response.context['view'], View)
|
||||||
|
|
||||||
@ignore_warnings(category=RemovedInDjango40Warning)
|
|
||||||
def test_template_params_filtering(self):
|
|
||||||
class ArtistView(TemplateView):
|
|
||||||
template_name = 'generic_views/about.html'
|
|
||||||
|
|
||||||
def get_context_data(self, *, artist_name, **kwargs):
|
|
||||||
context = super().get_context_data(**kwargs)
|
|
||||||
artist = Artist.objects.get(name=artist_name)
|
|
||||||
return {**context, 'artist': artist}
|
|
||||||
|
|
||||||
artist = Artist.objects.create(name='Rene Magritte')
|
|
||||||
response = ArtistView.as_view()(self.rf.get('/'), artist_name=artist.name)
|
|
||||||
self.assertEqual(response.context_data['artist'], artist)
|
|
||||||
|
|
Loading…
Reference in New Issue