diff options
| author | Christopher Paolini | 2013-08-16 13:23:04 -0400 |
|---|---|---|
| committer | Christopher Paolini | 2013-08-16 13:23:04 -0400 |
| commit | a95984e4d4b034c196d40f74fbdc6345e6d4124c (patch) | |
| tree | 794063fa0503b5d8b39010c4a7c98eb5421c8264 /rest_framework/utils | |
| parent | d07dae6e79d53fdcfc7d88e085fe7e6da97c9c74 (diff) | |
| download | django-rest-framework-a95984e4d4b034c196d40f74fbdc6345e6d4124c.tar.bz2 | |
Settings now have default functions
Updated the setting to have a default function.
Diffstat (limited to 'rest_framework/utils')
| -rw-r--r-- | rest_framework/utils/formatting.py | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/rest_framework/utils/formatting.py b/rest_framework/utils/formatting.py index c908ce66..4f59f659 100644 --- a/rest_framework/utils/formatting.py +++ b/rest_framework/utils/formatting.py @@ -49,39 +49,15 @@ def _camelcase_to_spaces(content): def get_view_name(cls, suffix=None): """ Return a formatted name for an `APIView` class or `@api_view` function. - If a VIEW_NAME_FUNCTION is set in settings the value of that will be used - if that value is "falsy" then the normal formatting will be used. """ - if api_settings.VIEW_NAME_FUNCTION: - name = api_settings.VIEW_NAME_FUNCTION(cls, suffix) - if name: - return name - - name = cls.__name__ - name = _remove_trailing_string(name, 'View') - name = _remove_trailing_string(name, 'ViewSet') - name = _camelcase_to_spaces(name) - if suffix: - name += ' ' + suffix - return name + return api_settings.VIEW_NAME_FUNCTION(cls, suffix) def get_view_description(cls, html=False): """ Return a description for an `APIView` class or `@api_view` function. - If a VIEW_DESCRIPTION_FUNCTION is set in settings the value of that will be used - if that value is "falsy" then the normal formatting will be used. """ - if api_settings.VIEW_DESCRIPTION_FUNCTION: - description = api_settings.VIEW_DESCRIPTION_FUNCTION(cls) - if description: - return markup_description(description) - - description = cls.__doc__ or '' - description = _remove_leading_indent(smart_text(description)) - if html: - return markup_description(description) - return description + return api_settings.VIEW_DESCRIPTION_FUNCTION(cls) def markup_description(description): @@ -93,3 +69,21 @@ def markup_description(description): else: description = escape(description).replace('\n', '<br />') return mark_safe(description) + + +def view_name(cls, suffix=None): + name = cls.__name__ + name = _remove_trailing_string(name, 'View') + name = _remove_trailing_string(name, 'ViewSet') + name = _camelcase_to_spaces(name) + if suffix: + name += ' ' + suffix + + return name + +def view_description(cls, html=False): + description = cls.__doc__ or '' + description = _remove_leading_indent(smart_text(description)) + if html: + return markup_description(description) + return description
\ No newline at end of file |
