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

Nested serializers support #104

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
manosim merged 6 commits into manosim:master from HackSoftware:nested_serializers_support
Jun 30, 2016
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Handle KeyError in ApiEndpoint
  • Loading branch information
Ivaylo Bachvarof committed Jun 22, 2016
commit c38fe528fbf22ec289cb044509b197aaa59196bf
29 changes: 15 additions & 14 deletions rest_framework_docs/api_endpoint.py
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, pattern, parent_pattern=None):
self.errors = None
self.serializer_class = self.__get_serializer_class__()
if self.serializer_class:
self.serializer = self.serializer_class()
self.serializer = self.__get_serializer__()
self.fields = self.__get_serializer_fields__(self.serializer)
self.fields_json = self.__get_serializer_fields_json__()

Expand All @@ -40,6 +40,12 @@ def __get_permissions_class__(self):
for perm_class in self.pattern.callback.cls.permission_classes:
return perm_class.__name__

def __get_serializer__(self):
try:
return self.serializer_class()
except KeyError as e:
self.errors = e

def __get_serializer_class__(self):
if hasattr(self.callback.cls, 'serializer_class'):
return self.callback.cls.serializer_class
Expand All @@ -51,19 +57,14 @@ def __get_serializer_fields__(self, serializer):
fields = []

if hasattr(serializer, 'get_fields'):
try:
for key, field in serializer.get_fields().items():
sub_fields = self.__get_serializer_fields__(field) if isinstance(field, BaseSerializer) else None
fields.append({
"name": key,
"type": str(field.__class__.__name__),
"sub_fields": sub_fields,
"required": field.required
})
except KeyError as e:
self.errors = e
fields = []

for key, field in serializer.get_fields().items():
sub_fields = self.__get_serializer_fields__(field) if isinstance(field, BaseSerializer) else None
fields.append({
"name": key,
"type": str(field.__class__.__name__),
"sub_fields": sub_fields,
"required": field.required
})
# FIXME:
# Show more attibutes of `field`?

Expand Down

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