Skip to main content

Django ZipView

Build Status

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 emails import Email


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

    def get_files(self):
        emails = Email.objects \
            .filter(user=self.request.user) \
            .exclude(attachment__isnull=True)

        return [email.attachment.file for email in emails if email.attachment.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'

In case you need to dynamically set the filename, you can override the get_archive_name method. It takes the request as a parameter.

def get_archive_name(self, request):
    import datetime
    today = datetime.date.today()
    return 'archive_{:%Y%m%d}.zip'.format(today)

Compatibility

Current supported django versions are 2.2, 3.1 and 3.2.

Testing

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

To launch tests:

pip install -r requiments/test.txt
tox

Author

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

Metadata

Release files for django-zipview 2.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for django-zipview 2.0.0
File Interpreter ABI Platform Actions
django_zipview-2.0.0-py3-none-any.whl Python 3 none any Details for django_zipview-2.0.0-py3-none-any.whl

Release files / django_zipview-2.0.0-py3-none-any.whl

Download URL django_zipview-2.0.0-py3-none-any.whl
Size 4.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b7e9839162113f8541dc11ab7a2512442a58558e4e9879d72e789bec4925b430
BLAKE2b-256 checksum
How to use checksums
fdaa70e5e0781229a3e6d713efbf802efa482dc39a491729ca74f791f5eaf243
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.22.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.8.5

Security for django-zipview 2.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page