Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
ad8f91a
added templates, templatetags paths into setup.py
Dec 20, 2010
6de519b
load UPLOADIFY_PATH, UPLOADIFY_UPLOAD_PATH from django.conf.settings
Dec 20, 2010
fcb41fe
fix typo
Dec 20, 2010
d76ff6d
fix for django 1.2.3
Dec 20, 2010
55a2f4a
add unique_id for each uploading; remove default processing allUpload…
Dec 21, 2010
556d3b8
Added project goal in README.
anderspetersson Jan 10, 2011
e53cfab
Changed default PATHS to reflect the changes regarding STATIC_URL / M…
anderspetersson Jan 10, 2011
b6babde
Fixed typos.
anderspetersson Jan 10, 2011
0e9e3f6
not use Uploadify for IE6,7 (not works); fix for IE8
Feb 8, 2011
4885854
add onComplete event
Mar 30, 2011
9e179ef
return httpResponse with file link
Mar 30, 2011
39cc4e4
add diferent senders, return data from receivers, remove auto upload
smacker Apr 20, 2011
68ccd6e
different fileDataName
smacker Apr 21, 2011
5af9b5c
all uploadify settings in tag, widget
smacker May 3, 2011
24a73d2
Merge pull request #1 from smacker/master.
frol May 3, 2011
80bf90e
fix some stange code; use django-misc instead sugar
May 13, 2011
029e701
use json response; use sessionid in POST data for check authenticated…
May 16, 2011
6425179
add django-misc in requirements; initial README
Jul 10, 2011
59e48f2
fix README, add usefull example
Jul 10, 2011
9b9d6c1
fix urls in README
Jul 10, 2011
81fcef7
fix README
Jul 10, 2011
82c84f7
fix README
Jul 10, 2011
16c1c91
Edited setup.py via GitHub
dontcare Aug 7, 2011
6946945
Merge pull request #2 from dontcare/patch-1
frol Aug 7, 2011
d2d9e8e
add version and name to setup.py
Dec 1, 2011
957a455
Merge branch 'master' of github.com:frol/django-uploadify
Dec 1, 2011
68a556b
hotfix setup.py, stupid bug
Dec 1, 2011
652d321
hotfix setup.py
Dec 1, 2011
fa14e0a
fix for django 1.4 (session key cannot be accessed through JS)
Jun 21, 2012
d67a58b
Now django-uploadify supports Uploadify v3.x; heads up! added new set…
Jun 21, 2012
e705c73
bump version to 0.2 because of new version of Uploadify
Jun 21, 2012
0a1c289
update complete/cancel/all complete signals for new and old versions …
Sep 13, 2012
ec27381
add optional jinja2 support
frol Mar 1, 2013
8b50793
merge version 0.3
frol Mar 1, 2013
b9fa687
small fix in template for jinja2 support (same template for django an…
frol Mar 1, 2013
3745da9
add UploadiFive support
frol Apr 11, 2013
9c0455a
fix readme
frol Apr 11, 2013
4c64ca9
remove debug alerts
frol Apr 11, 2013
ee6a954
fix urls import for Django 1.6 support
frol Apr 29, 2013
07b271a
fix urls compatible with Django 1.5
frol Jun 11, 2013
552a7e9
Tested on Django 1.6; Fixed accidentally hardcoded CSS and JS path
frol Aug 2, 2013
8b44809
bump version 0.3.1
frol Aug 2, 2013
c6f8c20
coffin templatetag fix; slightly changed behaviour of extra options
frol Mar 10, 2014
ebb50f7
Fixed a bug
frol Feb 6, 2015
a1a4bfb
Fixed a syntax error
frol Feb 6, 2015
646cc55
Use built-in json module instead of simplejson from django, which was…
frol Apr 2, 2015
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.pyc
.svn
.svn
*.swp
2 changes: 0 additions & 2 deletions README

This file was deleted.

95 changes: 95 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
Works on Django >= 1.2 <= 1.6. Note that there is support of different Uploadify versions and UploadiFive.

django-uploadify
================

A "Django":http://www.djangoproject.com/ re-usable app to integrate "Uploadify and UploadiFive":http://www.uploadify.com/.

.. contents::

Installation
============

Installing django-uploadify
---------------------------

#) Install package ::

pip install git+git://github.com/frol/django-uploadify.git

#) Add 'uploadify' to your INSTALLED_APPS in your project's settings.py file
#) There is support of Uploadify 2 (default), Uploadify 3 and UploadiFive v1.1.1. You can decide what version you would like to use by settings option UPLOADIFY_VERSION, available values are 2 (just int), 3 (just int) and 'uploadifive'.
#) Add a reference to uploadify in your urls.py... ::

(r'^uploadify/', include('uploadify.urls')),


Installing Uploadify
--------------------

.. _Download uploadify: http://www.uploadify.com/
#) "`Download uploadify`_"
#) Copy all of the 'uploadify' folder from the Uploadify distribution into your media root. Default is: MEDIA_URL\js\uploadify\
#) Rename the uploadify file from "jquery.uploadify.v2.1.0.min.js" (or whatever version it is) to simply "jquery.uploadify.js"
#) In uploadify/settings.py, make sure the setting UPLOADIFY_PATH is set to the correct value if the uploadify folder is installed to a location other than the default. Note that the UPLOADIFY_PATH setting is relative to the MEDIA_URL value.

Requrements
-----------

* django >= 1.2
.. _django-misc: https://github.com/ilblackdragon/django-misc/
* django-misc_ - application with a lot of useful stuff

Using django-uploadify
======================

How It Works
------------

Django-uploadify works by providing a template tag, {% multi_file_upload <upload_complete_url> %}., which takes a single parameter. The template tag will render the Uploadify jquery/flash multi-file upload interface on the page. A user may operate Uploadify, selecting and uploading multiple files. For each file that is uploaded a Django signal will be fired, containing the file data. After all uploads have been completed, the template tag will use the value of 'upload_complete_url'. It will fetch that page via AJAX, and replace the Uploadify GUI with the contents of the page (a jQuery $.load).

Code Examples
-------------

To insert the django-uploadify template tag... ::

{% load uploadify_tags %}{% multi_file_upload '/your/url/upload/complete/' %}

To add custom parameters to uploadify... ::

{% multi_file_upload '/your/url/upload/complete/' unique_id=someobj.id auto=1 %}

Creating a signal receiver... ::

def upload_received_handler(sender, request, data, **kwargs):
if data:
# process the received file here
try:
related_obj = SomeObj.objects.get(id=request.GET.get('unique_id'), owner=request.user)
except SomeObj.DoesNotExist:
return {'status': 'failed', 'status_msg': 'SomeObj not found'}
Media = Media.objects.create(image=data)
return {'status': 'ok', 'url': photo.get_preview_url()}
raise Http404

upload_received.connect(upload_received_handler, dispatch_uid='yourapp.whatever.upload_received')


Reference
=========

Client Side Event: allUploadsComplete
--------------------------------------
On the client side, a javascript event is provided to capture when all uploads have been completed. It can be bound with the following jQuery code: ::

$('#uploadify').bind('allUploadsComplete', function(e, data){
// This code executes on AllUploadsComplete event...
}

upload_complete_url Parameter
-----------------------------
When this page is fetched by the client-side javascript, the following Uploadify values are POST'ed to it:
* filesUploaded - The total number of files uploaded
* errors - The total number of errors while uploading
* allBytesLoaded - The total number of bytes uploaded
* speed - The average speed of all uploaded files
22 changes: 13 additions & 9 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
#!/usr/bin/env python

#This project forked from http://github.com/tstone/django-uploadify
#which lacked a setup.py file.
#This project forked from http://github.com/gsiegman/django-uploadify

from distutils.core import setup
from uploadify import PROJECT, VERSION

setup(name='django-uploadify',
description='Django integration of Uploadify jQuery plugin.',
author='Glenn Siegman',
author_email='gsiegman@gsiegman.com',
url='http://github.com/gsiegman/django-uploadify',
packages=['uploadify']
)
setup(
name=PROJECT,
version=VERSION,
description='Django integration of Uploadify jQuery plugin.',
author='Vlad Frolov',
author_email='frolvlad@gmail.com',
url='http://github.com/frol/django-uploadify',
packages=['uploadify', 'uploadify.templatetags'],
package_data={'uploadify': ['templates/uploadify/*.html']},
install_requires = [ 'django >= 1.3', 'django-misc' ],
)
2 changes: 2 additions & 0 deletions uploadify/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
__version__ = VERSION = '0.3.1'
__project__ = PROJECT = 'django-uploadify'
14 changes: 9 additions & 5 deletions uploadify/settings.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
from django.conf import settings
STATIC_URL = getattr(settings, 'STATIC_URL', '')
MEDIA_URL = getattr(settings, 'MEDIA_URL', '')



# Uploadify root folder path, relative to MEDIA_ROOT
UPLOADIFY_PATH = '%s%s' % (MEDIA_URL, 'js/uploadify/')
# Uploadify root folder path, relative to STATIC_URL
UPLOADIFY_PATH = getattr(settings, 'UPLOADIFY_PATH',
'%s%s' % (STATIC_URL, 'js/uploadify/'))

# Upload path that files are sent to
UPLOADIFY_UPLOAD_PATH = '%s%s' % (MEDIA_URL, 'uploads/')
UPLOADIFY_UPLOAD_PATH = getattr(settings, 'UPLOADIFY_UPLOAD_PATH',
'%s%s' % (MEDIA_URL, 'uploads/'))

# Version of uploadify that you use. Available versions are 2 or 3
UPLOADIFY_VERSION = getattr(settings, 'UPLOADIFY_VERSION', 3)
123 changes: 99 additions & 24 deletions uploadify/templates/uploadify/multi_file_upload.html
Original file line number Diff line number Diff line change
@@ -1,27 +1,102 @@
<script type="text/javascript" src="{{ uploadify_path }}swfobject.js"></script>
<script type="text/javascript" src="{{ uploadify_path }}jquery.uploadify.js"></script>
<div id="uploadify" class="multi-file-upload"><input id="fileInput" name="fileInput" type="file" /></div>
{% if uploadify_version == 'uploadifive' %}
<script type="text/javascript" src="{{ uploadify_path }}jquery.uploadifive.js"></script>
<link rel="stylesheet" type="text/css" href="{{ uploadify_path }}uploadifive.css" />
{% else %}
<script type="text/javascript" src="{{ uploadify_path }}swfobject.js"></script>
<script type="text/javascript" src="{{ uploadify_path }}jquery.uploadify.js"></script>
<link rel="stylesheet" type="text/css" href="{{ uploadify_path }}uploadify.css" />
{% endif %}
<div id="uploadify" class="multi_file_upload">
<input id="fileInput" name="fileInput" type="file" />
{% if not uploadify_auto %}
<input type="button" value="Upload" id="upload" />
{% endif %}
</div>
<script type="text/javascript">// <![CDATA[
$(document).ready(function() {
$('#fileInput').uploadify({
'uploader' : '{{ uploadify_path }}uploadify.swf',
'script' : '{% url uploadify_upload %}',
'cancelImg' : '{{ uploadify_path }}cancel.png',
'auto' : true,
'folder' : '{{ upload_path }}',
'multi' : true,
'onAllComplete' : allComplete
});
});
$(document).ready(function() {
if (/MSIE (\d+\.\d+);/.test(navigator.userAgent)) { //test for MSIE x.x;
var ieversion=new Number(RegExp.$1) // capture x.x portion and store as a number
if (ieversion < 8)
return;
}
{% if uploadify_version == 'uploadifive' %}
$('#fileInput').uploadifive({
{% else %}
$('#fileInput').uploadify({
{% endif %}
{% if uploadify_version == 2 %}
'uploader': '{{ uploadify_path }}uploadify.swf',
'script': '{% url "uploadify_upload" %}{{ uploadify_query }}',
'scriptData': {'sessionid': '{{ request.session.session_key }}', {{ uploadify_data|safe }}},
'onAllComplete': uploadify_allComplete,
'onComplete': uploadify_complete,
'onCancel': uploadify_cancelUpload,
{% else %}
{% if uploadify_version == 'uploadifive'%}
'uploadScript': '{% url "uploadify_upload" %}{{ uploadify_query }}',
'onUploadComplete': uploadify_complete,
{% else %}
'swf': '{{ uploadify_path }}uploadify.swf',
'uploader': '{% url "uploadify_upload" %}{{ uploadify_query }}',
'onUploadSuccess': uploadify_complete,
{% endif %}
'formData': {'sessionid': '{{ request.session.session_key }}', {{ uploadify_data|safe }}},
'onQueueComplete': uploadify_allComplete,
'onCancel': uploadify_cancelUpload,
{% endif %}
'cancelImg': '{{ uploadify_path }}cancel.png',
'removeCompleted': false,
{{ uploadify_options|safe }}
});

function allComplete(event, data) {
$('#uploadify').load('{{ upload_complete_url }}', {
'filesUploaded': data.filesUploaded,
'errorCount': data.errors,
'allBytesLoaded': data.allBytesLoaded,
'speed': data.speed
$('#upload').click(function(){
$('#fileInput').uploadifyUpload();
});
});
// Raise custom event
$('#uploadify').trigger('allUploadsComplete', data);
}
// ]]></script>

{% if uploadify_version == 2 %}
function uploadify_allComplete_old(event, data) {
$('#uploadify').trigger('allUploadsComplete', data);
}
function uploadify_cancelUpload_old(event, data) {
$('#uploadify').trigger('cancelUpload', data);
}
function uploadify_complete_old(event, ID, fileObj, response, data) {
var result = true;
response = $.parseJSON(response);
if (response.status == 'failed') {
var file_div = jQuery("#" + jQuery(event.target).attr('id') + ID);
file_div.addClass('uploadifyError');

file_div.find('.percentage').text(' - ' + response.status_msg);
result = false;
}
$('#uploadify').trigger('complete', [ID, fileObj, response, data]);
return result;
}
{% else %}
function uploadify_allComplete(queueData) {
$('#uploadify').trigger('allUploadsComplete', queueData);
}
function uploadify_cancelUpload(file) {
$('#uploadify').trigger('cancelUpload', file);
}
function uploadify_complete(file, data, response) {
var result = true;
data = $.parseJSON(data);
if (data.status == 'failed') {
{% if uploadify_version == 'uploadifive' %}
file.queueItem.find('.fileinfo').html(' - ' +data.status_msg);
file.queueItem.addClass('error');
{% else %}
var file_div = jQuery("#" + file.id);
file_div.addClass('uploadify-error');
file_div.find('.data').text(' - ' + data.status_msg);
{% endif %}
result = false;
}
$('#uploadify').trigger('complete', [file, data, response]);
return result;
}
{% endif %}
// ]]></script>
8 changes: 0 additions & 8 deletions uploadify/templatetags/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +0,0 @@
# To change this template, choose Tools | Templates
# and open the template in the editor.

__author__="tstone"
__date__ ="$Sep 24, 2009 3:27:35 PM$"

if __name__ == "__main__":
print "Hello World";
Loading