Hi, I'm trying to use an example posted on the "github" the link is http://github.com/tstone/django-uploadify. And I'm having trouble getting work. can you help me? I followed step by step, but does not work.
Accessing the "URL" / upload / the only thing is that returns "True"
part of settings.py
import os
PROJECT_ROOT_PATH = os.path.dirname(os.path.abspath(__file__))
MEDIA_ROOT = os.path.join(PROJECT_ROOT_PATH, 'media')
TEMPLATE_DIRS = ( os.path.join(PROJECT_ROOT_PATH, 'templates'))
urls.py
from django.conf.urls.defaults import *
from django.conf import settings
from teste.uploadify.views import *
from django.contrib import admin
admin.autodiscover()
urlpatterns = patterns('',
(r'^admin/', include(admin.site.urls)),
url(r'upload/$', upload, name='uploadify_upload'),
)
views.py
from django.http import HttpResponse
import django.dispatch
upload_received = django.dispatch.Signal(providing_args=['data'])
def upload(request, *args, **kwargs):
if request.method == 'POST':
if request.FILES:
upload_received.send(sender='uploadify', data=request.FILES['Filedata'])
return HttpResponse('True')
models.py
from django.db import models
def upload_received_handler(sender, data, **kwargs):
if file:
new_media = Media.objects.create(
file = data,
new_upload = True,
)
new_media.save()
upload_received.connect(upload_received_handler, dispatch_uid='uploadify.media.upload_received')
class Media(models.Model):
file = models.FileField(upload_to='images/upload/', null=True, blank=True)
new_upload = models.BooleanField()
uploadify_tags.py
from django import template
from teste import settings
register = template.Library()
@register.inclusion_tag('uploadify/multi_file_upload.html', takes_context=True)
def multi_file_upload(context, upload_complete_url):
"""
* 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
"""
return {
'upload_complete_url' : upload_complete_url,
'uploadify_path' : settings.UPLOADIFY_PATH, # checar essa linha
'upload_path' : settings.UPLOADIFY_UPLOAD_PATH,
}
template - uploadify/multi_file_upload.html
{% load uploadify_tags }{ multi_file_upload '/media/images/upload/' %}
<script type="text/javascript" src="{{ MEDIA_URL }}js/swfobject.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}js/jquery.uploadify.js"></script>
<div id="uploadify" class="multi-file-upload"><input id="fileInput" name="fileInput" type="file" /></div>
<script type="text/javascript">// <![CDATA[
$(document).ready(function() {
$('#fileInput').uploadify({
'uploader' : '/media/swf/uploadify.swf',
'script' : '{% url uploadify_upload %}',
'cancelImg' : '/media/images/uploadify-remove.png/',
'auto' : true,
'folder' : '/media/images/upload/',
'multi' : true,
'onAllComplete' : allComplete
});
});
function allComplete(event, data) {
$('#uploadify').load('{{ upload_complete_url }}', {
'filesUploaded' : data.filesUploaded,
'errorCount' : data.errors,
'allBytesLoaded' : data.allBytesLoaded,
'speed' : data.speed
});
// raise custom event
$('#uploadify') .trigger('allUploadsComplete', data);
}
// ]]</script>