From a092a72844705e3129b8996b81d8424997b5d37f Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Mon, 3 Sep 2012 16:54:17 +0100 Subject: View -> APIView --- djangorestframework/utils/breadcrumbs.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'djangorestframework/utils/breadcrumbs.py') diff --git a/djangorestframework/utils/breadcrumbs.py b/djangorestframework/utils/breadcrumbs.py index 85e13a5a..319ce5f9 100644 --- a/djangorestframework/utils/breadcrumbs.py +++ b/djangorestframework/utils/breadcrumbs.py @@ -1,9 +1,10 @@ from django.core.urlresolvers import resolve + def get_breadcrumbs(url): """Given a url returns a list of breadcrumbs, which are each a tuple of (name, url).""" - from djangorestframework.views import View + from djangorestframework.views import APIView def breadcrumbs_recursive(url, breadcrumbs_list): """Add tuples of (name, url) to the breadcrumbs list, progressively chomping off parts of the url.""" @@ -14,7 +15,7 @@ def get_breadcrumbs(url): pass else: # Check if this is a REST framework view, and if so add it to the breadcrumbs - if isinstance(getattr(view, 'cls_instance', None), View): + if isinstance(getattr(view, 'cls_instance', None), APIView): breadcrumbs_list.insert(0, (view.cls_instance.get_name(), url)) if url == '': -- cgit v1.2.3 From 6af75d3a69c486b19adc6e2da00719094778eb31 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Tue, 4 Sep 2012 09:29:59 +0100 Subject: Remove some bits from utils --- djangorestframework/utils/breadcrumbs.py | 1 - 1 file changed, 1 deletion(-) (limited to 'djangorestframework/utils/breadcrumbs.py') diff --git a/djangorestframework/utils/breadcrumbs.py b/djangorestframework/utils/breadcrumbs.py index 319ce5f9..84dd3dfa 100644 --- a/djangorestframework/utils/breadcrumbs.py +++ b/djangorestframework/utils/breadcrumbs.py @@ -30,4 +30,3 @@ def get_breadcrumbs(url): return breadcrumbs_recursive(url[:url.rfind('/') + 1], breadcrumbs_list) return breadcrumbs_recursive(url, []) - -- cgit v1.2.3 From 9921b6bd73c5256a3b65c2a5106717ce0fc8f0cf Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Wed, 19 Sep 2012 17:14:40 +0100 Subject: Use get_script_prefix to play nicely if not installed at the root. --- djangorestframework/utils/breadcrumbs.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'djangorestframework/utils/breadcrumbs.py') diff --git a/djangorestframework/utils/breadcrumbs.py b/djangorestframework/utils/breadcrumbs.py index 84dd3dfa..71284380 100644 --- a/djangorestframework/utils/breadcrumbs.py +++ b/djangorestframework/utils/breadcrumbs.py @@ -1,4 +1,4 @@ -from django.core.urlresolvers import resolve +from django.core.urlresolvers import resolve, get_script_prefix def get_breadcrumbs(url): @@ -6,7 +6,7 @@ def get_breadcrumbs(url): from djangorestframework.views import APIView - def breadcrumbs_recursive(url, breadcrumbs_list): + def breadcrumbs_recursive(url, breadcrumbs_list, prefix): """Add tuples of (name, url) to the breadcrumbs list, progressively chomping off parts of the url.""" try: @@ -16,7 +16,7 @@ def get_breadcrumbs(url): else: # Check if this is a REST framework view, and if so add it to the breadcrumbs if isinstance(getattr(view, 'cls_instance', None), APIView): - breadcrumbs_list.insert(0, (view.cls_instance.get_name(), url)) + breadcrumbs_list.insert(0, (view.cls_instance.get_name(), prefix + url)) if url == '': # All done @@ -24,9 +24,11 @@ def get_breadcrumbs(url): elif url.endswith('/'): # Drop trailing slash off the end and continue to try to resolve more breadcrumbs - return breadcrumbs_recursive(url.rstrip('/'), breadcrumbs_list) + return breadcrumbs_recursive(url.rstrip('/'), breadcrumbs_list, prefix) # Drop trailing non-slash off the end and continue to try to resolve more breadcrumbs - return breadcrumbs_recursive(url[:url.rfind('/') + 1], breadcrumbs_list) + return breadcrumbs_recursive(url[:url.rfind('/') + 1], breadcrumbs_list, prefix) - return breadcrumbs_recursive(url, []) + prefix = get_script_prefix() + url = url[len(prefix):] + return breadcrumbs_recursive(url, [], prefix) -- cgit v1.2.3 From cb8a8e98ed42f5053b9752064aa8c4094ee5f754 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Wed, 19 Sep 2012 18:48:59 +0100 Subject: Dont strip final '/' --- djangorestframework/utils/breadcrumbs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'djangorestframework/utils/breadcrumbs.py') diff --git a/djangorestframework/utils/breadcrumbs.py b/djangorestframework/utils/breadcrumbs.py index 71284380..ccee0081 100644 --- a/djangorestframework/utils/breadcrumbs.py +++ b/djangorestframework/utils/breadcrumbs.py @@ -29,6 +29,6 @@ def get_breadcrumbs(url): # Drop trailing non-slash off the end and continue to try to resolve more breadcrumbs return breadcrumbs_recursive(url[:url.rfind('/') + 1], breadcrumbs_list, prefix) - prefix = get_script_prefix() + prefix = get_script_prefix().rstrip('/') url = url[len(prefix):] return breadcrumbs_recursive(url, [], prefix) -- cgit v1.2.3 From 87dae4d8549c02fa9a57adb3bb876d249dae1f79 Mon Sep 17 00:00:00 2001 From: Tom Christie Date: Thu, 20 Sep 2012 13:19:43 +0100 Subject: Remove old 'djangorestframework directories --- djangorestframework/utils/breadcrumbs.py | 34 -------------------------------- 1 file changed, 34 deletions(-) delete mode 100644 djangorestframework/utils/breadcrumbs.py (limited to 'djangorestframework/utils/breadcrumbs.py') diff --git a/djangorestframework/utils/breadcrumbs.py b/djangorestframework/utils/breadcrumbs.py deleted file mode 100644 index ccee0081..00000000 --- a/djangorestframework/utils/breadcrumbs.py +++ /dev/null @@ -1,34 +0,0 @@ -from django.core.urlresolvers import resolve, get_script_prefix - - -def get_breadcrumbs(url): - """Given a url returns a list of breadcrumbs, which are each a tuple of (name, url).""" - - from djangorestframework.views import APIView - - def breadcrumbs_recursive(url, breadcrumbs_list, prefix): - """Add tuples of (name, url) to the breadcrumbs list, progressively chomping off parts of the url.""" - - try: - (view, unused_args, unused_kwargs) = resolve(url) - except Exception: - pass - else: - # Check if this is a REST framework view, and if so add it to the breadcrumbs - if isinstance(getattr(view, 'cls_instance', None), APIView): - breadcrumbs_list.insert(0, (view.cls_instance.get_name(), prefix + url)) - - if url == '': - # All done - return breadcrumbs_list - - elif url.endswith('/'): - # Drop trailing slash off the end and continue to try to resolve more breadcrumbs - return breadcrumbs_recursive(url.rstrip('/'), breadcrumbs_list, prefix) - - # Drop trailing non-slash off the end and continue to try to resolve more breadcrumbs - return breadcrumbs_recursive(url[:url.rfind('/') + 1], breadcrumbs_list, prefix) - - prefix = get_script_prefix().rstrip('/') - url = url[len(prefix):] - return breadcrumbs_recursive(url, [], prefix) -- cgit v1.2.3