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 39
39
40
40
<!-- Collect the nav links, forms, and other content for toggling -->
41
41
< 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 ">
43
43
< 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 ">
45
45
</ div >
46
46
</ form >
47
47
< 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">
70
70
</ div >
71
71
72
72
{% endfor %}
73
- {% else %}
73
+ {% elif not query %}
74
74
< 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 >
75
77
{% endif %}
76
78
77
79
{% endblock %}
Original file line number Diff line number Diff line change @@ -15,5 +15,12 @@ def get_context_data(self, **kwargs):
15
15
16
16
context = super (DRFDocsView , self ).get_context_data (** kwargs )
17
17
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
19
26
return context
Original file line number Diff line number Diff line change @@ -40,6 +40,16 @@ def test_index_view_with_endpoints(self):
40
40
# The view "OrganisationErroredView" (organisations/(?P<slug>[\w-]+)/errored/) should contain an error.
41
41
self .assertEqual (str (response .context ["endpoints" ][8 ].errors ), "'test_value'" )
42
42
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
+
43
53
@override_settings (REST_FRAMEWORK_DOCS = SETTINGS_HIDE_DOCS )
44
54
def test_index_view_docs_hidden (self ):
45
55
"""
You can’t perform that action at this time.
0 commit comments