|
4 | 4 | from rest_framework import parsers
|
5 | 5 | from rest_framework.exceptions import ParseError
|
6 | 6 |
|
7 |
| -from . import exceptions, renderers, serializers, utils |
8 |
| -from .settings import json_api_settings |
| 7 | +from rest_framework_json_api import exceptions, renderers, serializers |
| 8 | +from rest_framework_json_api.utils import get_resource_name, undo_format_field_names |
9 | 9 |
|
10 | 10 |
|
11 | 11 | class JSONParser(parsers.JSONParser):
|
@@ -37,27 +37,13 @@ class JSONParser(parsers.JSONParser):
|
37 | 37 |
|
38 | 38 | @staticmethod
|
39 | 39 | def parse_attributes(data):
|
40 |
| - attributes = data.get("attributes") |
41 |
| - uses_format_translation = json_api_settings.FORMAT_FIELD_NAMES |
42 |
| - |
43 |
| - if not attributes: |
44 |
| - return dict() |
45 |
| - elif uses_format_translation: |
46 |
| - # convert back to python/rest_framework's preferred underscore format |
47 |
| - return utils.format_field_names(attributes, "underscore") |
48 |
| - else: |
49 |
| - return attributes |
| 40 | + attributes = data.get("attributes") or dict() |
| 41 | + return undo_format_field_names(attributes) |
50 | 42 |
|
51 | 43 | @staticmethod
|
52 | 44 | def parse_relationships(data):
|
53 |
| - uses_format_translation = json_api_settings.FORMAT_FIELD_NAMES |
54 |
| - relationships = data.get("relationships") |
55 |
| - |
56 |
| - if not relationships: |
57 |
| - relationships = dict() |
58 |
| - elif uses_format_translation: |
59 |
| - # convert back to python/rest_framework's preferred underscore format |
60 |
| - relationships = utils.format_field_names(relationships, "underscore") |
| 45 | + relationships = data.get("relationships") or dict() |
| 46 | + relationships = undo_format_field_names(relationships) |
61 | 47 |
|
62 | 48 | # Parse the relationships
|
63 | 49 | parsed_relationships = dict()
|
@@ -130,7 +116,7 @@ def parse(self, stream, media_type=None, parser_context=None):
|
130 | 116 |
|
131 | 117 | # Check for inconsistencies
|
132 | 118 | if request.method in ("PUT", "POST", "PATCH"):
|
133 |
| - resource_name = utils.get_resource_name( |
| 119 | + resource_name = get_resource_name( |
134 | 120 | parser_context, expand_polymorphic_types=True
|
135 | 121 | )
|
136 | 122 | if isinstance(resource_name, str):
|
|
0 commit comments