def download_translation_file(translation, fmt=None): if fmt is not None: try: exporter = get_exporter(fmt)(translation=translation) except KeyError: raise Http404('File format not supported') exporter.add_units(translation) return exporter.get_response( '{{project}}-{0}-{{language}}.{{extension}}'.format( translation.subproject.slug)) srcfilename = translation.get_filename() # Construct file name (do not use real filename as it is usually not # that useful) filename = '{0}-{1}-{2}.{3}'.format(translation.subproject.project.slug, translation.subproject.slug, translation.language.code, translation.store.extension) # Create response with open(srcfilename) as handle: response = HttpResponse(handle.read(), content_type=translation.store.mimetype) # Fill in response headers response['Content-Disposition'] = 'attachment; filename={0}'.format( filename) return response
def download_translation_file(translation, fmt=None): if fmt is not None: try: exporter = get_exporter(fmt)(translation=translation) except KeyError: raise Http404('File format not supported') exporter.add_units(translation) return exporter.get_response( '{{project}}-{0}-{{language}}.{{extension}}'.format( translation.subproject.slug ) ) srcfilename = translation.get_filename() # Construct file name (do not use real filename as it is usually not # that useful) filename = '{0}-{1}-{2}.{3}'.format( translation.subproject.project.slug, translation.subproject.slug, translation.language.code, translation.store.extension ) # Create response with open(srcfilename) as handle: response = HttpResponse( handle.read(), content_type=translation.store.mimetype ) # Fill in response headers response['Content-Disposition'] = 'attachment; filename=%s' % filename return response