From 719681902740f0d16cba21aa8e20c8840e016337 Mon Sep 17 00:00:00 2001 From: Emmanouil Konstantinidis Date: Fri, 18 Dec 2015 21:16:30 +0000 Subject: [PATCH 1/3] Init search between endpoints --- rest_framework_docs/views.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/rest_framework_docs/views.py b/rest_framework_docs/views.py index 9f58155..f9919ff 100644 --- a/rest_framework_docs/views.py +++ b/rest_framework_docs/views.py @@ -15,5 +15,12 @@ def get_context_data(self, **kwargs): context = super(DRFDocsView, self).get_context_data(**kwargs) docs = ApiDocumentation() - context['endpoints'] = docs.get_endpoints() + endpoints = docs.get_endpoints() + + query = self.request.GET.get("q", None) + if query and endpoints: + endpoints = [endpoint for endpoint in endpoints if query in endpoint.path] + + context['query'] = query + context['endpoints'] = endpoints return context From c548ba8dd8cf804ebcc2ad9d4d0b8fae578ab6a5 Mon Sep 17 00:00:00 2001 From: Emmanouil Konstantinidis Date: Fri, 18 Dec 2015 21:28:40 +0000 Subject: [PATCH 2/3] Fix search --- rest_framework_docs/templates/rest_framework_docs/base.html | 4 ++-- rest_framework_docs/templates/rest_framework_docs/home.html | 4 +++- rest_framework_docs/views.py | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/rest_framework_docs/templates/rest_framework_docs/base.html b/rest_framework_docs/templates/rest_framework_docs/base.html index 8102c5c..3d3887d 100644 --- a/rest_framework_docs/templates/rest_framework_docs/base.html +++ b/rest_framework_docs/templates/rest_framework_docs/base.html @@ -39,9 +39,9 @@ {% endfor %} - {% else %} + {% elif not query %}

There are currently no api endpoints to document.

+ {% else %} +

No endpoints found for {{ query }}.

{% endif %} {% endblock %} diff --git a/rest_framework_docs/views.py b/rest_framework_docs/views.py index f9919ff..3b0012b 100644 --- a/rest_framework_docs/views.py +++ b/rest_framework_docs/views.py @@ -17,7 +17,7 @@ def get_context_data(self, **kwargs): docs = ApiDocumentation() endpoints = docs.get_endpoints() - query = self.request.GET.get("q", None) + query = self.request.GET.get("search", "") if query and endpoints: endpoints = [endpoint for endpoint in endpoints if query in endpoint.path] From b7d4bc3100b20113ae08256893572929ce80326a Mon Sep 17 00:00:00 2001 From: Emmanouil Konstantinidis Date: Fri, 18 Dec 2015 21:42:49 +0000 Subject: [PATCH 3/3] Test search funcitonality --- tests/tests.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/tests.py b/tests/tests.py index ac0b4ef..b23b60d 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -40,6 +40,16 @@ def test_index_view_with_endpoints(self): # The view "OrganisationErroredView" (organisations/(?P[\w-]+)/errored/) should contain an error. self.assertEqual(str(response.context["endpoints"][8].errors), "'test_value'") + def test_index_search_with_endpoints(self): + url = "%s?search=reset-password" % reverse("drfdocs") + print(url) + response = self.client.get(url) + + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.context["endpoints"]), 2) + self.assertEqual(response.context["endpoints"][1].path, "/accounts/reset-password/confirm/") + self.assertEqual(len(response.context["endpoints"][1].fields), 3) + @override_settings(REST_FRAMEWORK_DOCS=SETTINGS_HIDE_DOCS) def test_index_view_docs_hidden(self): """