Skip to content

Commit 084b2f6

Browse files
author
Emmanouil Konstantinidis
committed
Get list of methods
1 parent 13443fb commit 084b2f6

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

drfdocs/api_endpoint.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,17 @@ class ApiEndpoint(object):
55

66
def __init__(self, pattern, parent_pattern=None):
77
self.pattern = pattern
8+
self.callback = pattern.callback
89
self.name = pattern.name
9-
self.path = self._get_path(parent_pattern)
10-
self.view_name = pattern.callback.__name__
10+
self.path = self.__get_path__(parent_pattern)
11+
self.allowed_methods = self.__get_allowed_methods__()
12+
# self.view_name = pattern.callback.__name__
1113

12-
def _get_path(self, parent_pattern):
14+
def __get_path__(self, parent_pattern):
1315
if parent_pattern:
1416
parent_path = simplify_regex(parent_pattern.regex.pattern)[:-1]
1517
return "{0}{1}".format(parent_path, simplify_regex(self.pattern.regex.pattern))
1618
return simplify_regex(self.pattern.regex.pattern)
19+
20+
def __get_allowed_methods__(self):
21+
return [m.upper() for m in self.callback.cls.http_method_names if hasattr(self.callback.cls, m)]

drfdocs/static/css/style.css

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ body {
2222

2323
.endpoint .title {
2424
font-family: Menlo,Monaco,Consolas,"Courier New",monospace;
25+
word-wrap: break-word;
2526
}
2627

2728
/* @end Endpoint */

drfdocs/templates/drfdocs/home.html

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ <h2>API Endpoints</h2>
66
{% for endpoint in endpoints %}
77
<div class="endpoint">
88
<h3 class="title">{{ endpoint.path }}</h3>
9+
<ul class="list-inline methods">
10+
{% for method in endpoint.allowed_methods %}
11+
<li class="method">{{ method }}</li>
12+
{% endfor %}
13+
</ul>
914
<p>View Name: {{ endpoint.view_name }}</p>
1015
<p>URL Name: {{ endpoint.name }}</p>
1116
</div>

0 commit comments

Comments
 (0)