File tree Expand file tree Collapse file tree 3 files changed +25
-2
lines changed
templates/rest_framework/docs Expand file tree Collapse file tree 3 files changed +25
-2
lines changed 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 @@ -10,7 +10,7 @@ <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 %}
13
+ {% for link_key, link in section|schema_links |items %}
14
14
< li > < a href ="#{{ section_key }}-{{ link_key }} "> {{ link.title|default:link_key }}</ a > </ li >
15
15
{% endfor %}
16
16
</ ul >
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'
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