mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-29 13:04:03 +03:00
Fix up breadcrumbs to only breadcrumb for REST framework Views
This commit is contained in:
parent
370274f564
commit
eafda85508
|
@ -19,11 +19,11 @@ class NestedResourceInstance(View):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
urlpatterns = patterns('',
|
urlpatterns = patterns('',
|
||||||
url(r'^$', Root),
|
url(r'^$', Root.as_view()),
|
||||||
url(r'^resource/$', ResourceRoot),
|
url(r'^resource/$', ResourceRoot.as_view()),
|
||||||
url(r'^resource/(?P<key>[0-9]+)$', ResourceInstance),
|
url(r'^resource/(?P<key>[0-9]+)$', ResourceInstance.as_view()),
|
||||||
url(r'^resource/(?P<key>[0-9]+)/$', NestedResourceRoot),
|
url(r'^resource/(?P<key>[0-9]+)/$', NestedResourceRoot.as_view()),
|
||||||
url(r'^resource/(?P<key>[0-9]+)/(?P<other>[A-Za-z]+)$', NestedResourceInstance),
|
url(r'^resource/(?P<key>[0-9]+)/(?P<other>[A-Za-z]+)$', NestedResourceInstance.as_view()),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@ from djangorestframework.utils.description import get_name
|
||||||
def get_breadcrumbs(url):
|
def get_breadcrumbs(url):
|
||||||
"""Given a url returns a list of breadcrumbs, which are each a tuple of (name, url)."""
|
"""Given a url returns a list of breadcrumbs, which are each a tuple of (name, url)."""
|
||||||
|
|
||||||
|
from djangorestframework.views import View
|
||||||
|
|
||||||
def breadcrumbs_recursive(url, breadcrumbs_list):
|
def breadcrumbs_recursive(url, breadcrumbs_list):
|
||||||
"""Add tuples of (name, url) to the breadcrumbs list, progressively chomping off parts of the url."""
|
"""Add tuples of (name, url) to the breadcrumbs list, progressively chomping off parts of the url."""
|
||||||
|
|
||||||
|
@ -12,7 +14,8 @@ def get_breadcrumbs(url):
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
if callable(view):
|
# Check if this is a REST framework view, and if so add it to the breadcrumbs
|
||||||
|
if isinstance(getattr(view, 'cls_instance', None), View):
|
||||||
breadcrumbs_list.insert(0, (get_name(view), url))
|
breadcrumbs_list.insert(0, (get_name(view), url))
|
||||||
|
|
||||||
if url == '':
|
if url == '':
|
||||||
|
|
Loading…
Reference in New Issue
Block a user