Skip to main content

Simple Fine Uploader integration for Django

Project description

This is a Django integration of Fine Uploader JavaScript Upload Library.

https://img.shields.io/pypi/v/django-fineuploader.svg https://img.shields.io/pypi/dm/django-fineuploader.svg https://img.shields.io/github/license/bashu/django-fineuploader.svg

Installation

pip install django-fineuploader

External dependencies

  • jQuery - This is not included in the package since it is expected that in most scenarios this would already be available.

Setup

Add fineuploader and fineuploader.ajaxuploader to INSTALLED_APPS:

INSTALLED_APPS += (
    'fineuploader',
    'fineuploader.ajaxuploader',
)

Be sure you have the django.template.context_processors.request processor

TEMPLATES = [
    {
        ...
        'OPTIONS': {
            'context_processors': [
                ...
                'django.template.context_processors.request',
            ],
        },
    },
]

Update your urls.py file:

urlpatterns += [
    url(r'^fineuploader/', include('fineuploader.urls')),
]

and include fineuploader templates

{% include "fineuploader/fineuploader_css.html" %} {# Before the closing head tag #}
{% include "fineuploader/fineuploader_js.html" %} {# Before the closing body tag #}

When deploying on production server, don’t forget to run:

python manage.py collectstatic

Usage

# forms.py

from django import forms

from fineuploader.forms import FineFormMixin
from fineuploader.formfields import FineFileField

class ExampleForm(FineFormMixin, forms.ModelForm):

    files = FineFileField(label="Files")

    class Meta:
        ...

    def save(self, *args, **kwargs):
        obj = super(ExampleForm, self).save(commit=True)

        self.handle_upload(obj, self.request)  # handle uploaded files

        self.delete_temporary_files()  # deleting temporary files / objects

        return obj

# views.py

from django.views import generic
from django.contrib.auth.mixins import LoginRequiredMixin

class ExampleCreateView(LoginRequiredMixin, generic.CreateView):
    form_class = ExampleForm  # our custom form class
    ...

    def get_form_kwargs(self):
        kwargs = super(ExampleCreateView, self).get_form_kwargs()
        kwargs.update({"request": self.request})  # must pass self.request into form
        return kwargs

class ExampleUpdateView(LoginRequiredMixin, generic.UpdateView):
    form_class = ExampleForm  # our custom form class
    ...

    def get_form_kwargs(self):
        kwargs = super(ExampleUpdateView, self).get_form_kwargs()
        kwargs.update({"request": self.request})  # must pass self.request into form
        return kwargs

License

django-fineuploader is released under the BSD license.

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-fineuploader, version 0.2.1
Filename, size File type Python version Upload date Hashes
Filename, size django_fineuploader-0.2.1-py2.py3-none-any.whl (108.0 kB) File type Wheel Python version 3.8 Upload date Hashes View
Filename, size django-fineuploader-0.2.1.tar.gz (102.0 kB) File type Source Python version None Upload date Hashes View

Supported by

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