Skip to content

Commit dca59af

Browse files
committed
Docs: always consider section sub-documents
If the section has both links and sub-documents (nested routes), then both should be displayed.
1 parent ba091db commit dca59af

File tree

4 files changed

+27
-16
lines changed

4 files changed

+27
-16
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
{% load rest_framework %}
12
{% for section_key, section in items %}
23
{% if section_key %}
3-
<h{{level}} id="{{prefix}}{{ section_key }}" class="coredocs-section-title">{{ section_key }} <a href="#{{ section_key }}"><i class="fa fa-link" aria-hidden="true"></i>
4+
<h{{level}} id="{{prefix}}{{ section_key }}" class="coredocs-section-title">{{ section_key }} <a href="#{{ prefix }}{{ section_key }}"><i class="fa fa-link" aria-hidden="true"></i>
45
</a></h{{level}}>
56
{% endif %}
67

78
{% if section.links|items %}
89
{% for link_key, link in section.links|items %}
910
{% include "rest_framework/docs/link.html" with prefix=prefix level=level|add:1%}
1011
{% endfor %}
11-
{% else %}
12-
{% include 'rest_framework/docs/_recursive_document.html' with items=section|items prefix=prefix|add:section_key|add:'/' level=level|add:1 %}
1312
{% endif %}
13+
{% include 'rest_framework/docs/_recursive_document.html' with items=section.data|items prefix=prefix|add:section_key|add:'/' level=level|add:1 %}
1414
{% endfor %}
1515

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
{% load rest_framework %}
2+
{% if items %}
13
<ul id="{% if prefix %}{{prefix}}-dropdown{% else %}menu-content{% endif %}" class="menu-content collapse out">
24
{% for section_key, section in items %}
35
<li data-toggle="collapse" data-target="#{{prefix}}{{ section_key }}-dropdown" class="collapsed">
@@ -9,13 +11,12 @@
911
<li><a href="#{% if prefix %}{{prefix}}/{% endif %}{{ section_key }}-{{ link_key }}">{{ link.title|default:link_key }}</a></li>
1012
{% endfor %}
1113
</ul>
14+
{% endif %}
15+
{% if prefix %}
16+
{% include 'rest_framework/docs/_recursive_menu.html' with items=section.data|items prefix=prefix|add:'/'|add:section_key %}
1217
{% else %}
13-
{% if prefix %}
14-
{% include 'rest_framework/docs/_recursive_menu.html' with items=section|items prefix=prefix|add:'/'|add:section_key %}
15-
{% else %}
16-
{% include 'rest_framework/docs/_recursive_menu.html' with items=section|items prefix=section_key %}
17-
{% endif %}
18+
{% include 'rest_framework/docs/_recursive_menu.html' with items=section.data|items prefix=section_key %}
1819
{% endif %}
1920
{% endfor %}
2021
</ul>
21-
22+
{% endif %}

tests/interactive_doc/data.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from django.db import models
22
from rest_framework import serializers, viewsets
3+
from rest_framework.decorators import detail_route
34

45

56
class DummyModel(models.Model):
@@ -16,3 +17,7 @@ class Meta:
1617
class DummyViewSet(viewsets.ModelViewSet):
1718
serializer_class = DummySerializer
1819
queryset = DummyModel.objects.all()
20+
21+
@detail_route(methods=['get', 'post'])
22+
def retrieve_alt(self, request, *args, **kwargs):
23+
return self.retrieve(request, *args, **kwargs)

tests/interactive_doc/test_recursive_url.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,17 @@ def test_menu(self):
2727
)
2828

2929
def test_documentation(self):
30-
self.assertTrue(
31-
re.search('h2.*>not_dummies <a', self.content),
32-
'unable to find documentation section for not_dummies'
33-
)
34-
for model_type in ['aaaa', 'bbbb']:
30+
header_re = 'h{level}\s+id="{path}".*>{title} <a href="#{path}"'
31+
32+
for route in (('not_dummies',), ('dummy', 'aaaas'), ('dummy', 'bbbbs')):
33+
path = "/".join(route)
3534
self.assertTrue(
36-
re.search('h3.*>{}s <a'.format(model_type), self.content),
37-
'unable to find documentation section for dummy/{}'.format(model_type)
35+
re.search(header_re.format(level=1+len(route), path=path, title=route[-1]), self.content),
36+
'unable to find documentation section for {}'.format(path)
3837
)
38+
for method in ('read', 'create'):
39+
subpath = "{}/retrieve_alt-{}".format(path, method)
40+
self.assertTrue(
41+
re.search(header_re.format(level=3, path=subpath, title=method), self.content),
42+
'unable to find documentation section for {}'.format(subpath)
43+
)

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy