diff apps/bundle/views.py @ 209:4033ebe1867f

Add ability to download files This makes use of a new model (BundleVersion) to keep track of the locations on disk of the original uploads for each version. This will require some manual processing to get it working for existing bundles, since the information needed isn't being stored at the moment.
author dellsystem <ilostwaldo@gmail.com>
date Sun, 17 Feb 2013 14:57:39 -0500
parents cdcbfaa65cfe
children 2a234e11185c
line wrap: on
line diff
--- a/apps/bundle/views.py	Sat Oct 27 16:26:54 2012 -0400
+++ b/apps/bundle/views.py	Sun Feb 17 14:57:39 2013 -0500
@@ -5,8 +5,9 @@
 from django.shortcuts import get_object_or_404, render, redirect
 from django.contrib.auth.decorators import login_required
 from django.http import HttpResponse
+from django.views.static import serve
 
-from apps.bundle.models import Bundle, BundleFile
+from apps.bundle.models import Bundle, BundleFile, BundleVersion
 from apps.bundle.forms import BundleForm, BundleEditForm
 from apps.bundle.tasks import handle_bundle_upload
 from apps.pygments_style.models import PygmentsStyle
@@ -37,7 +38,6 @@
 
 
 def file_detail(request, user, bundle, version, path):
-    print version
     bundle_file = get_object_or_404(BundleFile, bundle__uploader__username=user,
         bundle__name=bundle, full_path=path, is_dir=False, version=version)
 
@@ -123,3 +123,14 @@
     }
 
     return render(request, "bundle/edit.djhtml", context)
+
+
+def download(request, user, bundle, version):
+    bundle = get_object_or_404(Bundle, uploader__username=user, name=bundle)
+    version = int(version)
+
+    # Look for the BundleVersion with this version
+    bundle_version = get_object_or_404(BundleVersion, bundle=bundle,
+        version=version)
+    return serve(request, bundle_version.file_name, os.path.join('tmp',
+        'bundles'))