Skip to content

Commit e866a41

Browse files
author
Maxence
committed
Use the endpoint's namespace into the group url
1 parent b774268 commit e866a41

File tree

3 files changed

+12
-8
lines changed

3 files changed

+12
-8
lines changed

rest_framework_docs/api_docs.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,4 @@ def _is_drf_view(self, pattern):
3232
return hasattr(pattern.callback, 'cls') and issubclass(pattern.callback.cls, APIView)
3333

3434
def get_endpoints(self):
35-
return sorted(self.endpoints, key=attrgetter('name_parent'))
35+
return sorted(self.endpoints, key=attrgetter('name'))

rest_framework_docs/api_endpoint.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,14 @@ def __init__(self, pattern, parent_pattern=None):
1313
if parent_pattern:
1414
self.name_parent = parent_pattern.namespace or parent_pattern.app_name or \
1515
simplify_regex(parent_pattern.regex.pattern).replace('/', '-')
16+
self.name = self.name_parent
1617
if hasattr(pattern.callback, 'cls') and issubclass(pattern.callback.cls, ModelViewSet):
17-
self.name_parent = '%s (REST)' % self.name_parent
18+
self.name = '%s (REST)' % self.name_parent
1819
else:
1920
self.name_parent = ''
21+
self.name = ''
22+
# self.labels = (self.name_parent, self.name, slugify(self.name))
23+
self.labels = dict(parent=self.name_parent, name=self.name)
2024
self.path = self.__get_path__(parent_pattern)
2125
self.allowed_methods = self.__get_allowed_methods__()
2226
self.errors = None

rest_framework_docs/templates/rest_framework_docs/home.html

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{% extends "rest_framework_docs/docs.html" %}
22

33
{% block apps_menu %}
4-
{% regroup endpoints by name_parent as endpoints_grouped %}
4+
{% regroup endpoints by labels as endpoints_grouped %}
55
{% if endpoints_grouped|length > 1 %}
66
<li class="dropdown">
77
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Jump To <span class="caret"></span></a>
88
<ul class="dropdown-menu">
99
{% for group in endpoints_grouped %}
10-
<li><a href="#{{ group.grouper|lower }}-group">{{ group.grouper }}</a></li>
10+
<li><a href="#{{ group.grouper.name|slugify }}-group">{{ group.grouper.name }}</a></li>
1111
{% endfor %}
1212
</ul>
1313
</li>
@@ -16,12 +16,12 @@
1616

1717

1818
{% block content %}
19-
{% regroup endpoints by name_parent as endpoints_grouped %}
19+
{% regroup endpoints by labels as endpoints_grouped %}
2020
{% if endpoints_grouped %}
2121
{% for group in endpoints_grouped %}
22-
<h1 id="{{ group.grouper|lower }}-group">
23-
{% if group.grouper %}
24-
<a href="{% url 'drfdocs-filter' group.grouper %}">{{group.grouper}}</a>
22+
<h1 id="{{ group.grouper.name|slugify }}-group">
23+
{% if group.grouper.parent %}
24+
<a href="{% url 'drfdocs-filter' group.grouper.parent %}">{{ group.grouper.name }}</a>
2525
{% endif %}
2626
</h1>
2727

0 commit comments

Comments
 (0)