Skip to content

Commit be05b9d

Browse files
author
Emmanouil Konstantinidis
committed
List docstrings of endpoints
1 parent fdecdfb commit be05b9d

File tree

6 files changed

+29
-4
lines changed

6 files changed

+29
-4
lines changed

demo/project/accounts/views.py

+6
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class TestView(TemplateView):
2020

2121

2222
class LoginView(APIView):
23+
"""
24+
A view that allows users to login providing their username and password.
25+
"""
2326

2427
throttle_classes = ()
2528
permission_classes = ()
@@ -42,6 +45,9 @@ class UserRegistrationView(generics.CreateAPIView):
4245

4346

4447
class UserProfileView(generics.RetrieveUpdateAPIView):
48+
"""
49+
An endpoint for users to view and update their profile information.
50+
"""
4551

4652
serializer_class = UserProfileSerializer
4753

rest_framework_docs/api_endpoint.py

+4
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ def __init__(self, pattern, parent_pattern=None):
77
self.pattern = pattern
88
self.callback = pattern.callback
99
# self.name = pattern.name
10+
self.docstring = self.__get_docstring__()
1011
self.name_parent = simplify_regex(parent_pattern.regex.pattern).replace('/', '') if parent_pattern else None
1112
self.path = self.__get_path__(parent_pattern)
1213
self.allowed_methods = self.__get_allowed_methods__()
@@ -22,6 +23,9 @@ def __get_path__(self, parent_pattern):
2223
def __get_allowed_methods__(self):
2324
return [m.upper() for m in self.callback.cls.http_method_names if hasattr(self.callback.cls, m)]
2425

26+
def __get_docstring__(self):
27+
return self.callback.cls.__doc__
28+
2529
def __get_serializer_fields__(self):
2630
fields = []
2731

rest_framework_docs/static/css/style.css

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rest_framework_docs/static/less/style.less

+12
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,22 @@ body {
9292
.panel-body {
9393
padding: 0;
9494

95+
.lead {
96+
margin-bottom: 5px;
97+
}
98+
9599
.alert {
96100
padding: 5px 10px;
97101
margin-top: 10px;
98102
}
103+
104+
.fields-desc {
105+
margin-bottom: 5px;
106+
}
107+
108+
.fields {
109+
list-style-type: square;
110+
}
99111
}
100112

101113
> .panel-heading +.panel-collapse > .panel-body { border: 0; }

rest_framework_docs/static/package.json

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@
2020
"django",
2121
"rest",
2222
"framework",
23-
"docs",
24-
"jekyll"
23+
"docs"
2524
],
2625
"author": "Emmanouil Konstantinidis",
2726
"license": "SEE LICENSE IN LICENSE",

rest_framework_docs/templates/rest_framework_docs/home.html

+5-1
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,16 @@ <h4 class="panel-title title">
4848

4949
<div id="{{ endpoint.path|slugify }}" class="panel-collapse collapse" role="tabpanel">
5050
<div class="panel-body">
51+
{% if endpoint.docstring %}
52+
<p class="lead">{{ endpoint.docstring }}</p>
53+
{% endif %}
54+
5155
{% if endpoint.errors %}
5256
<div class="alert alert-danger" role="alert">Oops! There was something wrong with {{ endpoint.errors }}. Please check your code.</div>
5357
{% endif %}
5458

5559
{% if endpoint.fields %}
56-
<p>Fields:</p>
60+
<p class="fields-desc">Fields:</p>
5761
<ul class="list fields">
5862
{% for field in endpoint.fields %}
5963
<li class="field">{{ field.name }}: {{ field.type }} {% if field.required %}<span class="label label-primary label-required" title="Required">R</span>{% endif %}</li>

0 commit comments

Comments
 (0)