Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install django-zipfile

How to install django-zipfile

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install django-zipfile
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.1.7
0.2.0Never BuiltWhy not?
0.1.7 Available View build log
0.1.1 Available View build log
0.0.6 Available View build log
Windows (64-bit)
0.1.7
0.2.0Never BuiltWhy not?
0.1.7 Available View build log
0.1.1 Available View build log
0.0.6 Available View build log
Mac OS X (10.5+)
0.1.7
0.2.0Never BuiltWhy not?
0.1.7 Available View build log
0.1.1 Available View build log
0.0.6 Available View build log
Linux (32-bit)
0.1.7
0.2.0Never BuiltWhy not?
0.1.7 Available View build log
0.1.1 Available View build log
0.0.6 Available View build log
Linux (64-bit)
0.2.0 Available View build log
0.1.7 Available View build log
0.1.1 Available View build log
0.0.6 Available View build log
 
License
MIT
Dependencies
Lastest release
version 0.2.0 on Jan 9th, 2014

A subclass of zipfile.Zipfile that works with Django templates.

Usage:

from zipfile import ZIP_DEFLATED
from django_zipfile import TemplateZipFile

def myview(request, object_id):
    obj = get_object_or_404(MyModel, pk=object_id)
    context = {
        'object': obj
    }
    response = HttpResponse(mimetype='application/octet-stream')
    response['Content-Disposition'] = 'attachment; filename=myfile.zip'

    container = TemplateZipFile(response, mode='w', compression=ZIP_DEFLATED, template_root='myapp/myzipskeleton/')

    container.write_template('mimetype')
    container.write_template('META-INF/container.xml')
    container.write_template('chapter1.html', context=context)

    container.close()
    return response

You can also specify multiple roots for your templates:

container = TemplateZipFile(response, mode='w', compression=ZIP_DEFLATED, template_root=['myapp/myzipskeleton/override/', 'myapp/myzipskeleton/default/'])

as well as multiple templates when you add files:

container.write_template(['override.html', 'default.html'], filename="chapter1.html")

TemplateZipFile will look for templates in the specified order, first by root, then by template name. For example:

myzipfile = TemplateZipFile(response, mode='w', compression=ZIP_DEFLATED, template_root=['override/', 'default/'])
myzipfile.write_template(['two.txt', 'one.txt'], filename='myfile.txt')

# Will use the first existing template from ['override/two.txt', 'override/one.txt', 'default/two.txt', 'default/one.txt']

If none of the templates can be found, write_template will raise a TemplateDoesNotExist error.

You can specify a file as optional with optional=True

myzipfile.write_template(['two.txt', 'one.txt'], filename='myfile.txt', optional=True)

Doing so will silently swallow the TemplateDoesNotExist exception.

Subscribe to package updates

Last updated Jan 9th, 2014

Download Stats

Last month:4

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.