File tree Expand file tree Collapse file tree 4 files changed +23
-4
lines changed
templates/rest_framework_docs Expand file tree Collapse file tree 4 files changed +23
-4
lines changed Original file line number Diff line number Diff line change 3939
4040 <!-- Collect the nav links, forms, and other content for toggling -->
4141 < div class ="collapse navbar-collapse " id ="drfdoc-navbar ">
42- < form class ="navbar-form navbar-right " role ="search ">
42+ < form method =" get " action =" . " class ="navbar-form navbar-right " role ="search ">
4343 < div class ="form-group ">
44- < input type ="text " class ="form-control " placeholder ="Search ">
44+ < input type ="text " class ="form-control " name =" search " value =" {{ query }} " placeholder ="Search ">
4545 </ div >
4646 </ form >
4747 < ul class ="nav navbar-nav navbar-right ">
Original file line number Diff line number Diff line change @@ -70,8 +70,10 @@ <h4 class="panel-title title">
7070 </ div >
7171
7272 {% endfor %}
73- {% else %}
73+ {% elif not query %}
7474 < h2 class ="text-center "> There are currently no api endpoints to document.</ h2 >
75+ {% else %}
76+ < h2 class ="text-center "> No endpoints found for {{ query }}.</ h2 >
7577 {% endif %}
7678
7779{% endblock %}
Original file line number Diff line number Diff line change @@ -15,5 +15,12 @@ def get_context_data(self, **kwargs):
1515
1616 context = super (DRFDocsView , self ).get_context_data (** kwargs )
1717 docs = ApiDocumentation ()
18- context ['endpoints' ] = docs .get_endpoints ()
18+ endpoints = docs .get_endpoints ()
19+
20+ query = self .request .GET .get ("search" , "" )
21+ if query and endpoints :
22+ endpoints = [endpoint for endpoint in endpoints if query in endpoint .path ]
23+
24+ context ['query' ] = query
25+ context ['endpoints' ] = endpoints
1926 return context
Original file line number Diff line number Diff line change @@ -40,6 +40,16 @@ def test_index_view_with_endpoints(self):
4040 # The view "OrganisationErroredView" (organisations/(?P<slug>[\w-]+)/errored/) should contain an error.
4141 self .assertEqual (str (response .context ["endpoints" ][8 ].errors ), "'test_value'" )
4242
43+ def test_index_search_with_endpoints (self ):
44+ url = "%s?search=reset-password" % reverse ("drfdocs" )
45+ print (url )
46+ response = self .client .get (url )
47+
48+ self .assertEqual (response .status_code , 200 )
49+ self .assertEqual (len (response .context ["endpoints" ]), 2 )
50+ self .assertEqual (response .context ["endpoints" ][1 ].path , "/accounts/reset-password/confirm/" )
51+ self .assertEqual (len (response .context ["endpoints" ][1 ].fields ), 3 )
52+
4353 @override_settings (REST_FRAMEWORK_DOCS = SETTINGS_HIDE_DOCS )
4454 def test_index_view_docs_hidden (self ):
4555 """
You can’t perform that action at this time.
0 commit comments