diff options
| author | Christopher Paolini | 2013-08-15 12:41:52 -0400 | 
|---|---|---|
| committer | Christopher Paolini | 2013-08-15 12:41:52 -0400 | 
| commit | d07dae6e79d53fdcfc7d88e085fe7e6da97c9c74 (patch) | |
| tree | 290c71cfa4b16e02063fae81e86cdb1e7e11f8e9 /rest_framework | |
| parent | c245fc6cde68403e8bc06b2f9886c35dcf74789a (diff) | |
| download | django-rest-framework-d07dae6e79d53fdcfc7d88e085fe7e6da97c9c74.tar.bz2 | |
Ability to override name/description of view
Added settings and additions to formatting.py
Diffstat (limited to 'rest_framework')
| -rw-r--r-- | rest_framework/settings.py | 4 | ||||
| -rw-r--r-- | rest_framework/utils/formatting.py | 15 | 
2 files changed, 19 insertions, 0 deletions
| diff --git a/rest_framework/settings.py b/rest_framework/settings.py index 8fd177d5..b65e42cf 100644 --- a/rest_framework/settings.py +++ b/rest_framework/settings.py @@ -69,6 +69,10 @@ DEFAULTS = {      'PAGINATE_BY': None,      'PAGINATE_BY_PARAM': None, +    # View configuration +    'VIEW_NAME_FUNCTION': None, +    'VIEW_DESCRIPTION_FUNCTION': None, +      # Authentication      'UNAUTHENTICATED_USER': 'django.contrib.auth.models.AnonymousUser',      'UNAUTHENTICATED_TOKEN': None, diff --git a/rest_framework/utils/formatting.py b/rest_framework/utils/formatting.py index 4bec8387..c908ce66 100644 --- a/rest_framework/utils/formatting.py +++ b/rest_framework/utils/formatting.py @@ -7,6 +7,7 @@ from django.utils.html import escape  from django.utils.safestring import mark_safe  from rest_framework.compat import apply_markdown, smart_text  import re +from rest_framework.settings import api_settings  def _remove_trailing_string(content, trailing): @@ -48,7 +49,14 @@ 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') @@ -61,7 +69,14 @@ def get_view_name(cls, suffix=None):  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: | 
