Commits

Diego Búrigo Zacarão  committed 4e2b8b7

Made sure download of compressed files for a release/language works

- Lets enable it by default. This might be slow, but it's a
cool feature.

  • Participants
  • Parent commits a5b240e

Comments (0)

Files changed (5)

File transifex/languages/urls.py

                   'queryset': Language.objects.all()}
     ),
 )
-
-#TODO: Make this setting work throughout the applications
-if getattr(settings, 'ENABLE_COMPRESSED_DOWNLOAD', True):
-    urlpatterns += patterns('',
-        url(
-            name = 'language_release_download',
-            regex = '^l/(?P<slug>[-_@\w]+)/collection/c/(?P<collection_slug>[-\w]+)/r/(?P<release_slug>[-\w]+)/download_(?P<filetype>[\w]+)/$',
-            view = language_release_download,
-        ),
-)

File transifex/projects/urls.py

     ),
 )
 
+if getattr(settings, 'ENABLE_COMPRESSED_DOWNLOAD', True):
+    urlpatterns += patterns('',
+        url(
+            name = 'release_language_download',
+            regex = '^p/(?P<project_slug>[-\w]+)/r/(?P<release_slug>[-\w]+)/l/(?P<language_code>[-_@\w]+)/download_(?P<filetype>[\w]+)/$',
+            view = release_language_download,
+        ),
+)
+
 
 # Teams
 urlpatterns += patterns('',

File transifex/projects/views/release.py

 # -*- coding: utf-8 -*-
 from django.core.urlresolvers import reverse
-from django.http import HttpResponseRedirect
+from django.http import Http404, HttpResponseRedirect, HttpResponse
 from django.shortcuts import render_to_response, get_object_or_404
 from django.template import RequestContext
 from django.utils.translation import ugettext as _
                                   {'release': release,},
                                   context_instance=RequestContext(request))
 
+
+def release_language_download(request, project_slug, release_slug, 
+        language_code, filetype):
+    """
+    Download a compressed file of all files for a release-language.
+    """
+    language = get_object_or_404(Language, code__iexact=language_code)
+    project = get_object_or_404(Project, slug__exact=project_slug)
+    release = get_object_or_404(Release, slug__exact=release_slug,
+        project__id=project.pk)
+    pofile_list = POFile.objects.by_language_and_release_total(language, release)
+
+    filename = '%s.%s_%s' % (project.slug, release.slug, language.code)
+    from translations.util.compressed import POCompressedArchive
+    try:
+        archive = POCompressedArchive(pofile_list, filename, filetype)
+        response = HttpResponse(file(archive.file_path).read())
+        response['Content-Disposition'] = 'attachment; filename=%s' % archive.filename
+        response['Content-Type'] = archive.content_type
+        archive.cleanup()
+    except NotImplementedError:
+        raise Http404
+    return response
+
+

File transifex/settings/40-apps.conf

 
 # Enable download of compressed zip/targz files in the Language x Release page
 # For now it's dissabled by default until we find out a faster way to compact those files on fly
-ENABLE_COMPRESSED_DOWNLOAD = False
+ENABLE_COMPRESSED_DOWNLOAD = True
 
 # Django-profile
 AUTH_PROFILE_MODULE = 'txcommon.profile'

File transifex/templates/projects/release_language_detail.html

 
 {% lang_stats_table pofile_list %}
 
-{% url language_release_download slug=language.code collection_slug=release.collection.slug release_slug=release.slug filetype="zip" as zip_download_url %}
-{% url language_release_download slug=language.code collection_slug=release.collection.slug release_slug=release.slug filetype="targz" as targz_download_url %}
+{% url release_language_download release.project.slug release.slug language.code "zip" as zip_download_url %}
+{% url release_language_download release.project.slug release.slug language.code "targz" as targz_download_url %}
 
  {% if zip_download_url %}
  <h4>Download</h4>