Progress bar upload for Django
Project description
========================
django-progressbarupload
========================
[![Build Status](https://travis-ci.org/ouhouhsami/django-progressbarupload.png?branch=master)](https://travis-ci.org/ouhouhsami/django-progressbarupload)
django-progressbarupload is a simple Django application that instantiates an HTML5 upload progress bar when the user submits a form with files (a form having basically FileField(s) and/or ImageField(s), and an enctype="multipart/form-data").
![ScreenShot](https://raw.github.com/ouhouhsami/django-progressbarupload/master/docs/img/admin_progress_bar_screenshot.png)
###Contributors
The following users have contributed:
* [Iago Suárez](https://github.com/iago-suarez)
* [Andrew Brookins](https://github.com/abrookins)
* [Callan Bryant](https://github.com/naggie)
* [Mathieu Comandon](https://github.com/strycore)
Quick start
-----------
Requirements :
* Django 1.7.4 or above.
* Python 2.7 or 3.4
* django.contrib.staticfiles app to serve static files
1. Install the app
pypi version
```
pip install django-progressbarupload
```
development version
```
pip install -e git+http://github.com/ouhouhsami/django-progressbarupload.git#egg=django-progressbarupload
```
2. Add progressbarupload to your INSTALLED_APPS in your settings
```
INSTALLED_APPS += ('progressbarupload', )
```
3. Add "progressbarupload.uploadhandler.ProgressBarUploadHandler" to your FILE_UPLOAD_HANDLERS setting
```python
FILE_UPLOAD_HANDLERS = (
"progressbarupload.uploadhandler.ProgressBarUploadHandler",
"django.core.files.uploadhandler.MemoryFileUploadHandler",
"django.core.files.uploadhandler.TemporaryFileUploadHandler",
)
```
4. Include the progressbarupload URLconf in your project urls.py
```
(r'^progressbarupload/', include('progressbarupload.urls')),
```
5. In your settings file, if you don't want to include jquery with {% progress_bar_media %}, then set:
``` python
PROGRESSBARUPLOAD_INCLUDE_JQUERY = False
```
Usage
-----
### ModelAdmin
Set the ```change_form_template``` and ```add_form_template``` attributes in your ModelAdmin to 'progressbarupload/change_form.html'.
from django.contrib import admin
from my_awesome_app.models import MyAwesomeModelWithFiles
class MyAwesomeModelWithFiles(admin.ModelAdmin):
change_form_template = 'progressbarupload/change_form.html'
add_form_template = 'progressbarupload/change_form.html'
admin.site.register(MyAwesomeModelWithFiles, UploadFileModelAdmin)
Demo
----
This app includes a demo app, just go inside testapp dir and run
python manage.py migrate
python manage.py runserver
then go to http://127.0.0.1:8000/admin or http://127.0.0.1:8000/admin http://127.0.0.1:8000/testapp/form or http://127.0.0.1:8000/testapp/modelform
### Form and ModelForm
To use a progress bar in your custom ModelForm or Form, load the progress_bar template tag set ```{% load progress_bar %}``` in the template, and use the following template tags ```{% progress_bar_media %}``` between <head> tags to load javascript files and ```{% progress_bar %}``` where you and to display the progress bar.
{% load progress_bar %}
<!DOCTYPE html>
<html>
<head>
{% progress_bar_media %}
</head>
<body>
<form enctype="multipart/form-data" method="post" action=".">
{% csrf_token %}
{{ form }}
{% progress_bar %}
<input type="submit" />
</form>
</body>
</html>
Further information
-------------------
Make sure your browser renders HTML5 ```<progress>``` tag and uses data-* attribute (IE>10, FF>6.0, Chrome>8.0, Opera>11.0).
As Django has a unique TemporaryFileUploadHandler for all request.FILES. For ModelAdmin, if you have related models, using TabularInline, the upload progress will also be shown in the admin add/change form as soon as you use the right templates in your ModelAdmin (and even if your ModelAdmin doesn't contain any file upload).
Custom TemporaryFileUploadHandler copied from http://djangosnippets.org/snippets/678/
Launch tests
------------
It assumes you have installed virtualenvwrapper (http://virtualenvwrapper.readthedocs.org/en/latest/)
```
# get the application code
git clone https://github.com/ouhouhsami/django-progressbarupload.git
cd django-progressbarupload
# create a virtualenv
mkvirtualenv progressbarupload
add2virtualenv .
# install requirements for tests and django (set the django version you want to use)
pip install -r requirements/tests.txt django==1.7.4
# launch tests
django-admin.py test --settings=progressbarupload.test_settings progressbarupload
```
=======
New: Use transparently with uwsgi/nginx
---------------------------------------
The combination of uwsgi and nginx prevent django-progressbarupload from
working because nginx buffers the entire POST request until it is complete
before sending it to uwsgi/django. This means your application runs faster as
uwsgi threads are less tied up, but it also makes it impossible to view to
progress Django side.
Whilst you could use XMLHttpRequest 2.0 to get the progress client-side, you
may not have the luxury if you need to support older browsers. This is where
[RFC1867][2] comes in. By configuring the [nginx-upload-progress-module][1] in
the following way, it is possible to transparently support the native method as
well as the plugin:
```
...
upload_progress uploadp 1m;
# JSON document rather than JSONP callback, pls
upload_progress_json_output;
...
location ^ upload/url/pattern/
track_uploads uploadp 30s {
}
...
location ^~ /progressbarupload/upload_progress {
report_uploads uploadp;
}
```
nginx-upload-progress-module is available on ubuntu in the `nginx-extras` package.
[1]: https://github.com/masterzen/nginx-upload-progress-module
[2]: http://www.rfcreader.com/#rfc1867
django-progressbarupload
========================
[![Build Status](https://travis-ci.org/ouhouhsami/django-progressbarupload.png?branch=master)](https://travis-ci.org/ouhouhsami/django-progressbarupload)
django-progressbarupload is a simple Django application that instantiates an HTML5 upload progress bar when the user submits a form with files (a form having basically FileField(s) and/or ImageField(s), and an enctype="multipart/form-data").
![ScreenShot](https://raw.github.com/ouhouhsami/django-progressbarupload/master/docs/img/admin_progress_bar_screenshot.png)
###Contributors
The following users have contributed:
* [Iago Suárez](https://github.com/iago-suarez)
* [Andrew Brookins](https://github.com/abrookins)
* [Callan Bryant](https://github.com/naggie)
* [Mathieu Comandon](https://github.com/strycore)
Quick start
-----------
Requirements :
* Django 1.7.4 or above.
* Python 2.7 or 3.4
* django.contrib.staticfiles app to serve static files
1. Install the app
pypi version
```
pip install django-progressbarupload
```
development version
```
pip install -e git+http://github.com/ouhouhsami/django-progressbarupload.git#egg=django-progressbarupload
```
2. Add progressbarupload to your INSTALLED_APPS in your settings
```
INSTALLED_APPS += ('progressbarupload', )
```
3. Add "progressbarupload.uploadhandler.ProgressBarUploadHandler" to your FILE_UPLOAD_HANDLERS setting
```python
FILE_UPLOAD_HANDLERS = (
"progressbarupload.uploadhandler.ProgressBarUploadHandler",
"django.core.files.uploadhandler.MemoryFileUploadHandler",
"django.core.files.uploadhandler.TemporaryFileUploadHandler",
)
```
4. Include the progressbarupload URLconf in your project urls.py
```
(r'^progressbarupload/', include('progressbarupload.urls')),
```
5. In your settings file, if you don't want to include jquery with {% progress_bar_media %}, then set:
``` python
PROGRESSBARUPLOAD_INCLUDE_JQUERY = False
```
Usage
-----
### ModelAdmin
Set the ```change_form_template``` and ```add_form_template``` attributes in your ModelAdmin to 'progressbarupload/change_form.html'.
from django.contrib import admin
from my_awesome_app.models import MyAwesomeModelWithFiles
class MyAwesomeModelWithFiles(admin.ModelAdmin):
change_form_template = 'progressbarupload/change_form.html'
add_form_template = 'progressbarupload/change_form.html'
admin.site.register(MyAwesomeModelWithFiles, UploadFileModelAdmin)
Demo
----
This app includes a demo app, just go inside testapp dir and run
python manage.py migrate
python manage.py runserver
then go to http://127.0.0.1:8000/admin or http://127.0.0.1:8000/admin http://127.0.0.1:8000/testapp/form or http://127.0.0.1:8000/testapp/modelform
### Form and ModelForm
To use a progress bar in your custom ModelForm or Form, load the progress_bar template tag set ```{% load progress_bar %}``` in the template, and use the following template tags ```{% progress_bar_media %}``` between <head> tags to load javascript files and ```{% progress_bar %}``` where you and to display the progress bar.
{% load progress_bar %}
<!DOCTYPE html>
<html>
<head>
{% progress_bar_media %}
</head>
<body>
<form enctype="multipart/form-data" method="post" action=".">
{% csrf_token %}
{{ form }}
{% progress_bar %}
<input type="submit" />
</form>
</body>
</html>
Further information
-------------------
Make sure your browser renders HTML5 ```<progress>``` tag and uses data-* attribute (IE>10, FF>6.0, Chrome>8.0, Opera>11.0).
As Django has a unique TemporaryFileUploadHandler for all request.FILES. For ModelAdmin, if you have related models, using TabularInline, the upload progress will also be shown in the admin add/change form as soon as you use the right templates in your ModelAdmin (and even if your ModelAdmin doesn't contain any file upload).
Custom TemporaryFileUploadHandler copied from http://djangosnippets.org/snippets/678/
Launch tests
------------
It assumes you have installed virtualenvwrapper (http://virtualenvwrapper.readthedocs.org/en/latest/)
```
# get the application code
git clone https://github.com/ouhouhsami/django-progressbarupload.git
cd django-progressbarupload
# create a virtualenv
mkvirtualenv progressbarupload
add2virtualenv .
# install requirements for tests and django (set the django version you want to use)
pip install -r requirements/tests.txt django==1.7.4
# launch tests
django-admin.py test --settings=progressbarupload.test_settings progressbarupload
```
=======
New: Use transparently with uwsgi/nginx
---------------------------------------
The combination of uwsgi and nginx prevent django-progressbarupload from
working because nginx buffers the entire POST request until it is complete
before sending it to uwsgi/django. This means your application runs faster as
uwsgi threads are less tied up, but it also makes it impossible to view to
progress Django side.
Whilst you could use XMLHttpRequest 2.0 to get the progress client-side, you
may not have the luxury if you need to support older browsers. This is where
[RFC1867][2] comes in. By configuring the [nginx-upload-progress-module][1] in
the following way, it is possible to transparently support the native method as
well as the plugin:
```
...
upload_progress uploadp 1m;
# JSON document rather than JSONP callback, pls
upload_progress_json_output;
...
location ^ upload/url/pattern/
track_uploads uploadp 30s {
}
...
location ^~ /progressbarupload/upload_progress {
report_uploads uploadp;
}
```
nginx-upload-progress-module is available on ubuntu in the `nginx-extras` package.
[1]: https://github.com/masterzen/nginx-upload-progress-module
[2]: http://www.rfcreader.com/#rfc1867
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file django-progressbarupload-0.1.7.tar.gz
.
File metadata
- Download URL: django-progressbarupload-0.1.7.tar.gz
- Upload date:
- Size: 21.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26ed611b189c674f86724c5f8714fd990a3f26c93401ff4cb62954aebda4e4c7 |
|
MD5 | dece1e14fa91976fec641c78ada2c8e2 |
|
BLAKE2b-256 | 96cdbf26667abdeb868435a8cbb947cc0aaa1325e71f18047b84b56e91a28e87 |
File details
Details for the file django_progressbarupload-0.1.7-py2.py3-none-any.whl
.
File metadata
- Download URL: django_progressbarupload-0.1.7-py2.py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 957ef23b0432421bd0629302e9a6efb546cdd97bac2fc55e2dd9d7af87937878 |
|
MD5 | 8a4f5865269ed2c79491af5aabf8551c |
|
BLAKE2b-256 | eb27ad08de99e9dfe7dffc9056a7514af3d36db7118f2de3ca67c88896b99e0b |