Skip to main content

A simple Django base view to zip and stream several files.

Project description

Django ZipView
==============

A base view to zip and stream several files.

Installation
------------

pip install django-zipview

Usage and examples
------------------

To create a zip download view:

* Extend BaseZipView
* implement `get_files`
* That's it

The `get_files` method must return a list of Django's File objects.

Example:

```python
from zipview.views import BaseZipView

from reviews import Review


class CommentsArchiveView(BaseZipView):
"""Download at once all comments for a review."""

def get_files(self):
document_key = self.kwargs.get('document_key')
reviews = Review.objects \
.filter(document__document_key=document_key) \
.exclude(comments__isnull=True)

return [review.comments.file for review in reviews if review.comments.name]
```

View configuration
------------------

By default, the downloaded file is named `download.zip` you can set a custom name
by setting the `zipfile_name` parameter.

```python

class ZipView(BaseZipView):
zipfile_name = 'toto.zip'
```

Testing
-------

Django ZipView uses [tox, the testing automation tool](https://tox.readthedocs.org/en/latest/),
to run tests.

To launch tests:

pip install tox
tox


Author
------

Crafted with love by [Thibault Jouannic](http://www.miximum.fr). You can
contact him for [Python / Django freelancing gigs](http://www.miximum.fr/a-propos/).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-zipview, version 1.0.0
Filename, size File type Python version Upload date Hashes
Filename, size django-zipview-1.0.0.tar.gz (3.9 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page