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
c419fb0f
Commit
c419fb0f
authored
Sep 06, 2014
by
Tom Christie
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1841 from jpadilla/view-description-as-promise
Supported translated text view descriptions
parents
f4e02446
97ebd68f
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
2 deletions
+28
-2
rest_framework/utils/formatting.py
+4
-2
tests/test_description.py
+24
-0
No files found.
rest_framework/utils/formatting.py
View file @
c419fb0f
...
...
@@ -2,11 +2,12 @@
Utility functions to return a formatted name and description for a given view.
"""
from
__future__
import
unicode_literals
import
re
from
django.utils.html
import
escape
from
django.utils.safestring
import
mark_safe
from
rest_framework.compat
import
apply_markdown
import
re
from
rest_framework.compat
import
apply_markdown
,
force_text
def
remove_trailing_string
(
content
,
trailing
):
...
...
@@ -28,6 +29,7 @@ def dedent(content):
as it fails to dedent multiline docstrings that include
unindented text on the initial line.
"""
content
=
force_text
(
content
)
whitespace_counts
=
[
len
(
line
)
-
len
(
line
.
lstrip
(
' '
))
for
line
in
content
.
splitlines
()[
1
:]
if
line
.
lstrip
()]
...
...
tests/test_description.py
View file @
c419fb0f
...
...
@@ -98,6 +98,30 @@ class TestViewNamesAndDescriptions(TestCase):
pass
self
.
assertEqual
(
MockView
()
.
get_view_description
(),
''
)
def
test_view_description_can_be_promise
(
self
):
"""
Ensure a view may have a docstring that is actually a lazily evaluated
class that can be converted to a string.
See: https://github.com/tomchristie/django-rest-framework/issues/1708
"""
# use a mock object instead of gettext_lazy to ensure that we can't end
# up with a test case string in our l10n catalog
class
MockLazyStr
(
object
):
def
__init__
(
self
,
string
):
self
.
s
=
string
def
__str__
(
self
):
return
self
.
s
def
__unicode__
(
self
):
return
self
.
s
class
MockView
(
APIView
):
__doc__
=
MockLazyStr
(
"a gettext string"
)
self
.
assertEqual
(
MockView
()
.
get_view_description
(),
'a gettext string'
)
def
test_markdown
(
self
):
"""
Ensure markdown to HTML works as expected.
...
...
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