Skip to content

Rename FORMAT_LINKS setting to FORMAT_RELATED_LINKS #878

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
merged 1 commit into from
Dec 29, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ any parts of the framework not mentioned in the documentation should generally b
### Added

* Ability for the user to select `included_serializers` to apply when using `BrowsableAPI`, based on available `included_serializers` defined for the current endpoint.
* Ability for the user to format serializer properties in URL segments using the `JSON_API_FORMAT_LINKS` setting.
* Ability for the user to format serializer properties in URL segments using the `JSON_API_FORMAT_RELATED_LINKS` setting.

### Fixed

Expand Down
6 changes: 3 additions & 3 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -479,10 +479,10 @@ When set to pluralize:

#### Related URL segments

Serializer properties in relationship and related resource URLs may be infected using the `JSON_API_FORMAT_LINKS` setting.
Serializer properties in relationship and related resource URLs may be infected using the `JSON_API_FORMAT_RELATED_LINKS` setting.

``` python
JSON_API_FORMAT_LINKS = 'dasherize'
JSON_API_FORMAT_RELATED_LINKS = 'dasherize'
```

For example, with a serializer property `created_by` and with `'dasherize'` formatting:
Expand Down Expand Up @@ -513,7 +513,7 @@ For example, with a serializer property `created_by` and with `'dasherize'` form
}
```

The relationship name is formatted by the `JSON_API_FORMAT_FIELD_NAMES` setting, but the URL segments are formatted by the `JSON_API_FORMAT_LINKS` setting.
The relationship name is formatted by the `JSON_API_FORMAT_FIELD_NAMES` setting, but the URL segments are formatted by the `JSON_API_FORMAT_RELATED_LINKS` setting.

### Related fields

Expand Down
2 changes: 1 addition & 1 deletion rest_framework_json_api/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
DEFAULTS = {
"FORMAT_FIELD_NAMES": False,
"FORMAT_TYPES": False,
"FORMAT_LINKS": False,
"FORMAT_RELATED_LINKS": False,
"PLURALIZE_TYPES": False,
"UNIFORM_EXCEPTIONS": False,
}
Expand Down
4 changes: 2 additions & 2 deletions rest_framework_json_api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,12 +151,12 @@ def format_resource_type(value, format_type=None, pluralize=None):
def format_link_segment(value, format_type=None):
"""
Takes a string value and returns it with formatted keys as set in `format_type`
or `JSON_API_FORMAT_LINKS`.
or `JSON_API_FORMAT_RELATED_LINKS`.

:format_type: Either 'dasherize', 'camelize', 'capitalize' or 'underscore'
"""
if format_type is None:
format_type = json_api_settings.FORMAT_LINKS
format_type = json_api_settings.FORMAT_RELATED_LINKS

return format_value(value, format_type)

Expand Down
8 changes: 4 additions & 4 deletions tests/test_relations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

@pytest.mark.urls(__name__)
@pytest.mark.parametrize(
"format_links,expected_url_segment",
"format_related_links,expected_url_segment",
[
(None, "relatedField_name"),
("dasherize", "related-field-name"),
Expand All @@ -19,10 +19,10 @@
("underscore", "related_field_name"),
],
)
def test_relationship_urls_respect_format_links(
settings, format_links, expected_url_segment
def test_relationship_urls_respect_format_related_links_setting(
settings, format_related_links, expected_url_segment
):
settings.JSON_API_FORMAT_LINKS = format_links
settings.JSON_API_FORMAT_RELATED_LINKS = format_related_links

model = BasicModel(text="Some text")

Expand Down
2 changes: 1 addition & 1 deletion tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def test_format_field_names(settings, format_type, output):
],
)
def test_format_field_segment(settings, format_type, output):
settings.JSON_API_FORMAT_LINKS = format_type
settings.JSON_API_FORMAT_RELATED_LINKS = format_type
assert format_link_segment("first_Name") == output


Expand Down