Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
fdba5971
Commit
fdba5971
authored
Apr 12, 2016
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add link to the documentation to html view of API
Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
130442fb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
1 deletion
+39
-1
weblate/api/views.py
weblate/api/views.py
+38
-1
weblate/settings_example.py
weblate/settings_example.py
+1
-0
No files found.
weblate/api/views.py
View file @
fdba5971
...
...
@@ -23,10 +23,12 @@ import os.path
from
django.core.exceptions
import
PermissionDenied
from
django.shortcuts
import
get_object_or_404
from
django.http
import
Http404
,
HttpResponse
from
django.utils.encoding
import
smart_text
from
rest_framework
import
parsers
,
viewsets
from
rest_framework.decorators
import
detail_route
from
rest_framework.response
import
Response
from
rest_framework.utils
import
formatting
from
weblate.api.serializers
import
(
ProjectSerializer
,
ComponentSerializer
,
TranslationSerializer
,
...
...
@@ -42,6 +44,7 @@ from weblate.trans.permissions import (
)
from
weblate.lang.models
import
Language
from
weblate.trans.views.helper
import
download_translation_file
from
weblate
import
get_doc_url
OPERATIONS
=
{
'push'
:
(
can_push_translation
,
'do_push'
),
...
...
@@ -50,6 +53,40 @@ OPERATIONS = {
'commit'
:
(
can_commit_translation
,
'commit_pending'
),
}
DOC_TEXT
=
"""
See <a href="{0}">the Weblate's Web API documentation</a> for detailed description of the API.
"""
def
get_view_description
(
view_cls
,
html
=
False
):
"""
Given a view class, return a textual description to represent the view.
This name is used in the browsable API, and in OPTIONS responses.
This function is the default for the `VIEW_DESCRIPTION_FUNCTION` setting.
"""
description
=
view_cls
.
__doc__
or
''
description
=
formatting
.
dedent
(
smart_text
(
description
))
if
hasattr
(
view_cls
,
'serializer_class'
):
doc_url
=
get_doc_url
(
'api'
'{0}s'
.
format
(
view_cls
.
serializer_class
.
Meta
.
model
.
__name__
.
lower
()
)
)
else
:
doc_url
=
get_doc_url
(
'api'
)
description
=
'
\
n
\
n
'
.
join
((
description
,
DOC_TEXT
.
format
(
doc_url
)
))
if
html
:
return
formatting
.
markup_description
(
description
)
return
description
class
MultipleFieldMixin
(
object
):
"""
...
...
@@ -136,8 +173,8 @@ class WeblateViewSet(viewsets.ReadOnlyModelViewSet):
class
ProjectViewSet
(
WeblateViewSet
):
"""Translation projects API.
<a href="https://docs.weblate.org/en/latest/api.html#projects">doc</a>
"""
queryset
=
Project
.
objects
.
none
()
serializer_class
=
ProjectSerializer
lookup_field
=
'slug'
...
...
weblate/settings_example.py
View file @
fdba5971
...
...
@@ -579,6 +579,7 @@ REST_FRAMEWORK = {
'rest_framework.pagination.PageNumberPagination'
),
'PAGE_SIZE'
:
20
,
'VIEW_DESCRIPTION_FUNCTION'
:
'weblate.api.views.get_view_description'
,
}
# Example for restricting access to logged in users
...
...
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