File tree Expand file tree Collapse file tree 7 files changed +352
-9
lines changed
static/rest_framework/docs/js
templates/rest_framework/docs Expand file tree Collapse file tree 7 files changed +352
-9
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,14 @@ var responseDisplay = 'data'
2
2
var coreapi = window . coreapi
3
3
var schema = window . schema
4
4
5
+ function normalizeKeys ( arr ) {
6
+ var _normarr = [ ] ;
7
+ for ( var i = 0 ; i < arr . length ; i ++ ) {
8
+ _normarr = _normarr . concat ( arr [ i ] . split ( ' > ' ) ) ;
9
+ }
10
+ return _normarr ;
11
+ }
12
+
5
13
function normalizeHTTPHeader ( str ) {
6
14
// Capitalize HTTP headers for display.
7
15
return ( str . charAt ( 0 ) . toUpperCase ( ) + str . substring ( 1 ) )
@@ -94,7 +102,7 @@ $(function () {
94
102
var $requestAwaiting = $form . find ( '.request-awaiting' )
95
103
var $responseRaw = $form . find ( '.response-raw' )
96
104
var $responseData = $form . find ( '.response-data' )
97
- var key = $form . data ( 'key' )
105
+ var key = normalizeKeys ( $form . data ( 'key' ) )
98
106
var params = { }
99
107
var entries = formEntries ( $form . get ( ) [ 0 ] )
100
108
@@ -212,7 +220,6 @@ $(function () {
212
220
}
213
221
214
222
var client = new coreapi . Client ( options )
215
-
216
223
client . action ( schema , key , params ) . then ( function ( data ) {
217
224
var response = JSON . stringify ( data , null , 2 )
218
225
$requestAwaiting . addClass ( 'hide' )
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ <h2 id="{{ section_key }}" class="coredocs-section-title">{{ section_key }} <a h
20
20
</ a > </ h2 >
21
21
{% endif %}
22
22
23
- {% for link_key, link in section.links |items %}
23
+ {% for link_key, link in section|schema_links |items %}
24
24
{% include "rest_framework/docs/link.html" %}
25
25
{% endfor %}
26
26
{% endfor %}
Original file line number Diff line number Diff line change 1
1
{% load rest_framework %}
2
2
3
3
<!-- Modal -->
4
- < div class ="modal fade api-modal " id ="{{ section_key }}_{{ link_key }}_modal " tabindex ="-1 " role ="dialog " aria-labelledby ="api explorer modal ">
4
+ < div class ="modal fade api-modal " id ="{{ section_key }}_{{ link_key|slugify }}_modal " tabindex ="-1 " role ="dialog " aria-labelledby ="api explorer modal ">
5
5
< div class ="modal-dialog modal-lg " role ="document ">
6
6
< div class ="modal-content ">
7
7
< div class ="modal-header ">
Original file line number Diff line number Diff line change 6
6
class ="btn btn-sm btn-success "
7
7
style ="float: right; margin-top: 20px "
8
8
data-toggle ="modal "
9
- data-target ="#{{ section_key }}_{{ link_key }}_modal ">
9
+ data-target ="#{{ section_key }}_{{ link_key|slugify }}_modal ">
10
10
< i class ="fa fa-exchange "> </ i > Interact
11
11
</ button >
12
12
13
- < h3 id ="{{ section_key }}-{{ link_key }} " class ="coredocs-link-title "> {{ link.title|default:link_key }} < a href ="#{{ section_key }}-{{ link_key }} "> < i class ="fa fa-link " aria-hidden ="true "> </ i >
13
+ < h3 id ="{{ section_key }}-{{ link_key|slugify }} " class ="coredocs-link-title "> {{ link.title|default:link_key }} < a href ="#{{ section_key }}-{{ link_key|slugify }} "> < i class ="fa fa-link " aria-hidden ="true "> </ i >
14
14
</ a > </ h3 >
15
15
16
16
< div class ="meta ">
Original file line number Diff line number Diff line change @@ -10,8 +10,8 @@ <h3 class="brand"><a href="#">{{ document.title }}</a></h3>
10
10
< li data-toggle ="collapse " data-target ="#{{ section_key }}-dropdown " class ="collapsed ">
11
11
< a > < i class ="fa fa-dot-circle-o fa-lg "> </ i > {% if section_key %}{{ section_key }}{% else %}API Endpoints{% endif %} < span class ="arrow "> </ span > </ a >
12
12
< ul class ="sub-menu {% if section_key %}collapse{% endif %} " id ="{{ section_key }}-dropdown ">
13
- {% for link_key, link in section.links |items %}
14
- < li > < a href ="#{{ section_key }}-{{ link_key }} "> {{ link.title|default:link_key }}</ a > </ li >
13
+ {% for link_key, link in section|schema_links |items %}
14
+ < li > < a href ="#{{ section_key }}-{{ link_key|slugify }} "> {{ link.title|default:link_key }}</ a > </ li >
15
15
{% endfor %}
16
16
</ ul >
17
17
</ li >
Original file line number Diff line number Diff line change @@ -244,6 +244,29 @@ def items(value):
244
244
return value .items ()
245
245
246
246
247
+ @register .filter
248
+ def schema_links (section , sec_key = None ):
249
+ """
250
+ Recursively find every link in a schema, even nested.
251
+ """
252
+ NESTED_FORMAT = '%s > %s' # this format is used in docs/js/api.js:normalizeKeys
253
+ links = section .links
254
+ if section .data :
255
+ data = section .data .items ()
256
+ for sub_section_key , sub_section in data :
257
+ new_links = schema_links (sub_section , sec_key = sub_section_key )
258
+ links .update (new_links )
259
+
260
+ if sec_key is not None :
261
+ new_links = OrderedDict ()
262
+ for link_key , link in links .items ():
263
+ new_key = NESTED_FORMAT % (sec_key , link_key )
264
+ new_links .update ({new_key : link })
265
+ return new_links
266
+
267
+ return links
268
+
269
+
247
270
@register .filter
248
271
def add_nested_class (value ):
249
272
if isinstance (value , dict ):
You can’t perform that action at this time.
0 commit comments