Commit 65faa05d authored by Michal Čihař's avatar Michal Čihař

Add API for listing translations and components

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent c0b416c0
...@@ -57,6 +57,10 @@ Projects ...@@ -57,6 +57,10 @@ Projects
:query operation: Operation to perform, one of ``push``, ``pull``, ``commit``, ``reset`` :query operation: Operation to perform, one of ``push``, ``pull``, ``commit``, ``reset``
.. http:get:: /api/projects/(string:project)/components/
Returns list of translation components in given project.
Components Components
++++++++++ ++++++++++
...@@ -92,6 +96,10 @@ Components ...@@ -92,6 +96,10 @@ Components
Returns template file for new translations. Returns template file for new translations.
.. http:get:: /api/components/(string:project)/(string:component)/translations/
Returns list of translation objects in given component.
Translations Translations
++++++++++++ ++++++++++++
...@@ -217,7 +225,7 @@ Weblate provides various exports to allow you further process the data. ...@@ -217,7 +225,7 @@ Weblate provides various exports to allow you further process the data.
.. deprecated:: 2.6 .. deprecated:: 2.6
Please use :http:get:`/api/translations/(string:project)/(string:component)/(string:language)/` Please use :http:get:`/api/components/(string:project)/(string:component)/translations/`
instead, it allows to access ACL controlled projects as well. instead, it allows to access ACL controlled projects as well.
Retrieves statistics for given component in JSON format. Optionally as Retrieves statistics for given component in JSON format. Optionally as
......
...@@ -65,6 +65,7 @@ class APIBaseTest(APITestCase, RepoTestMixin): ...@@ -65,6 +65,7 @@ class APIBaseTest(APITestCase, RepoTestMixin):
self.assertEqual(response.status_code, code) self.assertEqual(response.status_code, code)
if data is not None: if data is not None:
self.assertEqual(response.data, data) self.assertEqual(response.data, data)
return response
class ProjectAPITest(APIBaseTest): class ProjectAPITest(APIBaseTest):
...@@ -130,6 +131,13 @@ class ProjectAPITest(APIBaseTest): ...@@ -130,6 +131,13 @@ class ProjectAPITest(APIBaseTest):
} }
) )
def test_components(self):
request = self.do_request(
'api:project-components',
self.project_kwargs,
)
self.assertEqual(request.data['count'], 1)
class ComponentAPITest(APIBaseTest): class ComponentAPITest(APIBaseTest):
def test_list_components(self): def test_list_components(self):
...@@ -216,6 +224,13 @@ class ComponentAPITest(APIBaseTest): ...@@ -216,6 +224,13 @@ class ComponentAPITest(APIBaseTest):
code=404, code=404,
) )
def test_translations(self):
request = self.do_request(
'api:component-translations',
self.component_kwargs,
)
self.assertEqual(request.data['count'], 3)
class LanguageAPITest(APIBaseTest): class LanguageAPITest(APIBaseTest):
def test_list_languages(self): def test_list_languages(self):
......
...@@ -138,6 +138,21 @@ class ProjectViewSet(WeblateViewSet): ...@@ -138,6 +138,21 @@ class ProjectViewSet(WeblateViewSet):
'source_language' 'source_language'
) )
@detail_route(methods=['get'])
def components(self, request, **kwargs):
obj = self.get_object()
queryset = obj.subproject_set.all()
page = self.paginate_queryset(queryset)
serializer = ComponentSerializer(
page,
many=True,
context={'request': request}
)
return self.get_paginated_response(serializer.data)
class ComponentViewSet(MultipleFieldMixin, WeblateViewSet): class ComponentViewSet(MultipleFieldMixin, WeblateViewSet):
"""Translation components API. """Translation components API.
...@@ -214,6 +229,21 @@ class ComponentViewSet(MultipleFieldMixin, WeblateViewSet): ...@@ -214,6 +229,21 @@ class ComponentViewSet(MultipleFieldMixin, WeblateViewSet):
'application/binary', 'application/binary',
) )
@detail_route(methods=['get'])
def translations(self, request, **kwargs):
obj = self.get_object()
queryset = obj.translation_set.all()
page = self.paginate_queryset(queryset)
serializer = TranslationSerializer(
page,
many=True,
context={'request': request}
)
return self.get_paginated_response(serializer.data)
class TranslationViewSet(MultipleFieldMixin, WeblateViewSet): class TranslationViewSet(MultipleFieldMixin, WeblateViewSet):
"""Translation components API. """Translation components API.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment