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

Actually implement download

parent da40fce1
from django.shortcuts import render_to_response, get_object_or_404 from django.shortcuts import render_to_response, get_object_or_404
from django.core.servers.basehttp import FileWrapper
from django.utils.translation import ugettext_lazy, ugettext as _ from django.utils.translation import ugettext_lazy, ugettext as _
from django.template import RequestContext from django.template import RequestContext
from django.conf import settings from django.conf import settings
...@@ -9,6 +10,7 @@ from trans.models import Project, SubProject, Translation, Unit, Suggestion ...@@ -9,6 +10,7 @@ from trans.models import Project, SubProject, Translation, Unit, Suggestion
from trans.forms import TranslationForm from trans.forms import TranslationForm
from util import is_plural, split_plural, join_plural from util import is_plural, split_plural, join_plural
import logging import logging
import os.path
logger = logging.getLogger('weblate') logger = logging.getLogger('weblate')
...@@ -48,12 +50,16 @@ def download_translation(request, project, subproject, lang): ...@@ -48,12 +50,16 @@ def download_translation(request, project, subproject, lang):
obj = get_object_or_404(Translation, language__code = lang, subproject__slug = subproject, subproject__project__slug = project) obj = get_object_or_404(Translation, language__code = lang, subproject__slug = subproject, subproject__project__slug = project)
store = obj.get_store() store = obj.get_store()
srcfilename = obj.get_filename()
mime = store.Mimetypes[0] mime = store.Mimetypes[0]
ext = store.Extensions[0] ext = store.Extensions[0]
filename = '%s-%s-%s.%s' % (project, subproject, lang, ext) filename = '%s-%s-%s.%s' % (project, subproject, lang, ext)
response = HttpResponse(mimetype = mime) wrapper = FileWrapper(file(srcfilename))
response = HttpResponse(wrapper, mimetype = mime)
response['Content-Disposition'] = 'attachment; filename=%s' % filename response['Content-Disposition'] = 'attachment; filename=%s' % filename
response['Content-Length'] = os.path.getsize(srcfilename)
return response return response
......
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