Commit e91b10ba authored by Michal Čihař's avatar Michal Čihař

Export monolingual and new language base files

Signed-off-by: default avatarMichal Čihař <michal@cihar.com>
parent 179280e9
...@@ -84,6 +84,14 @@ Components ...@@ -84,6 +84,14 @@ Components
: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/components/(string:project)/(string:component)/monolingual_base/
Returns base file for monolingual translations.
.. http:get:: /api/components/(string:project)/(string:component)/new_template/
Returns template file for new translations.
Translations Translations
++++++++++++ ++++++++++++
......
...@@ -202,6 +202,20 @@ class ComponentAPITest(APIBaseTest): ...@@ -202,6 +202,20 @@ class ComponentAPITest(APIBaseTest):
} }
) )
def test_new_template(self):
self.do_request(
'api:component-new-template',
self.component_kwargs,
code=404,
)
def test_monolingual(self):
self.do_request(
'api:component-monolingual-base',
self.component_kwargs,
code=404,
)
class LanguageAPITest(APIBaseTest): class LanguageAPITest(APIBaseTest):
def test_list_languages(self): def test_list_languages(self):
......
...@@ -18,9 +18,11 @@ ...@@ -18,9 +18,11 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
# #
import os.path
from django.core.exceptions import PermissionDenied from django.core.exceptions import PermissionDenied
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.http import Http404 from django.http import Http404, HttpResponse
from rest_framework import parsers, viewsets from rest_framework import parsers, viewsets
from rest_framework.decorators import detail_route from rest_framework.decorators import detail_route
...@@ -175,6 +177,43 @@ class ComponentViewSet(MultipleFieldMixin, WeblateViewSet): ...@@ -175,6 +177,43 @@ class ComponentViewSet(MultipleFieldMixin, WeblateViewSet):
return Response(data=LockSerializer(obj).data) return Response(data=LockSerializer(obj).data)
def download_file(self, filename, content_type):
"""Wrapper for file download"""
with open(filename, 'rb') as handle:
response = HttpResponse(
handle.read(),
content_type=content_type
)
response['Content-Disposition'] = \
'attachment; filename="{0}"'.format(
os.path.basename(filename)
)
return response
@detail_route(methods=['get'])
def monolingual_base(self, request, **kwargs):
obj = self.get_object()
if not obj.template:
raise Http404('No template found!')
return self.download_file(
obj.get_template_filename(),
obj.template_store.mimetype
)
@detail_route(methods=['get'])
def new_template(self, request, **kwargs):
obj = self.get_object()
if not obj.new_base:
raise Http404('No file found!')
return self.download_file(
obj.get_new_base_filename(),
'application/binary',
)
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