Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
django-rest-framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
edx
django-rest-framework
Commits
a95984e4
Commit
a95984e4
authored
Aug 16, 2013
by
Christopher Paolini
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Settings now have default functions
Updated the setting to have a default function.
parent
d07dae6e
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
28 deletions
+25
-28
rest_framework/settings.py
+4
-2
rest_framework/utils/formatting.py
+21
-26
No files found.
rest_framework/settings.py
View file @
a95984e4
...
@@ -70,8 +70,8 @@ DEFAULTS = {
...
@@ -70,8 +70,8 @@ DEFAULTS = {
'PAGINATE_BY_PARAM'
:
None
,
'PAGINATE_BY_PARAM'
:
None
,
# View configuration
# View configuration
'VIEW_NAME_FUNCTION'
:
None
,
'VIEW_NAME_FUNCTION'
:
'rest_framework.utils.formatting.view_name'
,
'VIEW_DESCRIPTION_FUNCTION'
:
None
,
'VIEW_DESCRIPTION_FUNCTION'
:
'rest_framework.utils.formatting.view_description'
,
# Authentication
# Authentication
'UNAUTHENTICATED_USER'
:
'django.contrib.auth.models.AnonymousUser'
,
'UNAUTHENTICATED_USER'
:
'django.contrib.auth.models.AnonymousUser'
,
...
@@ -129,6 +129,8 @@ IMPORT_STRINGS = (
...
@@ -129,6 +129,8 @@ IMPORT_STRINGS = (
'TEST_REQUEST_RENDERER_CLASSES'
,
'TEST_REQUEST_RENDERER_CLASSES'
,
'UNAUTHENTICATED_USER'
,
'UNAUTHENTICATED_USER'
,
'UNAUTHENTICATED_TOKEN'
,
'UNAUTHENTICATED_TOKEN'
,
'VIEW_NAME_FUNCTION'
,
'VIEW_DESCRIPTION_FUNCTION'
)
)
...
...
rest_framework/utils/formatting.py
View file @
a95984e4
...
@@ -49,39 +49,15 @@ def _camelcase_to_spaces(content):
...
@@ -49,39 +49,15 @@ def _camelcase_to_spaces(content):
def
get_view_name
(
cls
,
suffix
=
None
):
def
get_view_name
(
cls
,
suffix
=
None
):
"""
"""
Return a formatted name for an `APIView` class or `@api_view` function.
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
:
return
api_settings
.
VIEW_NAME_FUNCTION
(
cls
,
suffix
)
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
def
get_view_description
(
cls
,
html
=
False
):
def
get_view_description
(
cls
,
html
=
False
):
"""
"""
Return a description for an `APIView` class or `@api_view` function.
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
:
return
api_settings
.
VIEW_DESCRIPTION_FUNCTION
(
cls
)
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
def
markup_description
(
description
):
def
markup_description
(
description
):
...
@@ -93,3 +69,21 @@ def markup_description(description):
...
@@ -93,3 +69,21 @@ def markup_description(description):
else
:
else
:
description
=
escape
(
description
)
.
replace
(
'
\n
'
,
'<br />'
)
description
=
escape
(
description
)
.
replace
(
'
\n
'
,
'<br />'
)
return
mark_safe
(
description
)
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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment