Movatterモバイル変換


[0]ホーム

URL:


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

New field to exclude APIViews from endpoint list#90

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
dschien wants to merge2 commits intomanosim:master
base:master
Choose a base branch
Loading
fromdschien:master
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletionsrequirements.txt
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -3,3 +3,4 @@ djangorestframework==3.3.2
coverage==4.0.3
flake8==2.5.1
mkdocs==0.15.3
django-markdown2==2.3.1
3 changes: 2 additions & 1 deletionrest_framework_docs/api_docs.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -27,7 +27,8 @@ def get_all_view_names(self, urlpatterns, parent_pattern=None):
self.get_all_view_names(urlpatterns=pattern.url_patterns, parent_pattern=parent_pattern)
elif isinstance(pattern, RegexURLPattern) and self._is_drf_view(pattern) and not self._is_format_endpoint(pattern):
api_endpoint = ApiEndpoint(pattern, parent_pattern)
self.endpoints.append(api_endpoint)
if not api_endpoint.exclude:
self.endpoints.append(api_endpoint)

def _is_drf_view(self, pattern):
"""
Expand Down
15 changes: 7 additions & 8 deletionsrest_framework_docs/api_endpoint.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,7 +5,6 @@


class ApiEndpoint(object):

def __init__(self, pattern, parent_pattern=None):
self.pattern = pattern
self.callback = pattern.callback
Expand All@@ -19,6 +18,7 @@ def __init__(self, pattern, parent_pattern=None):
self.fields = self.__get_serializer_fields__()
self.fields_json = self.__get_serializer_fields_json__()
self.permissions = self.__get_permissions_class__()
self.exclude = getattr(self.callback.cls, 'drfdocs_exclude', False)

def __get_path__(self, parent_pattern):
if parent_pattern:
Expand All@@ -42,17 +42,16 @@ def __get_serializer_fields__(self):
serializer = self.callback.cls.serializer_class
if hasattr(serializer, 'get_fields'):
try:
fields = [{
"name": key,
"type": str(field.__class__.__name__),
"required": field.required
} for key, field in serializer().get_fields().items()]
fields = [{"name": key,
"type": str(field.__class__.__name__),
"required": field.required
} for key, field in serializer().get_fields().items()]
except KeyError as e:
self.errors = e
fields = []

# FIXME:
# Show more attibutes of `field`?
# FIXME:
# Show more attibutes of `field`?

return fields

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
{% extends "rest_framework_docs/docs.html" %}
{% load md2 %}

{% block apps_menu %}
{% regroup endpoints by name_parent as endpoints_grouped %}
Expand DownExpand Up@@ -56,7 +57,7 @@ <h4 class="panel-title title">
<div id="{{ endpoint.path|slugify }}" class="panel-collapse collapse" role="tabpanel">
<div class="panel-body">
{% if endpoint.docstring %}
<p class="lead">{{ endpoint.docstring }}</p>
<div class="lead">{{ endpoint.docstring| markdown:"code-friendly, code-color"}}</div>
{% endif %}

{% if endpoint.errors %}
Expand All@@ -71,7 +72,7 @@ <h4 class="panel-title title">
{% endfor %}
</ul>
{% elif not endpoint.errors %}
<p>No fields.</p>
<!--<p>No fields.</p>-->
{% endif %}
</div>
</div>
Expand Down
5 changes: 2 additions & 3 deletionstests/tests.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,6 @@


class DRFDocsViewTests(TestCase):

SETTINGS_HIDE_DOCS = {
'HIDE_DOCS': True # Default: False
}
Expand All@@ -13,7 +12,6 @@ def setUp(self):
super(DRFDocsViewTests, self).setUp()

def test_settings_module(self):

settings = DRFSettings()

self.assertEqual(settings.get_setting("HIDE_DOCS"), False)
Expand All@@ -33,7 +31,8 @@ def test_index_view_with_endpoints(self):
self.assertEqual(response.context["endpoints"][0].name_parent, "accounts")
self.assertEqual(response.context["endpoints"][0].allowed_methods, ['POST', 'OPTIONS'])
self.assertEqual(response.context["endpoints"][0].path, "/accounts/login/")
self.assertEqual(response.context["endpoints"][0].docstring, "A view that allows users to login providing their username and password.")
self.assertEqual(response.context["endpoints"][0].docstring,
"A view that allows users to login providing their username and password.")
self.assertEqual(len(response.context["endpoints"][0].fields), 2)
self.assertEqual(response.context["endpoints"][0].fields[0]["type"], "CharField")
self.assertTrue(response.context["endpoints"][0].fields[0]["required"])
Expand Down
1 change: 1 addition & 0 deletionstests/urls.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -13,6 +13,7 @@
url(r'^user/profile/$', views.UserProfileView.as_view(), name="profile"),

url(r'^test/$', views.TestView.as_view(), name="test-view"),
url(r'^exclude/$', views.ExcludedTestView.as_view(), name="test-exclude"),
]

organisations_urls = [
Expand Down
16 changes: 8 additions & 8 deletionstests/views.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -19,11 +19,18 @@ class TestView(TemplateView):
template_name = "a_test.html"


class ExcludedTestView(APIView):
"""
This view should not be included in DRF Docs.
"""
drfdocs_exclude = True


class LoginView(APIView):
"""
A view that allows users to login providing their username and password.
"""

drfdocs_exclude = False
throttle_classes = ()
permission_classes = ()
parser_classes = (parsers.FormParser, parsers.MultiPartParser, parsers.JSONParser,)
Expand All@@ -39,7 +46,6 @@ def post(self, request):


class UserRegistrationView(generics.CreateAPIView):

permission_classes = (AllowAny,)
serializer_class = serializers.UserRegistrationSerializer

Expand All@@ -56,7 +62,6 @@ def get_object(self):


class PasswordResetView(APIView):

permission_classes = (AllowAny,)
queryset = User.objects.all()

Expand All@@ -72,7 +77,6 @@ def post(self, request, *args, **kwargs):


class PasswordResetConfirmView(APIView):

permission_classes = (AllowAny,)
serializer_class = serializers.ResetPasswordSerializer

Expand All@@ -84,12 +88,10 @@ def post(self, request, *args, **kwargs):


class CreateOrganisationView(generics.CreateAPIView):

serializer_class = serializers.CreateOrganisationSerializer


class OrganisationMembersView(generics.ListAPIView):

serializer_class = serializers.OrganisationMembersSerializer

def get_queryset(self):
Expand All@@ -98,7 +100,6 @@ def get_queryset(self):


class LeaveOrganisationView(generics.DestroyAPIView):

def get_object(self):
return Membership.objects.order_by('?').first()

Expand All@@ -109,5 +110,4 @@ def delete(self, request, *args, **kwargs):


class OrganisationErroredView(generics.ListAPIView):

serializer_class = serializers.OrganisationErroredSerializer

[8]ページ先頭

©2009-2025 Movatter.jp