GithubHelp home page GithubHelp logo

alem / django-jfu Goto Github PK

View Code? Open in Web Editor NEW
148.0 10.0 73.0 493 KB

A Django Library for jQuery File Upload

License: BSD 3-Clause "New" or "Revised" License

Shell 0.29% Python 6.60% HTML 10.36% CSS 2.16% JavaScript 80.59%

django-jfu's Introduction

Django-JFU - A Django Library for jQuery File Upload

Django-JFU is designed to simplify the tasks involved in integrating jQuery File Upload (https://github.com/blueimp/jquery-file-upload) into Django. Django-JFU assumes very little and leaves the model/view design up to the user.

Other Django - jQuery File Upload implementations are full-featured but generally serve more as demonstrations than libraries for existing applications.

If you seek a tool to ease the integration of jQuery File Upload into your Django application while still having a great degree of freedom, you may find this package useful.

Demo

Installation

  1. pip install django-jfu.
  2. Add 'jfu' to INSTALLED_APPS in your project settings.py file.
  3. Add 'django.core.context_processors.request' and 'django.core.context_processors.static' to TEMPLATE_CONTEXT_PROCESSORS in settings.py.
  4. Run python manage.py collectstatic.

Usage

Django-JFU provides simple customizable template tags and override-able templates that do the work of integrating the jQuery File Upload CSS and JavaScipt and the HTML implementation found in the jQuery File Upload demo.

To place the jQuery File Upload widget in a template, simply insert the following within it:

{% load jfutags %}
{% jfu %}

Then create a view that will handle the uploaded files. The URL for the view is expected to be named 'jfu_upload' by default, although this can be customized (see Customization below).

Here is an example implementation:

In your urls.py file:

...
url( r'upload/', views.upload, name = 'jfu_upload' ),

# You may optionally define a delete url as well
url( r'^delete/(?P<pk>\d+)$', views.upload_delete, name = 'jfu_delete' ),

In your views.py file:

import os
from django.conf import settings
from django.core.urlresolvers import reverse
from django.views import generic
from django.views.decorators.http import require_POST
from jfu.http import upload_receive, UploadResponse, JFUResponse

from YOURAPP.models import YOURMODEL

@require_POST
def upload( request ):

    # The assumption here is that jQuery File Upload
    # has been configured to send files one at a time.
    # If multiple files can be uploaded simulatenously,
    # 'file' may be a list of files.
    file = upload_receive( request )

    instance = YOURMODEL( file = file )
    instance.save()

    basename = os.path.basename( instance.file.path )

    file_dict = {
        'name' : basename,
        'size' : file.size,

        'url': settings.MEDIA_URL + basename,
        'thumbnailUrl': settings.MEDIA_URL + basename,

        'deleteUrl': reverse('jfu_delete', kwargs = { 'pk': instance.pk }),
        'deleteType': 'POST',
    }

    return UploadResponse( request, file_dict )

@require_POST
def upload_delete( request, pk ):
    success = True
    try:
        instance = YOURMODEL.objects.get( pk = pk )
        os.unlink( instance.file.path )
        instance.delete()
    except YOURMODEL.DoesNotExist:
        success = False

    return JFUResponse( request, success )

Customization

Django-JFU is designed to be very customizable.

The Django-JFU template tag optionally takes two arguments: the name of the template to load and the name of the URL pointing to the upload-handling view.:

{% load jfutags %}
{% jfu 'your_fileuploader.html' 'your_uploader_URL_name' %}

A custom template can extend from the master Django-JFU template jfu/upload_form.html. There are several blocks which may be overriden for the purpose of customization:

  • JS_OPTS - The options supplied to the jQuery File Upload fileupload function.
  • JS_INIT - The initializing JavaScript
  • FILE_INPUT - The file input for the upload form.

The blocks above are most-likely what you will want to override when seeking to customize. For instance, one would go about adding a few options to the fileupload function in this manner:

# your_fileuploader.html
{% extends 'jfu/upload_form.html' %}

{% block JS_OPTS %}
autoUpload: true,
maxNumberOfFiles: 5,
sequentialUploads: true,
{% endblock %}

There are several other blocks too:

HTML Components

  • MODAL_GALLERY - The modal gallery
  • UPLOAD_FORM - The file upload form used as target for the file upload widget.
    • UPLOAD_FORM_LISTING - The table listing the files available for upload/download.
    • UPLOAD_FORM_LINDICATOR - The loading indicator shown during file processing.
    • UPLOAD_FORM_PROGRESS_BAR - The global progress information.
    • UPLOAD_FORM_BUTTON_BAR - The fileupload-buttonbar contains buttons to add/delete files and start/cancel the upload.
      • UPLOAD_FORM_BUTTON_BAR_CONTROL - Contains buttons to start/cancel the upload or delete files.
      • UPLOAD_FORM_BUTTON_BAR_ADD - Contains the file input used to add files.
        • FILE_INPUT or UPLOAD_FORM_BUTTON_BAR_ADD_FILE_INPUT - Contains the file input.
        • UPLOAD_FORM_BUTTON_BAR_ADD_EXTRA - An empty block allowing the addition of extra inputs.
      • UPLOAD_FORM_BUTTON_BAR_EXTRA - An empty block allowing the addition of extra components.
    • UPLOAD_FORM_EXTRA - An empty block allowing the addition of extra components.

CSS Components

  • CSS
    • CSS_BOOTSTRAP
    • CSS_BLUEIMP_GALLERY
    • CSS_JQUERY_FILE_UPLOAD
    • CSS_JQUERY_FILE_UPLOAD_UI
    • CSS_HTML5_SHIM
    • CSS_EXTRA

JS Components

  • JS_TEMPLATES

    • JS_DOWNLOAD_TEMPLATE

      • JS_DOWNLOAD_TEMPLATE_DELETE
      • JS_DOWNLOAD_TEMPLATE_DOWNLOAD
      • JS_DOWNLOAD_TEMPLATE_PREVIEW
      • JS_DOWNLOAD_TEMPLATE_ERROR
      • JS_DOWNLOAD_TEMPLATE_FSIZE
    • JS_UPLOAD_TEMPLATE * JS_UPLOAD_TEMPLATE_PREVIEW * JS_UPLOAD_TEMPLATE_UPLOAD * JS_UPLOAD_TEMPLATE_CONTROLS

      • JS_UPLOAD_TEMPLATE_START
      • JS_UPLOAD_TEMPLATE_CANCEL
      • JS_UPLOAD_TEMPLATE_PROGRESSBAR
  • JS_SCRIPTS

    • JS_JQUERY
    • JS_JQUERY_UI_WIDGET
    • JS_TEMPLATES_PLUGIN
    • JS_LOAD_IMAGE
    • JS_CANVAS_TO_BLOB
    • JS_BOOTSTRAP
    • JS_BLUEIMP_GALLERY
    • JS_BOOTSTRAP_IFRAME_TRANSPORT
    • JS_JQUERY_FILE_UPLOAD
    • JS_JQUERY_FILE_UPLOAD_FP
    • JS_JQUERY_FILE_UPLOAD_IMAGE
    • JS_JQUERY_FILE_UPLOAD_AUDIO
    • JS_JQUERY_FILE_UPLOAD_VIDEO
    • JS_JQUERY_FILE_UPLOAD_VALIDATE
    • JS_JQUERY_FILEUPLOAD_UI
    • JS_XDR_TRANSPORT
    • JS_EXTRA

The included JavaScript and CSS can be updated or suppressed by overriding these blocks

# your_fileuploader.html
{% extends 'jfu/upload_form.html' %}

{% block JS_JQUERY %}
    <script src={{STATIC_URL}}/js/my.newer.jquery.js />
{% endblock %}

{% block CSS_BOOTSTRAP %}
    {% comment %}
    This is already included.
    {% endcomment %}
{% endblock %}

or by replacing the static files themselves.

Demo

If you have downloaded from the repository, a simple demo application has been included in the 'demo' directory. To test it out, enter the 'demo' directory and run

./setup && ./run

Note that virtualenv is required for the demo to function.

Contribution

Django-JFU is wholly open source and welcomes contributions of any kind. Feel free to either extend it, report bugs, or provide suggestions for improvements. The author of Django-JFU can be contacted at [email protected].

django-jfu's People

Contributors

stelzzz 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-jfu's Issues

Dont upload in the demo

When i tryied to upload images in the your demo, it didnt started uploading. Why? Using Django 1.6.1 on windows

How can I pass extra variable from upload views to the template ?

JFU upload from View Repo

@require_POST
@login_required
def view_repo_upload(request):

file = upload_receive( request )
pid=int(request.REQUEST.get('product_id'))
p = Product.objects.get(id=pid)
instance = ProductGallery(product=p,image=file)
instance.save()

basename = os.path.basename( instance.image.path )
remaining_count = settings.IMAGE_COUNT - p.image_count()

file_dict = {
    'name' : basename,
    'size' : file.size,
    'url': settings.MEDIA_URL+'/images/product/'+ basename,
    'thumbnailUrl': settings.MEDIA_URL +'/images/product/'+ basename,
    'deleteUrl': reverse('jfu_delete', kwargs = { 'pk': instance.pk }),
    'deleteType': 'POST',

}


return UploadResponse( request, file_dict)

From this View , how can I pass the value of the 'remaining_count' to the corresponding template?

Please help me out ..

KeyError: 'HTTP_ACCEPT_ENCODING'

Hi

Not sure if this is a django-jfu issue but I am getting the following errors during upload which django is email to the ADMIN email address. The images do seem to be uploading but its generating 100's of emails and I'm worried this is a more serious problem. Thanks

Traceback (most recent call last):

File "/usr/local/lib/python2.7/dist-packages/django/core/handlers/base.py", line 114, in get_response
response = wrapped_callback(request, _callback_args, *_callback_kwargs)

File "/usr/local/lib/python2.7/dist-packages/django/views/decorators/http.py", line 41, in inner
return func(request, _args, *_kwargs)

File "/usr/django/htb/jfu/views.py", line 100, in upload
return UploadResponse( request, file_dict )

File "/usr/django/htb/jfu/http.py", line 49, in init
super( UploadResponse, self ).init( request, data, _args, *_kwargs )

File "/usr/django/htb/jfu/http.py", line 23, in init
mime = j if j in request.META['HTTP_ACCEPT_ENCODING'] else 'text/plain'

KeyError: 'HTTP_ACCEPT_ENCODING'

<WSGIRequest
path:/upload/,
GET:<QueryDict: {u'club': [u'114'], u'gender': [u'2'], u'price': [u'3.00'], u'event': [u'30'], u'prop_bespoke': [u'5']}>,
POST:<QueryDict: {u'csrfmiddlewaretoken': [u'p1RebfXufQx2IUdwNbm4dKktU0Mu5gEg']}>,
COOKIES:{'_dc': '1',
'_ga': 'GA1.2.811151867.1399232243',
'csrftoken': 'p1RebfXufQx2IUdwNbm4dKktU0Mu5gEg',
'sessionid': 'na16oa5yqjp10ka9uzqoddy92cktbrum'},
META:{'CONTENT_LENGTH': '5665409',
'CONTENT_TYPE': 'multipart/form-data; boundary=----WebKitFormBoundaryunOBVRBg0ZWRjB8d',
u'CSRF_COOKIE': u'p1RebfXufQx2IUdwNbm4dKktU0Mu5gEg',
'DOCUMENT_ROOT': '/var/www',
'GATEWAY_INTERFACE': 'CGI/1.1',
'HTTP_ACCEPT': 'application/json, text/javascript, /; q=0.01',
'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.8',
'HTTP_CACHE_CONTROL': 'max-age=259200',
'HTTP_CONNECTION': 'keep-alive',
'HTTP_COOKIE': 'sessionid=na16oa5yqjp10ka9uzqoddy92cktbrum; _dc=1; _ga=GA1.2.811151867.1399232243; csrftoken=p1RebfXufQx2IUdwNbm4dKktU0Mu5gEg',
'HTTP_HOST': 'www.example.com',
'HTTP_ORIGIN': 'http://www.example.com',
'HTTP_REFERER': 'http://www.example.com/upload1/',
'HTTP_USER_AGENT': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.114 Safari/537.36',
'HTTP_VIA': '1.1 example.co.uk:3128 (squid/2.6.STABLE21)',
'HTTP_X_FORWARDED_FOR': '10.32.3.180',
'HTTP_X_REQUESTED_WITH': 'XMLHttpRequest',
'PATH_INFO': u'/upload/',
'PATH_TRANSLATED': '/usr/django/htb/htb/wsgi.py/upload/',
'QUERY_STRING': '&event=30&price=3.00&club=114&gender=2&prop_bespoke=5',
'REMOTE_ADDR': '194.66.175.81',
'REMOTE_PORT': '59367',
'REQUEST_METHOD': 'POST',
'REQUEST_URI': '/upload/?&event=30&price=3.00&club=114&gender=2&prop_bespoke=5',
'SCRIPT_FILENAME': '/usr/django/htb/htb/wsgi.py',
'SCRIPT_NAME': u'',
'SERVER_ADDR': '172.31.8.216',
'SERVER_ADMIN': 'webmaster@localhost',
'SERVER_NAME': 'www.example.com',
'SERVER_PORT': '80',
'SERVER_PROTOCOL': 'HTTP/1.0',
'SERVER_SIGNATURE': '

Apache/2.2.22 (Ubuntu) Server at www.example.com Port 80\n',
'SERVER_SOFTWARE': 'Apache/2.2.22 (Ubuntu)',
'mod_wsgi.application_group': 'ip-172-31-8-216.eu-west-1.compute.internal|',
'mod_wsgi.callable_object': 'application',
'mod_wsgi.enable_sendfile': '0',
'mod_wsgi.handler_script': '',
'mod_wsgi.input_chunked': '0',
'mod_wsgi.listener_host': '',
'mod_wsgi.listener_port': '80',
'mod_wsgi.process_group': '',
'mod_wsgi.queue_start': '1401201975006359',
'mod_wsgi.request_handler': 'wsgi-script',
'mod_wsgi.script_reloading': '1',
'mod_wsgi.version': (3, 4),
'wsgi.errors': <mod_wsgi.Log object at 0x7f27585156b0>,
'wsgi.file_wrapper': <built-in method file_wrapper of mod_wsgi.Adapter object at 0x7f2730131198>,
'wsgi.input': <mod_wsgi.Input object at 0x7f27399a2cb0>,
'wsgi.multiprocess': True,
'wsgi.multithread': True,
'wsgi.run_once': False,
'wsgi.url_scheme': 'http',
'wsgi.version': (1, 0)}>

html characters !

Hi,

I am using django 1.5 and after uploading image i get the result below ... The code pieces in upload_form html is mixing with the image...

jfu_error

why does photo.file.name contain local path?

jfu - views.py
why after instance.save(), instance.name becomes sth like "C:/foo/bar.jpg" what if I need only "bar.jpg"? I tried to change it but after instance.save() it goes back again.

I need it to be a "bar.jpg" because I want to handle it with easythumb

@require_POST
def upload( request,topic_id = ''):
    if topic_id  == '':
        pass
    else:
        t = topic.objects.get(id = topic_id)
        if t.picture != None:
            return None

    # The assumption here is that jQuery File Upload
    # has been configured to send files one at a time.
    # If multiple files can be uploaded simulatenously,
    # 'file' may be a list of files.
    file = upload_receive( request )


    instance = Photo( file = file )
    
    instance.slug = os.path.basename(instance.file.name)
    instance.file.name = os.path.basename(instance.file.name)
    instance.save()


    try:
        t.picture = instance
        t.save()
    except:
        pass

    basename = os.path.basename( instance.file.path )

    file_dict = {
        'name' : basename,
        'size' : file.size,

        'url': settings.MEDIA_URL + basename,
        'thumbnailUrl': settings.MEDIA_URL + basename,

        # 'deleteUrl': reverse('jfu_delete', kwargs = { 'pk': instance.pk }),
        # 'deleteType': 'POST',
    }

    return UploadResponse( request, file_dict )

I done following the instrtuction step by step,Then i has this problem,Can you help me

AttributeError at /space/

'NoneType' object has no attribute 'META'

Request Method: GET
Request URL: http://127.0.0.1:8000/space/
Django Version: 1.4.5
Exception Type: AttributeError
Exception Value:

'NoneType' object has no attribute 'META'

Exception Location: /Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/django/middleware/csrf.py in get_token, line 49
Python Executable: /Users/bruce/Desktop/blogenv/bin/python
Python Version: 2.7.2
Python Path:

['/Users/bruce/Desktop/bcblog',
'/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/setuptools-0.6c11-py2.7.egg',
'/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/pip-1.3.1-py2.7.egg',
'/Users/bruce/Desktop/blogenv/lib/python27.zip',
'/Users/bruce/Desktop/blogenv/lib/python2.7',
'/Users/bruce/Desktop/blogenv/lib/python2.7/plat-darwin',
'/Users/bruce/Desktop/blogenv/lib/python2.7/plat-mac',
'/Users/bruce/Desktop/blogenv/lib/python2.7/plat-mac/lib-scriptpackages',
'/Users/bruce/Desktop/blogenv/Extras/lib/python',
'/Users/bruce/Desktop/blogenv/lib/python2.7/lib-tk',
'/Users/bruce/Desktop/blogenv/lib/python2.7/lib-old',
'/Users/bruce/Desktop/blogenv/lib/python2.7/lib-dynload',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-darwin',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/lib-tk',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac',
'/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/plat-mac/lib-scriptpackages',
'/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages',
'/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/PIL']

Server time: 星期二, 16 七月 2013 16:42:57 +0800
Error during template rendering

In template /Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/jfu/templates/jfu/upload_form.html, error at line 82
'NoneType' object has no attribute 'META'
72 {% block UPLOAD_FORM %}
73
74 {% comment %}
75 The file upload form used as target for the file upload widget
76 {% endcomment %}
77 <form
78 id="fileupload" action="{{ upload_handler_url }}"
79 method="POST" enctype="multipart/form-data"
80 >
81
82 {% csrf_token %}
83 {% comment %}
84 Redirect browsers with JavaScript disabled to the origin page
85 {% endcomment %}
86
87
88
89
90
91 {% block UPLOAD_FORM_BUTTON_BAR %}
92


Traceback Switch to copy-and-paste view

/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/django/core/handlers/base.py in get_response

                            response = callback(request, *callback_args, **callback_kwargs)

    ...
▶ Local vars
/Users/bruce/Desktop/bcblog/space/views.py in spaceHome

        return shortcuts.render_to_response('space/index.html')

    ...
▶ Local vars
/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/django/shortcuts/__init__.py in render_to_response

        return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)

    ...
▶ Local vars
/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/django/template/loader.py in render_to_string

            return t.render(Context(dictionary))

    ...
▶ Local vars
/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/django/template/base.py in render

                return self._render(context)

    ...
▶ Local vars
/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/django/template/base.py in _render

            return self.nodelist.render(context)

    ...
▶ Local vars
/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/django/template/base.py in render

                    bit = self.render_node(node, context)

    ...
▶ Local vars
/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/django/template/debug.py in render_node

                return node.render(context)

    ...
▶ Local vars
/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/django/template/base.py in render

                        return func(*resolved_args, **resolved_kwargs)

    ...
▶ Local vars
/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/jfu/templatetags/jfutags.py in jfu

        return t.render( Context( context ) )

    ...
▶ Local vars
/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/django/template/base.py in render

                return self._render(context)

    ...
▶ Local vars
/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/django/template/base.py in _render

            return self.nodelist.render(context)

    ...
▶ Local vars
/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/django/template/base.py in render

                    bit = self.render_node(node, context)

    ...
▶ Local vars
/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/django/template/debug.py in render_node

                return node.render(context)

    ...
▶ Local vars
/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/django/template/loader_tags.py in render

                result = self.nodelist.render(context)

    ...
▶ Local vars
/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/django/template/base.py in render

                    bit = self.render_node(node, context)

    ...
▶ Local vars
/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/django/template/debug.py in render_node

                return node.render(context)

    ...
▶ Local vars
/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/django/template/defaulttags.py in render

            if csrf_token:

    ...
▶ Local vars
/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/django/utils/functional.py in __wrapper__

                    res = func(*self.__args, **self.__kw)

    ...
▶ Local vars
/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/django/core/context_processors.py in _get_val

            token = get_token(request)

    ...
▶ Local vars
/Users/bruce/Desktop/blogenv/lib/python2.7/site-packages/django/middleware/csrf.py in get_token

        request.META["CSRF_COOKIE_USED"] = True

    ...
▶ Local vars 

How can i add {% jfu %} in another form or two form at a time

HI i am solve that issue but after that i want to make some changes in jf like
in demo photos application has only one field "file" in my application i have two field i am user this
" {% jfu 'photo_upload_form.html' %}"
in another form so how can i handle it
please help!!
Thanks in advance!!!

Added more fields in models from upload view

hi ,
i am using django-jfu
all working well,
but now i want to pass one more field from upload view
my model for image is product_image fields are

product = models.ForeignKey('Product', verbose_name=_('Product'), null=True, blank=True)
file = models.FileField( upload_to = settings.MEDIA_ROOT ,null=True, blank=True)

file are saved from upload view but i want to save 'product ' also for his relation ship so how can i do that

i am added jfu form in product add form template
please help me for solve this issue,
Thanks in Advance!!!

Can I use this code for uploading xml/txt/csv/bat/sh files?

HI,

Thanks for sharing this package.
I wanted to use this code for uploading xml/txt/csv/bat/sh files and opening them in browsers using "ACE Editor". But I am facing problems in configuring it for these other file types.

Could you please help me with this?
Regards,
Gaurav

Static content collision

It should be a good idea just to move static content to /jfu/static/jfu/... in order to avoid collisions with other apps static content.
Let me know if you need PR

View function executed twice - probable bug

We are trying to use django-jfu in a project. The view function is being executed twice. The behavior is reproducible with the demo app as follows:

  • Modify Home get_context_data (the view function for upload) as follows:

def get_context_data(self, *_kwargs):
context = super( Home, self ).get_context_data( _kwargs )
context['accepted_mime_types'] = ['image/
']
context['set_id'] = uuid.uuid4().hex
print '===== ', context['set_id']
return context

  • Run the server and go to "http://localhost:8000/". You'll get output that is something like this:

    (venv)~/.../django-jfu-2.0.1/demo$ ./manage.py runserver
    Validating models...

    0 errors found
    March 29, 2014 - 10:32:30
    Django version 1.6.2, using settings 'demo.settings'
    Starting development server at http://127.0.0.1:8000/
    Quit the server with CONTROL-C.
    ===== e1171839d4d04815893c01cccf406f46
    [29/Mar/2014 10:32:40] "GET / HTTP/1.1" 200 12766
    [29/Mar/2014 10:32:40] "GET /static/css/jquery.fileupload-ui.css HTTP/1.1" 304 0
    [29/Mar/2014 10:32:40] "GET /static/js/vendor/jquery.ui.widget.js HTTP/1.1" 304 0
    [29/Mar/2014 10:32:40] "GET /static/css/jquery.fileupload.css HTTP/1.1" 304 0
    [29/Mar/2014 10:32:40] "GET /static/demo/tmpl.min.js HTTP/1.1" 304 0
    [29/Mar/2014 10:32:40] "GET /static/demo/blueimp-gallery.min.css HTTP/1.1" 304 0
    [29/Mar/2014 10:32:40] "GET /static/demo/load-image.min.js HTTP/1.1" 304 0
    [29/Mar/2014 10:32:40] "GET /static/demo/canvas-to-blob.min.js HTTP/1.1" 304 0
    [29/Mar/2014 10:32:40] "GET /static/demo/jquery.blueimp-gallery.min.js HTTP/1.1" 304 0
    [29/Mar/2014 10:32:40] "GET /static/js/jquery.iframe-transport.js HTTP/1.1" 304 0
    [29/Mar/2014 10:32:40] "GET /static/js/jquery.fileupload.js HTTP/1.1" 304 0
    [29/Mar/2014 10:32:40] "GET /static/js/jquery.fileupload-process.js HTTP/1.1" 304 0
    [29/Mar/2014 10:32:40] "GET /static/js/jquery.fileupload-image.js HTTP/1.1" 304 0
    [29/Mar/2014 10:32:40] "GET /static/js/jquery.fileupload-validate.js HTTP/1.1" 304 0
    [29/Mar/2014 10:32:40] "GET /static/js/jquery.fileupload-ui.js HTTP/1.1" 304 0
    [29/Mar/2014 10:32:40] "GET /static/js/jquery.fileupload-video.js HTTP/1.1" 304 0
    [29/Mar/2014 10:32:40] "GET /static/js/jquery.fileupload-audio.js HTTP/1.1" 304 0
    ===== 0e5fb5e18c1948fda29ce9ae22972b7a
    [29/Mar/2014 10:32:40] "GET / HTTP/1.1" 200 12766

Clearly the view function was executed twice.

My JS is not especially good but some debugging suggests that the issue is in or near jquery.ui.widget... .

As a point of reference, the use case here is to upload a group of files that must be processed/managed as a set. In our particular case, multiple files are uploaded together. There is a single control file and multiple data files. The control file and sample data files need to be associated with one another. In our case we are using the set_id to hold that association.

How to handlle each uploaded file?

Hi,

First of all, thank you for sharing the code.

I would like to know how to handle each individual uploaded file, before it is saved to disk?
Is there a function that I should implement or modify?

Thanks!

How to add args to upload view?

Hello!
How to use JFU for add variable in upload view?
For example, set some keys for YourUploadModel

@require_POST
def upload( request, some_key ):
    file = upload_receive( request )

    instance = YourUploadModel( some_key=some_key, sfile_field = file )
    instance.save()
...

How we make jfu form ass mandatory

hi i am using jfu
now i want to know how we make jfu form as mandatory or required true
using javascript or anything

please help
Thanks in advanced!!!

How to add fields to be uploaded with files

How would I add some more fields that are associated with each upload. For example I want the user to give a title each uploaded file and have it saved in the Model. I looked at the demo but I am not clear on how to do that?

Take the control over this module and merge the best

Hi all,

The maintener of this module seems lost from here, and a lot of forks have been done for fixing a lot of various issues.
The fact is that the module on pypi seems to refer to this outdated repo.

Is there a way to select a fork as a new reference in which pull issue will be merged, or several contributors will be integrated to the project?
Then, we may try to merge all the forks.

Thanks

Uncaught TypeError: Object [object Object] has no method 'live'

Hey there,

Thanks for a great package!

I just wanted to let you know that I'm getting a Javascript error with jQuery 1.10.1:

"Uncaught TypeError: Object [object Object] has no method 'live' "

It seems to stem from the following file in upload_form.html, found in the JS_DIALOG block (line 489 for me):

$('#fileupload .files a:not([target^=_blank])').live(

Please note that .live() is deprecated as of jQuery 1.7, and .on() should be used instead (http://api.jquery.com/live/)

Thanks again, and with the best regards,
Martin

Image not render properly

Hi i am using your liabrary for multiuplod in django

I add url in my applications urls.py

#url for JFU
url( r'upload/', 'products.views.upload', name = 'jfu_upload' ),
# You may optionally define a delete url as well
url( r'^delete/(?P\d+)$', 'products.views.upload_delete', name = 'jfu_delete' ),
and my view is

@require_POST
def upload( request ):

# The assumption here is that jQuery File Upload
# has been configured to send files one at a time.
# If multiple files can be uploaded simulatenously,
# 'file' may be a list of files.
file = upload_receive( request )

instance = Product( file = file )
#instance = Product_image( file = file )
instance.save()

basename = os.path.basename( instance.file.path )

file_dict = {
    'name' : basename,
    'size' : file.size,

    'url': settings.MEDIA_URL + basename,
    'thumbnailUrl': settings.MEDIA_URL + basename,

    'deleteUrl': reverse('jfu_delete', kwargs = { 'pk': instance.pk }),
    'deleteType': 'POST',
}

return UploadResponse( request, file_dict )

@require_POST
def upload_delete( request, pk ):
success = True
try:
instance = Product.objects.get( pk = pk )
os.unlink( instance.file.path )
instance.delete()
except Product.DoesNotExist:
success = False

return JFUResponse( request, success )

in my models.py have many fields

in my template

{% load jfutags %}
{% jfu %}
with this it render image uplod control properly after when i click on "Add files" it shows select dialog after i select images and click on "open" so it not render selected image in html

in console it shows
"TypeError: $(...).fileupload is not a function"
Error
so how can i solve this
Thanks in advance!!!

Initial data fot block JS_DOWNLOAD_TEMPLATE

Hello! Is it possible to init data in JS_DOWNLOAD_TEMPLATE block?
I need show uploaded files before.
In code used "o" variable. How to set initial data for "o"?

...
<script id="template-download" type="text/x-tmpl">
{{ JQ_OPEN }} for (var i=0, file; file=o.files[i]; i++) { {{ JQ_CLOSE }}
...

Thanks!

set limit for image upload

hi,
I want to set limit for image upload

i add this block in my template

{% block JS_OPTS %}
autoUpload: true,
maxNumberOfFiles: 2,
sequentialUploads: true,
{% endblock %}

but can't work
how can i do this ,
pls help,
thanks in advance!!!

Update multiple image object django_jfu

hi ,
i am using django-jfu successfully
now i want to upate existing multiupload image form
so how can i do that
Means how we create view like upload_edit or upload_update for existing added object

please help,
Thanks in advance !!!

Reverse for 'jfu_upload' with arguments '()'

i am trying to impliment this JFU but it always made the same error

Reverse for 'jfu_upload' with arguments '()' and keyword arguments '{}' not found. 0 pattern(s) tried: []
1 {% extends 'dossier/index.html' %}
2
3 {% block content %}
4 {% load jfutags %}
5 {% jfu 'photo_upload_form.html' %}
6
7 {% endblock %}

Issues running on Windows

Ran into a couple of issues running this on Windows:

  1. demo/wsgi.py loads activate_this.py from venv/bin/ but it is actually found in venv/scripts/
  2. using the demo UI, you cannot delete uploaded files. In demo/photos/views.py, the call to os.unlink() fails with "The process cannot access the file because it is being used by another process". Basically the uploaded JPG/PNG is locked by the Python process and cannot be deleted. Not sure if that is your demo code, or the underlying jquery file uploader failing to close a file handle, or otherwise unlock the file.

django 1.9 - RemovedInDjango110Warning: django.core.context_processors

Hi Alem,

Many thanks for making django-jfu available!

I have just upgraded my django app to django 1.9 and I see that the development server is returning this warning/error:

.../lib/python2.7/site-packages/jfu/templatetags/jfutags.py:1: RemovedInDjango110Warning: django.core.context_processors is deprecated in favor of django.template.context_processors.
from django.core.context_processors import csrf

Is there any chance you might be able to release a new version to fix this?

Many thanks!

Adam

How to get the uploads ID

I've got a two step upload process. After the user has uploaded some files, she has to fill a form with contact information. The contact information need to be mapped to the uploads. Is there a away to get the uploads? Thanks!

Bootstrap 3?

Hi

Are there any plans to update this excellent project to Bootstrap 3? As it stands progress bars and Glyphicons fail to render if you combine it with a project using Bootstrap 3.

Thanks

django-jfu

I have been using django-jfu in a project for a year or so. It stopped working in Firefox when I updated to FF v 44.0.2 and it is still broken in 45.0.1. It still works in Chrome, IE and Safari. There appear to be at least two problems. When selecting multiple files only one of them appears in the upload list. The second issue is when uploading the front end send an empty upload request to the backend. Any thoughts on what's going on or how I might further debug this?

Thanks!

esther

for image i use s3 amazon bucket so it return 500 INTERNAL SERVER ERROR

i use django-jfu it work perfectly in normal uploading
but when i use amazon bucket for store images it return
500 INTERNAL SERVER ERROR

NotImplementedError at /en/upload_photo/
This backend doesn't support absolute paths.

but image store successfully but it gives error
i attach image of that
jfu_error

this error how can i solve this error

please remove blueimp-gallery

I strongly suggest remove blueimp-gallery from code.
I spend many hours trying debug, why my java scripts stop working after plug-in django-jfu in template. Source of trouble was blueimp-gallery.

It ts very conflictable plugin and far better solution exist for displaing pictures.
And jfu should be "UPLOAD" not "display" solution.

Wrong pathes in css

File "/demo/blueimp-gallery.min.css" contains incorrect urls.

For example:
.blueimp-gallery>.slides>.slide-error{
background:url(../img/error.png) center no-repeat
}

But in directory "static/img" this file does not exists!
It causes errors in CSS/JS compressors.

In one of my templates i'm using
{% extends "jfu/upload_form.html" %}

This file contains:

So, when I run collectstatic, file "demo/blueimp-gallery.min.css" attaches to the list of files, which should be compressed

P.S. I'm sorry for my English

'NoneType' object has no attribute 'META'

First of all, sorry to open up a second issue regarding this error. I believe it's exactly the same one that ksgt00016758 was having trouble with, but I don't understand how he managed to fix it.

I added 'django.core.context_processors.request' as you said in your instructions:
TEMPLATE_CONTEXT_PROCESSORS = global_settings.TEMPLATE_CONTEXT_PROCESSORS + (
'django.core.context_processors.request',
)

Debug page:
'NoneType' object has no attribute 'META'

Request Method: GET
Request URL: http://127.0.0.1:8000/
Django Version: 1.4.1
Exception Type: AttributeError
Exception Value:

'NoneType' object has no attribute 'META'

Exception Location: /usr/lib/python2.7/dist-packages/django/middleware/csrf.py in get_token, line 49
Python Executable: /usr/bin/python
Python Version: 2.7.3
Python Path:

['/home/bristol/kalakotkas',
'/usr/lib/python2.7',
'/usr/lib/python2.7/plat-linux2',
'/usr/lib/python2.7/lib-tk',
'/usr/lib/python2.7/lib-old',
'/usr/lib/python2.7/lib-dynload',
'/usr/local/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages',
'/usr/lib/python2.7/dist-packages/PIL',
'/usr/lib/python2.7/dist-packages/gst-0.10',
'/usr/lib/python2.7/dist-packages/gtk-2.0',
'/usr/lib/pymodules/python2.7',
'/usr/lib/python2.7/dist-packages/ubuntu-sso-client']

Server time: Sun, 18 Aug 2013 17:13:59 -0400
Error during template rendering

In template /usr/local/lib/python2.7/dist-packages/jfu/templates/jfu/upload_form.html, error at line 82
'NoneType' object has no attribute 'META'
72 {% block UPLOAD_FORM %}
73
74 {% comment %}
75 The file upload form used as target for the file upload widget
76 {% endcomment %}
77 <form
78 id="fileupload" action="{{ upload_handler_url }}"
79 method="POST" enctype="multipart/form-data"
80 >
81
82 {% csrf_token %}
83
84 {% comment %}
85 Redirect browsers with JavaScript disabled to the origin page
86 {% endcomment %}
87
88
89
90
91
92 {% block UPLOAD_FORM_BUTTON_BAR %}
Traceback Switch to copy-and-paste view

/usr/lib/python2.7/dist-packages/django/core/handlers/base.py in get_response

                            response = callback(request, *callback_args, **callback_kwargs)

    ...
▶ Local vars
/home/bristol/kalakotkas/imageboard/views.py in home

        return render_to_response('home.html', c)

    ...
▶ Local vars
/usr/lib/python2.7/dist-packages/django/shortcuts/__init__.py in render_to_response

        return HttpResponse(loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)

    ...
▶ Local vars
/usr/lib/python2.7/dist-packages/django/template/loader.py in render_to_string

            return t.render(Context(dictionary))

    ...
▶ Local vars
/usr/lib/python2.7/dist-packages/django/template/base.py in render

                return self._render(context)

    ...
▶ Local vars
/usr/lib/python2.7/dist-packages/django/template/base.py in _render

            return self.nodelist.render(context)

    ...
▶ Local vars
/usr/lib/python2.7/dist-packages/django/template/base.py in render

                    bit = self.render_node(node, context)

    ...
▶ Local vars
/usr/lib/python2.7/dist-packages/django/template/debug.py in render_node

                return node.render(context)

    ...
▶ Local vars
/usr/lib/python2.7/dist-packages/django/template/base.py in render

                        return func(*resolved_args, **resolved_kwargs)

    ...
▶ Local vars
/usr/local/lib/python2.7/dist-packages/jfu/templatetags/jfutags.py in jfu

        return t.render( Context( context ) )

    ...
▶ Local vars
/usr/lib/python2.7/dist-packages/django/template/base.py in render

                return self._render(context)

    ...
▶ Local vars
/usr/lib/python2.7/dist-packages/django/template/base.py in _render

            return self.nodelist.render(context)

    ...
▶ Local vars
/usr/lib/python2.7/dist-packages/django/template/base.py in render

                    bit = self.render_node(node, context)

    ...
▶ Local vars
/usr/lib/python2.7/dist-packages/django/template/debug.py in render_node

                return node.render(context)

    ...
▶ Local vars
/usr/lib/python2.7/dist-packages/django/template/loader_tags.py in render

                result = self.nodelist.render(context)

    ...
▶ Local vars
/usr/lib/python2.7/dist-packages/django/template/base.py in render

                    bit = self.render_node(node, context)

    ...
▶ Local vars
/usr/lib/python2.7/dist-packages/django/template/debug.py in render_node

                return node.render(context)

    ...
▶ Local vars
/usr/lib/python2.7/dist-packages/django/template/defaulttags.py in render

            if csrf_token:

    ...
▶ Local vars
/usr/lib/python2.7/dist-packages/django/utils/functional.py in __wrapper__

                    res = func(*self.__args, **self.__kw)

    ...
▶ Local vars
/usr/lib/python2.7/dist-packages/django/core/context_processors.py in _get_val

            token = get_token(request)

    ...
▶ Local vars
/usr/lib/python2.7/dist-packages/django/middleware/csrf.py in get_token

        request.META["CSRF_COOKIE_USED"] = True

    ...
▶ Local vars 

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.