Skip to main content

droppablefileinput

Release Build status codecov Commit activity License

DroppableFileInput is a custom Django widget that enhances the usability of file input forms by allowing users to drag and drop files. This widget utilizes JavaScript to provide interactive feedback, such as highlighting the drop area when a file is dragged over and displaying file details on the page. This uses no external JavaScript dependencies, all functionality is brought by this package.

Features

  • Drag and Drop: Easy file uploading by dragging files into the drop area.
  • Interactive Feedback: Highlights the drop area during a drag operation and shows file details once a file is selected.
  • Size Validation: Validates the file size on the client side before submitting to the server.
  • Type Validation: Ensures that only allowed file types can be uploaded.
  • Auto Submit: Optionally auto-submits the form once a file is selected.

Installation

To install DroppableFileInput, you can download it directly from GitHub or use pip:

pip install git+https://github.com/blackbox-innovation/django-droppablefileinput.git

Setup

After installation, add droppablefileinput to your INSTALLED_APPS in your Django settings:

INSTALLED_APPS = [
...
'droppablefileinput',
...
]

Ensure you have Django's static file handling set up, as this widget relies on associated CSS and JavaScript files.

Usage

To use the DroppableFileInput in your Django forms, import the widget and use it in a form field:

from django import forms
from droppablefileinput.widgets import DroppableFileInput
class UploadForm(forms.Form):
file = forms.FileField(widget=DroppableFileInput())

In your templates, make sure to include the form's media:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>Upload File</title>
    {{ form.media }}
  </head>
  <body>
    <form method="post" enctype="multipart/form-data">
      {% csrf_token %} {{ form.as_p }}
      <button type="submit">Upload</button>
    </form>
  </body>
</html>

Customization

The DroppableFileInput widget can be customized with the following parameters:

  • auto_submit: Whether to auto-submit the form upon file selection.
  • max_file_size: Maximum file size allowed for upload.
  • allowed_types: List of allowed file MIME types.
  • icon_url: URL to the icon image to display in the drop area.
  • icon_width: Width of the icon image.
  • icon_height: Height of the icon image.

Example:

class UploadForm(forms.Form):
    file = forms.FileField(widget=DroppableFileInput(
    auto_submit=True,
    max_file_size="10M",
    allowed_types="image/jpeg,image/png",
    icon_url=static('images/custom-icon.svg'),
    icon_width=40,
    icon_height=40
))

Contributing

Contributions are welcome! If you would like to contribute to this project, please follow these steps:

  1. Fork the repository on GitHub.
  2. Clone your forked repository to your local machine.
  3. Create a new branch for your feature or fix.
  4. Make changes and test.
  5. Submit a pull request with a clear description of the changes and any relevant issue numbers.

License

Distributed under the MIT License. See LICENSE file for more information.

Support

If you have any issues or feature requests, please file an issue on the GitHub repository issue tracker.

Metadata

Release files for droppablefileinput 0.1.2

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

Source distribution (sdist)

Source distribution for droppablefileinput 0.1.2
File Size Uploaded Provenance
droppablefileinput-0.1.2.tar.gz 58.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for droppablefileinput 0.1.2
File Interpreter ABI Platform
droppablefileinput-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 72.8 kB

Release files / droppablefileinput-0.1.2.tar.gz

Download URL droppablefileinput-0.1.2.tar.gz
Size 58.2 kB
Tags Source
SHA-256 checksum
How to use checksums
d2514086ad89cbc46c320d530d382a9fe1f1411b452ffe8e73a070ac7d87c8a5
BLAKE2b-256 checksum
How to use checksums
72378bad099d6fa012185f034e9f497e8fc70b42049d76c37e9e339298a74810
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.13

Release files / droppablefileinput-0.1.2-py3-none-any.whl

Download URL droppablefileinput-0.1.2-py3-none-any.whl
Size 14.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ec8b8e3b48b35dd4856aa9fbd6befd20c586bfff4c486e9265c85c260745a419
BLAKE2b-256 checksum
How to use checksums
16408fc4fff6051d6ec87831ab26e2daff8eceb6517b23f45a7031f3b2920f96
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.13

Security for droppablefileinput 0.1.2

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