Skip to content

Commit ace28b5

Browse files
author
Emmanouil Konstantinidis
committed
List serialiser fields
1 parent 3987d57 commit ace28b5

File tree

5 files changed

+22
-11
lines changed

5 files changed

+22
-11
lines changed

rest_framework_docs/api_endpoint.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import inspect
23
from django.contrib.admindocs.views import simplify_regex
34

@@ -15,6 +16,7 @@ def __init__(self, pattern, parent_pattern=None):
1516
# self.view_name = pattern.callback.__name__
1617
self.errors = None
1718
self.fields = self.__get_serializer_fields__()
19+
self.fields_json = self.__get_serializer_fields_json__()
1820

1921
def __get_path__(self, parent_pattern):
2022
if parent_pattern:
@@ -47,3 +49,8 @@ def __get_serializer_fields__(self):
4749
# Show more attibutes of `field`?
4850

4951
return fields
52+
53+
def __get_serializer_fields_json__(self):
54+
# FIXME:
55+
# Return JSON or not?
56+
return json.dumps(self.fields)

rest_framework_docs/static/rest_framework_docs/css/style.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

rest_framework_docs/static/rest_framework_docs/js/index.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,14 @@ $( document ).ready(function() {
9494
};
9595

9696
var _setupFields = function (fields) {
97-
97+
$.each( fields, function( i, field ) {
98+
$('#fields').append("" +
99+
'<div class="form-group">' +
100+
'<label for="field' + field.name + '">' + field.name + '</label>' +
101+
'<input type="text" class="form-control" id="field' + field.name + '" placeholder="' + field.type + '">' +
102+
'</div>' +
103+
"");
104+
});
98105
};
99106

100107
var setupForm = function (data) {

rest_framework_docs/static/rest_framework_docs/less/style.less

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,9 @@ body {
194194
}
195195

196196
.fields {
197-
197+
label {
198+
text-transform: capitalize;
199+
}
198200
}
199201
}
200202

rest_framework_docs/templates/rest_framework_docs/home.html

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ <h4 class="panel-title title">
4545
data-toggle="modal"
4646
data-path="{{ endpoint.path }}"
4747
data-methods="{{ endpoint.allowed_methods }}"
48-
data-fields="{{ endpoint.fields }}">
48+
data-fields="{{ endpoint.fields_json }}">
4949
<i class="fa fa-plug"></i></li>
5050
</ul>
5151
</div>
@@ -98,7 +98,6 @@ <h4 class="modal-title">Live API Endpoints</h4>
9898

9999
<div class="row">
100100
<div class="col-md-6 request">
101-
102101
<h3>Request</h3>
103102
<form id="requestForm">
104103
<div class="form-group">
@@ -116,15 +115,11 @@ <h5>Headers</h5>
116115

117116
<h5>Data</h5>
118117
<div id="fields" class="fields"></div>
119-
<div class="form-group">
120-
<label for="exampleInputPassword1">Password</label>
121-
<input type="password" class="form-control" id="exampleInputPassword1" placeholder="Password">
122-
</div>
118+
123119
<button type="submit" class="btn btn-default">Send</button>
124120
</form>
125-
126-
127121
</div>
122+
128123
<div class="col-md-6 response">
129124
<h3>Response <span id="responseStatusCode" class="label status-code pull-right"></span></h3>
130125
<div><strong>Status Text</strong>: <span class="status-text" id="responseStatusText"></span></div>

0 commit comments

Comments
 (0)