Do not ignore overridden View.get_view_name() in breadcrumbs

This commit is contained in:
Ollie Walsh 2015-08-14 12:16:57 +01:00
parent 1b53e804ee
commit 3d0292e1cd
2 changed files with 17 additions and 2 deletions

View File

@ -32,8 +32,7 @@ def get_breadcrumbs(url, request=None):
# Don't list the same view twice in a row.
# Probably an optional trailing slash.
if not seen or seen[-1] != view:
suffix = getattr(view, 'suffix', None)
name = view_name_func(cls, suffix)
name = cls().get_view_name()
insert_url = preserve_builtin_query_params(prefix + url, request)
breadcrumbs_list.insert(0, (name, insert_url))
seen.append(view)

View File

@ -31,10 +31,15 @@ class NestedResourceRoot(APIView):
class NestedResourceInstance(APIView):
pass
class CustomNameResourceInstance(APIView):
def get_view_name(self):
return "Foo"
urlpatterns = [
url(r'^$', Root.as_view()),
url(r'^resource/$', ResourceRoot.as_view()),
url(r'^resource/customname$', CustomNameResourceInstance.as_view()),
url(r'^resource/(?P<key>[0-9]+)$', ResourceInstance.as_view()),
url(r'^resource/(?P<key>[0-9]+)/$', NestedResourceRoot.as_view()),
url(r'^resource/(?P<key>[0-9]+)/(?P<other>[A-Za-z]+)$', NestedResourceInstance.as_view()),
@ -75,6 +80,17 @@ class BreadcrumbTests(TestCase):
]
)
def test_resource_instance_customname_breadcrumbs(self):
url = '/resource/customname'
self.assertEqual(
get_breadcrumbs(url),
[
('Root', '/'),
('Resource Root', '/resource/'),
('Foo', '/resource/customname')
]
)
def test_nested_resource_breadcrumbs(self):
url = '/resource/123/'
self.assertEqual(