-
Notifications
You must be signed in to change notification settings - Fork 301
Don't force translation of request attribute names #284
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
Jerel Unruh <[email protected]> | ||
Greg Aker <[email protected]> | ||
Adam Wróbel <https://adamwrobel.com> | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,8 @@ | |
from rest_framework import parsers | ||
from rest_framework.exceptions import ParseError | ||
|
||
from django.conf import settings | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you move this import line above the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've actually copied the style applied here from utils.py file: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, the style is a bit of a mess because it's not consistent. Don't worry about it. I created issue #344 after I left this comment above so it can be cleaned up in the future. I'll get this line later. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend using |
||
|
||
from . import utils, renderers, exceptions | ||
|
||
|
||
|
@@ -29,12 +31,27 @@ class JSONParser(parsers.JSONParser): | |
|
||
@staticmethod | ||
def parse_attributes(data): | ||
return utils.format_keys(data.get('attributes'), 'underscore') if data.get('attributes') else dict() | ||
attributes = data.get('attributes') | ||
uses_format_translation = getattr(settings, 'JSON_API_FORMAT_KEYS', False) | ||
|
||
if not attributes: | ||
return dict() | ||
elif uses_format_translation: | ||
# convert back to python/rest_framework's preferred underscore format | ||
return utils.format_keys(attributes, 'underscore') | ||
else: | ||
return attributes | ||
|
||
@staticmethod | ||
def parse_relationships(data): | ||
relationships = (utils.format_keys(data.get('relationships'), 'underscore') | ||
if data.get('relationships') else dict()) | ||
uses_format_translation = getattr(settings, 'JSON_API_FORMAT_KEYS', False) | ||
relationships = data.get('relationships') | ||
|
||
if not relationships: | ||
relationships = dict() | ||
elif uses_format_translation: | ||
# convert back to python/rest_framework's preferred underscore format | ||
relationships = utils.format_keys(relationships, 'underscore') | ||
|
||
# Parse the relationships | ||
parsed_relationships = dict() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks. I totally understand not wanting to put your email address. I don't like doing that either for the same reason you described. Thanks for adding your name.