scipy / SciPyCentral

SciPy Central
http://scipy-central.org
BSD 3-Clause "New" or "Revised" License
16 stars 12 forks source link

Download link added to snippets and libraries #99

Closed kgdunn closed 13 years ago

kgdunn commented 13 years ago

Provides a ZIP file of code.

Add "http://" at the top of snippet downloads

kgdunn commented 13 years ago

Create ZIP file in a staging area; don't recreate unless the submission is updated

Download a zip file: http://bitkickers.blogspot.com/2010/07/django-zip-files-create-dynamic-in.html

from StringIO import StringIO
from zipfile import ZipFile
from django.http import HttpResponse

def download(request, company_id):     

    in_memory = StringIO()
    zip = ZipFile(in_memory, "a")

    zip.writestr("file1.txt", "some text contents")
    zip.writestr("file2.csv", "csv,data,here")

    # fix for Linux zip files read in Windows
    for file in zip.filelist:
        file.create_system = 0    

    zip.close()

    response = HttpResponse(mimetype="application/zip")
    response["Content-Disposition"] = "attachment; filename=two_files.zip"

    in_memory.seek(0)    
    response.write(in_memory.read())

    return response
kgdunn commented 13 years ago

Fixed, in various commits on and before 10 August