Skip to content

A Django generiv view to dynamically generate an archive of multiple files

License

Notifications You must be signed in to change notification settings

luckydonald-forks/django-zipview

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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:

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.

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

Testing

Django ZipView uses tox, the testing automation tool, to run tests.

To launch tests:

pip install tox
tox

Author

Crafted with love by Thibault Jouannic. You can contact him for Python / Django freelancing gigs.

About

A Django generiv view to dynamically generate an archive of multiple files

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Python 96.0%
  • Makefile 4.0%