mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-02-25 16:00:49 +03:00
Fix docs multiple nested and multiple methods
This commit is contained in:
parent
3110635685
commit
ed38371c3a
|
@ -20,7 +20,7 @@
|
||||||
</a></h2>
|
</a></h2>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
{% for link_key, link in section.links|items %}
|
{% for link_key, link in section|schema_links|items %}
|
||||||
{% include "rest_framework/docs/link.html" %}
|
{% include "rest_framework/docs/link.html" %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
<li data-toggle="collapse" data-target="#{{ section_key }}-dropdown" class="collapsed">
|
<li data-toggle="collapse" data-target="#{{ section_key }}-dropdown" class="collapsed">
|
||||||
<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>
|
<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>
|
||||||
<ul class="sub-menu {% if section_key %}collapse{% endif %}" id="{{ section_key }}-dropdown">
|
<ul class="sub-menu {% if section_key %}collapse{% endif %}" id="{{ section_key }}-dropdown">
|
||||||
{% for link_key, link in section.links|items %}
|
{% for link_key, link in section|schema_links|items %}
|
||||||
<li><a href="#{{ section_key }}-{{ link_key }}">{{ link.title|default:link_key }}</a></li>
|
<li><a href="#{{ section_key }}-{{ link_key }}">{{ link.title|default:link_key }}</a></li>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -244,6 +244,29 @@ def items(value):
|
||||||
return value.items()
|
return value.items()
|
||||||
|
|
||||||
|
|
||||||
|
@register.filter
|
||||||
|
def schema_links(section, sec_key=None):
|
||||||
|
"""
|
||||||
|
Recursively find every link in a schema, even nested.
|
||||||
|
"""
|
||||||
|
NESTED_FORMAT = '%s > %s'
|
||||||
|
links = section.links
|
||||||
|
if section.data:
|
||||||
|
data = section.data.items()
|
||||||
|
for sub_section_key, sub_section in data:
|
||||||
|
new_links = schema_links(sub_section, sec_key=sub_section_key)
|
||||||
|
links.update(new_links)
|
||||||
|
|
||||||
|
if sec_key is not None:
|
||||||
|
new_links = OrderedDict()
|
||||||
|
for link_key, link in links.items():
|
||||||
|
new_key = NESTED_FORMAT % (sec_key, link_key)
|
||||||
|
new_links.update({new_key: link})
|
||||||
|
return new_links
|
||||||
|
|
||||||
|
return links
|
||||||
|
|
||||||
|
|
||||||
@register.filter
|
@register.filter
|
||||||
def add_nested_class(value):
|
def add_nested_class(value):
|
||||||
if isinstance(value, dict):
|
if isinstance(value, dict):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user