From a26d63345786f24aad753405c49822f89faa2093 Mon Sep 17 00:00:00 2001 From: Kevin Partington Date: Mon, 28 Dec 2020 09:27:10 -0600 Subject: [PATCH] Rename FORMAT_LINKS setting to FORMAT_RELATED_LINKS --- CHANGELOG.md | 2 +- docs/usage.md | 6 +++--- rest_framework_json_api/settings.py | 2 +- rest_framework_json_api/utils.py | 4 ++-- tests/test_relations.py | 8 ++++---- tests/test_utils.py | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 858fd8d9..13be06bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/docs/usage.md b/docs/usage.md index ca0ccd22..81e52989 100644 --- a/docs/usage.md +++ b/docs/usage.md @@ -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: @@ -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 diff --git a/rest_framework_json_api/settings.py b/rest_framework_json_api/settings.py index e7cc3711..0e790847 100644 --- a/rest_framework_json_api/settings.py +++ b/rest_framework_json_api/settings.py @@ -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, } diff --git a/rest_framework_json_api/utils.py b/rest_framework_json_api/utils.py index 7b211207..c87fa000 100644 --- a/rest_framework_json_api/utils.py +++ b/rest_framework_json_api/utils.py @@ -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) diff --git a/tests/test_relations.py b/tests/test_relations.py index e9f3800b..2565542f 100644 --- a/tests/test_relations.py +++ b/tests/test_relations.py @@ -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"), @@ -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") diff --git a/tests/test_utils.py b/tests/test_utils.py index 449f515e..f542ad7d 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -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