Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 019a258

Browse files
committed
Merge branch 'master' into patch-1
2 parents fd5213e + 411eb1f commit 019a258

File tree

9 files changed

+78
-19
lines changed

9 files changed

+78
-19
lines changed

‎.travis.yml‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,14 @@ env:
1111
- DJANGO_VERSION=1.8
1212
- DJANGO_VERSION=1.9
1313

14+
cache:
15+
- pip
16+
- directories:
17+
- rest_framework_docs/static/node_modules/
18+
19+
before_install:
20+
- nvm install 5
21+
1422
install:
1523
- cd rest_framework_docs/static/ && npm install && cd ../../
1624
- pip install -r requirements.txt

‎codecov.yml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
coverage:
2+
precision: 2
3+
round: down
4+
range: "70...100"
5+
6+
status:
7+
project: false
8+
patch: false
9+
changes: false
10+
11+
comment: off

‎docs/changelog.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ title: "Changelog"
33
source_filename: "changelog"
44
---
55

6+
### Release 0.0.10
7+
8+
- Use get_serializer_class for Views without serlaizer_class attribute [#92](https://github.com/ekonstantinidis/django-rest-framework-docs/pull/92)
9+
10+
611
### Release 0.0.9
712

813
- Support for more types of `ROOT_URLCONF`

‎docs/templates.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ To hide the GitHub badge from the page, just override it with an empty block.
3636
{% block jumbotron %}
3737
<div class="jumbotron">
3838
<h1>Project Title</h1>
39-
<h3>Documentantion of the project 'Example'.</h3>
39+
<h3>Documentation of the project 'Example'.</h3>
4040
</div>
4141
{% endblock %}
4242

@@ -65,7 +65,7 @@ File location: `templates/rest_framework_docs/docs.html`
6565
{% block jumbotron %}
6666
<div class="jumbotron">
6767
<h1>'Project Name' Web API</h1>
68-
<h3>Documentantion of the 'Project Name' Web API.</h3>
68+
<h3>Documentation of the 'Project Name' Web API.</h3>
6969
</div>
7070
{% endblock %}
7171

‎rest_framework_docs/__init__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '0.0.9'
1+
__version__ = '0.0.10'

‎rest_framework_docs/api_endpoint.py‎

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,27 @@ def __get_permissions_class__(self):
3737

3838
def __get_serializer_fields__(self):
3939
fields = []
40+
serializer = None
4041

41-
if hasattr(self.callback.cls, 'serializer_get_fields'):
42+
if hasattr(self.callback.cls, 'serializer_class'):
4243
serializer = self.callback.cls.serializer_class
43-
if hasattr(serializer, 'get_fields'):
44-
try:
45-
fields = [{
46-
"name": key,
47-
"type": str(field.__class__.__name__),
48-
"required": field.required
49-
} for key, field in serializer().get_fields().items()]
50-
except KeyError as e:
51-
self.errors = e
52-
fields = []
53-
54-
# FIXME:
55-
# Show more attibutes of `field`?
44+
45+
elif hasattr(self.callback.cls, 'get_serializer_class'):
46+
serializer = self.callback.cls.get_serializer_class(self.pattern.callback.cls())
47+
48+
if hasattr(serializer, 'get_fields'):
49+
try:
50+
fields = [{
51+
"name": key,
52+
"type": str(field.__class__.__name__),
53+
"required": field.required
54+
} for key, field in serializer().get_fields().items()]
55+
except KeyError as e:
56+
self.errors = e
57+
fields = []
58+
59+
# FIXME:
60+
# Show more attibutes of `field`?
5661

5762
return fields
5863

‎tests/tests.py‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def test_index_view_with_endpoints(self):
2727
response = self.client.get(reverse('drfdocs'))
2828

2929
self.assertEqual(response.status_code, 200)
30-
self.assertEqual(len(response.context["endpoints"]), 10)
30+
self.assertEqual(len(response.context["endpoints"]), 11)
3131

3232
# Test the login view
3333
self.assertEqual(response.context["endpoints"][0].name_parent, "accounts")
@@ -38,8 +38,16 @@ def test_index_view_with_endpoints(self):
3838
self.assertEqual(response.context["endpoints"][0].fields[0]["type"], "CharField")
3939
self.assertTrue(response.context["endpoints"][0].fields[0]["required"])
4040

41+
self.assertEqual(response.context["endpoints"][1].name_parent, "accounts")
42+
self.assertEqual(response.context["endpoints"][1].allowed_methods, ['POST', 'OPTIONS'])
43+
self.assertEqual(response.context["endpoints"][1].path, "/accounts/login2/")
44+
self.assertEqual(response.context["endpoints"][1].docstring, "A view that allows users to login providing their username and password. Without serializer_class")
45+
self.assertEqual(len(response.context["endpoints"][1].fields), 2)
46+
self.assertEqual(response.context["endpoints"][1].fields[0]["type"], "CharField")
47+
self.assertTrue(response.context["endpoints"][1].fields[0]["required"])
48+
4149
# The view "OrganisationErroredView" (organisations/(?P<slug>[\w-]+)/errored/) should contain an error.
42-
self.assertEqual(str(response.context["endpoints"][8].errors), "'test_value'")
50+
self.assertEqual(str(response.context["endpoints"][9].errors), "'test_value'")
4351

4452
def test_index_search_with_endpoints(self):
4553
response = self.client.get("%s?search=reset-password" % reverse("drfdocs"))

‎tests/urls.py‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
accounts_urls = [
88
url(r'^login/$', views.LoginView.as_view(), name="login"),
9+
url(r'^login2/$', views.LoginWithSerilaizerClassView.as_view(), name="login2"),
910
url(r'^register/$', views.UserRegistrationView.as_view(), name="register"),
1011
url(r'^reset-password/$', view=views.PasswordResetView.as_view(), name="reset-password"),
1112
url(r'^reset-password/confirm/$', views.PasswordResetConfirmView.as_view(), name="reset-password-confirm"),

‎tests/views.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,24 @@ def delete(self, request, *args, **kwargs):
111111
class OrganisationErroredView(generics.ListAPIView):
112112

113113
serializer_class = serializers.OrganisationErroredSerializer
114+
115+
116+
class LoginWithSerilaizerClassView(APIView):
117+
"""
118+
A view that allows users to login providing their username and password. Without serializer_class
119+
"""
120+
121+
throttle_classes = ()
122+
permission_classes = ()
123+
parser_classes = (parsers.FormParser, parsers.MultiPartParser, parsers.JSONParser,)
124+
renderer_classes = (renderers.JSONRenderer,)
125+
126+
def post(self, request):
127+
serializer = self.serializer_class(data=request.data)
128+
serializer.is_valid(raise_exception=True)
129+
user = serializer.validated_data['user']
130+
token, created = Token.objects.get_or_create(user=user)
131+
return Response({'token': token.key})
132+
133+
def get_serializer_class(self):
134+
return AuthTokenSerializer

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /