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
b4c07052
Commit
b4c07052
authored
Mar 23, 2016
by
Michal Čihař
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Include self-links in all API objects
Signed-off-by:
Michal Čihař
<
michal@cihar.com
>
parent
ae4582b9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
50 additions
and
6 deletions
+50
-6
weblate/api/serializers.py
weblate/api/serializers.py
+48
-5
weblate/api/urls.py
weblate/api/urls.py
+2
-1
No files found.
weblate/api/serializers.py
View file @
b4c07052
...
...
@@ -24,6 +24,29 @@ from weblate.trans.models import Project, SubProject, Translation
from
weblate.lang.models
import
Language
class
MultiFieldHyperlinkedIdentityField
(
serializers
.
HyperlinkedIdentityField
):
def
get_url
(
self
,
obj
,
view_name
,
request
,
format
):
"""
Given an object, return the URL that hyperlinks to the object.
May raise a `NoReverseMatch` if the `view_name` and `lookup_field`
attributes are not configured to correctly match the URL conf.
"""
# Unsaved objects will not yet have a valid URL.
if
hasattr
(
obj
,
'pk'
)
and
obj
.
pk
is
None
:
return
None
kwargs
=
{}
for
lookup
in
self
.
lookup_field
:
value
=
obj
for
key
in
lookup
.
split
(
'__'
):
value
=
getattr
(
value
,
key
)
kwargs
[
lookup
]
=
value
return
self
.
reverse
(
view_name
,
kwargs
=
kwargs
,
request
=
request
,
format
=
format
)
class
LanguageSerializer
(
serializers
.
ModelSerializer
):
web_url
=
serializers
.
CharField
(
source
=
'get_absolute_url'
,
read_only
=
True
)
...
...
@@ -62,25 +85,45 @@ class ComponentSerializer(serializers.ModelSerializer):
web_url
=
serializers
.
CharField
(
source
=
'get_absolute_url'
,
read_only
=
True
)
project
=
ProjectSerializer
(
read_only
=
True
)
serializer_url_field
=
MultiFieldHyperlinkedIdentityField
class
Meta
(
object
):
model
=
SubProject
fields
=
(
'
id'
,
'
name'
,
'slug'
,
'project'
,
'vcs'
,
'repo'
,
'git_export'
,
'name'
,
'slug'
,
'project'
,
'vcs'
,
'repo'
,
'git_export'
,
'branch'
,
'filemask'
,
'template'
,
'file_format'
,
'license'
,
'license_url'
,
'web_url'
,
'license_url'
,
'web_url'
,
'url'
,
)
extra_kwargs
=
{
'url'
:
{
'view_name'
:
'api:component-detail'
,
'lookup_field'
:
(
'project__slug'
,
'slug'
),
}
}
class
TranslationSerializer
(
serializers
.
ModelSerializer
):
web_url
=
serializers
.
CharField
(
source
=
'get_absolute_url'
,
read_only
=
True
)
subproject
=
ComponentSerializer
(
read_only
=
True
)
component
=
ComponentSerializer
(
read_only
=
True
,
source
=
'subproject'
)
language
=
LanguageSerializer
(
read_only
=
True
)
serializer_url_field
=
MultiFieldHyperlinkedIdentityField
class
Meta
(
object
):
model
=
Translation
fields
=
(
'
id'
,
'language'
,
'subprojec
t'
,
'translated'
,
'fuzzy'
,
'total'
,
'
language'
,
'componen
t'
,
'translated'
,
'fuzzy'
,
'total'
,
'translated_words'
,
'fuzzy_words'
,
'failing_checks_words'
,
'total_words'
,
'failing_checks'
,
'have_suggestion'
,
'have_comment'
,
'language_code'
,
'filename'
,
'revision'
,
'web_url'
,
'language_code'
,
'filename'
,
'revision'
,
'web_url'
,
'url'
,
)
extra_kwargs
=
{
'url'
:
{
'view_name'
:
'api:translation-detail'
,
'lookup_field'
:
(
'subproject__project__slug'
,
'subproject__slug'
,
'language__code'
,
),
}
}
weblate/api/urls.py
View file @
b4c07052
...
...
@@ -35,7 +35,8 @@ router.register(
)
router
.
register
(
r'components/(?P<project__slug>[^/]+)'
,
ComponentViewSet
ComponentViewSet
,
'component'
,
)
router
.
register
(
r'translations/'
...
...
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