mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #24055 -- Keep reference to view class for resolve()
This commit is contained in:
committed by
Loic Bistuer
parent
67235fd4ef
commit
a420f83e7d
@@ -11,7 +11,7 @@ from django.core.checks import Error
|
||||
from django.core.files import temp as tempfile
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.core.urlresolvers import (NoReverseMatch,
|
||||
get_script_prefix, reverse, set_script_prefix)
|
||||
get_script_prefix, resolve, reverse, set_script_prefix)
|
||||
# Register auth models with the admin.
|
||||
from django.contrib.auth import get_permission_codename
|
||||
from django.contrib.admin import ModelAdmin
|
||||
@@ -56,6 +56,7 @@ from .models import (Article, BarAccount, CustomArticle, EmptyModel, FooAccount,
|
||||
Simple, UndeletableObject, UnchangeableObject, Choice, ShortMessage,
|
||||
Telegram, Pizza, Topping, FilteredManager, City, Restaurant, Worker,
|
||||
ParentWithDependentChildren, Character, FieldOverridePost, Color2)
|
||||
from . import customadmin
|
||||
from .admin import site, site2, CityAdmin
|
||||
|
||||
|
||||
@@ -749,6 +750,12 @@ class AdminViewBasicTest(AdminViewBasicTestCase):
|
||||
with self.assertRaises(NoReverseMatch):
|
||||
reverse('admin:app_list', args=('admin_views2',))
|
||||
|
||||
def test_resolve_admin_views(self):
|
||||
index_match = resolve('/test_admin/admin4/')
|
||||
list_match = resolve('/test_admin/admin4/auth/user/')
|
||||
self.assertIs(index_match.func.admin_site, customadmin.simple_site)
|
||||
self.assertIsInstance(list_match.func.model_admin, customadmin.CustomPwdTemplateUserAdmin)
|
||||
|
||||
def test_proxy_model_content_type_is_used_for_log_entries(self):
|
||||
"""
|
||||
Log entries for proxy models should have the proxy model's content
|
||||
|
||||
@@ -5,6 +5,7 @@ import unittest
|
||||
import warnings
|
||||
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from django.core.urlresolvers import resolve
|
||||
from django.http import HttpResponse
|
||||
from django.utils import six
|
||||
from django.utils.deprecation import RemovedInDjango19Warning
|
||||
@@ -329,6 +330,15 @@ class TemplateViewTest(TestCase):
|
||||
response = self.client.get('/template/content_type/')
|
||||
self.assertEqual(response['Content-Type'], 'text/plain')
|
||||
|
||||
def test_resolve_view(self):
|
||||
match = resolve('/template/content_type/')
|
||||
self.assertIs(match.func.view_class, TemplateView)
|
||||
self.assertEqual(match.func.view_initkwargs['content_type'], 'text/plain')
|
||||
|
||||
def test_resolve_login_required_view(self):
|
||||
match = resolve('/template/login_required/')
|
||||
self.assertIs(match.func.view_class, TemplateView)
|
||||
|
||||
|
||||
@ignore_warnings(category=RemovedInDjango19Warning)
|
||||
@override_settings(ROOT_URLCONF='generic_views.urls')
|
||||
|
||||
@@ -3,6 +3,7 @@ from __future__ import unicode_literals
|
||||
|
||||
from django.conf.urls import url
|
||||
from django.contrib.auth import views as auth_views
|
||||
from django.contrib.auth.decorators import login_required
|
||||
from django.views.decorators.cache import cache_page
|
||||
from django.views.generic import TemplateView
|
||||
|
||||
@@ -14,6 +15,8 @@ urlpatterns = [
|
||||
# TemplateView
|
||||
url(r'^template/no_template/$',
|
||||
TemplateView.as_view()),
|
||||
url(r'^template/login_required/$',
|
||||
login_required(TemplateView.as_view())),
|
||||
url(r'^template/simple/(?P<foo>\w+)/$',
|
||||
TemplateView.as_view(template_name='generic_views/about.html')),
|
||||
url(r'^template/custom/(?P<foo>\w+)/$',
|
||||
|
||||
Reference in New Issue
Block a user