Code Monkey home page Code Monkey logo

django-progressbarupload's Introduction

django-progressbarupload

Build Status

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

Contributors

The following users have contributed:

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

    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:

    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

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 andnginx 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 comes in. By configuring the nginx-upload-progress-module 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.

django-progressbarupload's People

Contributors

flimm avatar foobarbecue avatar iago-suarez avatar iepathos avatar mehdipourfar avatar naggie avatar ouhouhsami avatar sebcorbin avatar seedyrom avatar stefankoegl avatar strycore avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-progressbarupload's Issues

Can't see progress bar

On Django 1.7 with django-progressbarupload master version.
My form template is:

{% load progress_bar %}
<form action="/upload/" method="POST" enctype="multipart/form-data">
    {% csrf_token %}
    {% for field in upload_form %}
    <div class="row">
        {{ field.errors }}
        {{ field.label_tag }} {{ field }}
    </div>
    {% endfor %}
    {% progress_bar %}
    <input type="submit" value="Upload" />
</form>

HTML output I get:

<form action="/upload/" method="POST" enctype="multipart/form-data">
  <input type="hidden" name="csrfmiddlewaretoken" value="BmnjVvlrAfSk9Yeua9wyjmZ6RykSnLsb">
  <div class="row">
    <label for="id_imagefile">Select a file:</label> <input id="id_imagefile" name="imagefile" type="file">
  </div>
  <progress id="progressBar" data-progress_bar_uuid="72de7380-a4ea-447d-b6ee-7a7dbf4941f3" style="width:100%" value="0" max="100" hidden=""></progress>
  <script>upload_progress_url = "/progressbarupload/upload_progress"</script>
  <input type="submit" value="Upload">
</form>

Although file is beeing uploaded, but I can't see the progress bar.

from views import upload_progress ImportError: No module named 'views'

``Unhandled exception in thread started by <function check_errors..wrapper at 0x103ef01e0>
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/utils/autoreload.py", line 226, in wrapper
fn(_args, *_kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/management/commands/runserver.py", line 116, in inner_run
self.check(display_num_errors=True)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/management/base.py", line 426, in check
include_deployment_checks=include_deployment_checks,
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/checks/registry.py", line 75, in run_checks
new_errors = check(app_configs=app_configs)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/checks/urls.py", line 13, in check_url_config
return check_resolver(resolver)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/checks/urls.py", line 23, in check_resolver
for pattern in resolver.url_patterns:
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/utils/functional.py", line 33, in get
res = instance.dict[self.name] = self.func(instance)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/urlresolvers.py", line 417, in url_patterns
patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/utils/functional.py", line 33, in get
res = instance.dict[self.name] = self.func(instance)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/core/urlresolvers.py", line 410, in urlconf_module
return import_module(self.urlconf_name)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 986, in _gcd_import
File "", line 969, in _find_and_load
File "", line 958, in _find_and_load_unlocked
File "", line 673, in _load_unlocked
File "", line 662, in exec_module
File "", line 222, in _call_with_frames_removed
File "/Users/yuchenlin/workspace/w4lfv_svn/w4lfv/w4lfv/urls.py", line 30, in
url(r'^progressbarupload/', include('progressbarupload.urls')),
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/django/conf/urls/init.py", line 52, in include
urlconf_module = import_module(urlconf_module)
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/importlib/init.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "", line 986, in _gcd_import
File "", line 969, in _find_and_load
File "", line 958, in _find_and_load_unlocked
File "", line 673, in _load_unlocked
File "", line 662, in exec_module
File "", line 222, in _call_with_frames_removed
File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/progressbarupload/urls.py", line 3, in
from views import upload_progress
ImportError: No module named 'views'

[QUESTION] Real life use case

Hello!

I was using a way to display progress of upload and this looks like a viable solution for DJango BUT what about axios methods out of the box? Here is shown what I am referring to.

Is this is mainly used for AJAX and MVC structure or it could be used with REST API too?

Thank you

Works fine in Firefox, not in IE 10 or Chrome

Thank you for providing this. It's set up in a tidy package and easy to install.

I was previously using http://djangosnippets.org/snippets/678/ which also does not work in Chrome. I switched to this package hoping the <progress> tag would work in Chrome.

In Firefox, everything is fine, /progressbarupload/upload_progress is read repeatedly and the progress bar appears above the Save button, as expected.

In Chrome and IE10, the space for the progress bar does not appear above the Save button and the /progressbarupload URL is not read.

Firefox:
image

Chrome:
image

Django 1.7 not supported?

I'm using Django 1.7 with django-progressbarupload 0.1.6 and am getting the following error:

new_file() takes at most 6 arguments (7 given)

New release + pypi version working with Django 2.x

Does the current HEAD version work with Django 2.1 or Django 2.2?
The last release on PyPI does not, but the current code has already fixes
for Django 2.0 (e.g. replacement of from django.core.urlresolvers import reverse).

If this works for Django 2.x, could you please release a new version on PyPI?
However, thanks for this package.

Question/issue on position of progress bar in Chrome/Firefox/Safari

Attempting to use django-progressbarupload in Django project. Working on Linux Mint 32 bit. In Chrome Django admin displays progress bar but always in lower left corner of screen. It does not appear possible to position the bar elsewhere. In Firefox Django admin does not display a progress bar, rather displays message waiting for host. Working on Mac, progress bar always displays in lower left corner.

This behavior appears inconsistent with the documentation.

Is there a fix/workaround?

Regards,
Richard ([email protected]/[email protected])

Django 1.8 ImportError: cannot import name 'patterns'

if i try to start my server after configure the progress bar settigns i get this error

File ".../venv/lib/python3.5/site-packages/progressbarupload/urls.py", line 2, in <module>
    from django.conf.urls import patterns, url, include
ImportError: cannot import name 'patterns'

this error occures cause i use Django 1.8 and the pattens() function is deprecated sind version 1.8
(see https://docs.djangoproject.com/en/1.9/ref/urls/#patterns)

can u maybe upgrade the url settings in the progressbarupload/urls.py ?

{% progress_bar %} doesn't display progress.

I'm building a small app that stores whalesong. I've got my forms uploading to an S3 via boto3 and django-storages. I've also installed the development version of django-progressbarupload and am running django 2.0.6

The progress bar element appears and is styled, but doesn't animate nor sync with the file upload. The files are going to an s3 via a spotty connection, and the transfer usually takes 10-15 seconds. I've attached a video of an upload in action.

base template header

<head>
	{% load progress_bar %}

	{% block title %}<title>Whale Song and other Cetacean Communication</title>{% endblock %}
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">

	{% load static %}
	<link rel="stylesheet" type="text/css" href="{% static 'css/app.css' %}">
	<script type="text/javascript" src="{% static 'js/amplitude.min.js' %}"></script>
	<script src="{% static "js/jquery-3.3.1.min.js" %}"></script>

    {% progress_bar_media %}

</head>

form template snip

{% extends "base_generic.html" %}
{% load progress_bar %}

{% block content %}


<form action="" method="post" enctype="multipart/form-data">
	{% csrf_token %}

	{{ form.non_field_errors }}
	
	<div>
		<label for="{{ form.file.id_for_label }}">File</label>
		{{ form.file.errors }}
		{{ form.file }}
		
		{% progress_bar %}
	</div>

Project Here:
https://github.com/kidconcept/whalejams

Video Here
https://tinytake.s3.amazonaws.com/pulse/elpulpo/attachments/8400940/TinyTake29-07-2018-11-47-06.mp4

Settings needs django.template.loaders.eggs.Loader if installed with easy_install

Hi there,

This app looks promising.

If django-progressbarupload is installed with easy_install, then the TEMPLATE_LOADERS setting needs to have 'django.template.loaders.eggs.Loader'. Otherwise the template files can't be found because they are inside the egg zip file.

I am no fan of eggs but you might want to document this anyway. Or the other way is to put the template files in the package_data section of setup.py. This is the way django does it. Or I think the zip_safe=False setting in setup.py does the same thing.

Cheers,

Rodney

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.