Skip to content

Commit 7911103

Browse files
committed
Basic version 8.8.2 added
1 parent 76999a7 commit 7911103

File tree

6 files changed

+231
-4
lines changed

6 files changed

+231
-4
lines changed

fileupload/static/js/jquery.cookie.js

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
/*!
2+
* jQuery Cookie Plugin v1.3.1
3+
* https://github.com/carhartl/jquery-cookie
4+
*
5+
* Copyright 2013 Klaus Hartl
6+
* Released under the MIT license
7+
*/
8+
(function ($, document, undefined) {
9+
10+
var pluses = /\+/g;
11+
12+
function raw(s) {
13+
return s;
14+
}
15+
16+
function decoded(s) {
17+
return unRfc2068(decodeURIComponent(s.replace(pluses, ' ')));
18+
}
19+
20+
function unRfc2068(value) {
21+
if (value.indexOf('"') === 0) {
22+
// This is a quoted cookie as according to RFC2068, unescape
23+
value = value.slice(1, -1).replace(/\\"/g, '"').replace(/\\\\/g, '\\');
24+
}
25+
return value;
26+
}
27+
28+
function fromJSON(value) {
29+
return config.json ? JSON.parse(value) : value;
30+
}
31+
32+
var config = $.cookie = function (key, value, options) {
33+
34+
// write
35+
if (value !== undefined) {
36+
options = $.extend({}, config.defaults, options);
37+
38+
if (value === null) {
39+
options.expires = -1;
40+
}
41+
42+
if (typeof options.expires === 'number') {
43+
var days = options.expires, t = options.expires = new Date();
44+
t.setDate(t.getDate() + days);
45+
}
46+
47+
value = config.json ? JSON.stringify(value) : String(value);
48+
49+
return (document.cookie = [
50+
encodeURIComponent(key), '=', config.raw ? value : encodeURIComponent(value),
51+
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
52+
options.path ? '; path=' + options.path : '',
53+
options.domain ? '; domain=' + options.domain : '',
54+
options.secure ? '; secure' : ''
55+
].join(''));
56+
}
57+
58+
// read
59+
var decode = config.raw ? raw : decoded;
60+
var cookies = document.cookie.split('; ');
61+
var result = key ? null : {};
62+
for (var i = 0, l = cookies.length; i < l; i++) {
63+
var parts = cookies[i].split('=');
64+
var name = decode(parts.shift());
65+
var cookie = decode(parts.join('='));
66+
67+
if (key && key === name) {
68+
result = fromJSON(cookie);
69+
break;
70+
}
71+
72+
if (!key) {
73+
result[name] = fromJSON(cookie);
74+
}
75+
}
76+
77+
return result;
78+
};
79+
80+
config.defaults = {};
81+
82+
$.removeCookie = function (key, options) {
83+
if ($.cookie(key) !== null) {
84+
$.cookie(key, null, options);
85+
return true;
86+
}
87+
return false;
88+
};
89+
90+
})(jQuery, document);

fileupload/templates/base.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<span class="icon-bar"></span>
3333
<span class="icon-bar"></span>
3434
</button>
35-
<a class="navbar-brand" href="https://github.com/blueimp/jQuery-File-Upload">Django jQuery File Upload</a>
35+
<a class="navbar-brand" href="https://github.com/sigurdga/django-jquery-file-upload">Django jQuery File Upload</a>
3636
</div>
3737
<div class="navbar-collapse collapse">
3838
<ul class="nav navbar-nav">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<!DOCTYPE HTML>
2+
<html lang="en">
3+
<head>
4+
<!-- Force latest IE rendering engine or ChromeFrame if installed -->
5+
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"><![endif]-->
6+
<meta charset="utf-8">
7+
<title>Django jQuery File Upload Demo - Basic version</title>
8+
<meta name="description" content="File Upload widget with multiple file selection, drag&amp;drop support and progress bar for jQuery. Supports cross-domain, chunked and resumable file uploads. Works with any server-side platform (PHP, Python, Ruby on Rails, Java, Node.js, Go etc.) that supports standard HTML form file uploads.">
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
10+
<!-- Bootstrap styles -->
11+
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.0/css/bootstrap.min.css">
12+
<!-- Generic page styles -->
13+
<link rel="stylesheet" href="{{ STATIC_URL }}css/style.css">
14+
<!-- CSS to style the file input field as button and adjust the Bootstrap progress bars -->
15+
<link rel="stylesheet" href="{{ STATIC_URL }}css/jquery.fileupload-ui.css">
16+
</head>
17+
<body>
18+
<div class="navbar navbar-default navbar-fixed-top">
19+
<div class="container">
20+
<div class="navbar-header">
21+
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-fixed-top .navbar-collapse">
22+
<span class="icon-bar"></span>
23+
<span class="icon-bar"></span>
24+
<span class="icon-bar"></span>
25+
</button>
26+
<a class="navbar-brand" href="https://github.com/sigurdga/django-jquery-file-upload">Django jQuery File Upload</a>
27+
</div>
28+
<div class="navbar-collapse collapse">
29+
<ul class="nav navbar-nav">
30+
<li class="active"><a href="#">Demo</a></li>
31+
<li><a href="https://github.com/sigurdga/django-jquery-file-upload">Source Code</a></li>
32+
<li><a href="https://github.com/blueimp/jQuery-File-Upload/wiki">Documentation</a></li>
33+
</ul>
34+
</div>
35+
</div>
36+
</div>
37+
<div class="container">
38+
<h1>jQuery File Upload Demo</h1>
39+
<h2 class="lead">Basic version</h2>
40+
<ul class="nav nav-tabs">
41+
<li class="active"><a href="/upload/basic">Basic</a></li>
42+
<li><a href="basic-plus.html" style="display:none;">Basic Plus</a></li>
43+
<li><a href="/upload/new">Basic Plus UI</a></li>
44+
<li><a href="angularjs.html" style="display:none;">AngularJS</a></li>
45+
<li><a href="jquery-ui.html" style="display:none;">jQuery UI</a></li>
46+
</ul>
47+
<br>
48+
<blockquote>
49+
<p>File Upload widget with multiple file selection, drag&amp;drop support and progress bar for jQuery.<br>
50+
Supports cross-domain, chunked and resumable file uploads.<br>
51+
Works with any server-side platform (PHP, Python, Ruby on Rails, Java, Node.js, Go etc.) that supports standard HTML form file uploads.</p>
52+
</blockquote>
53+
<br>
54+
{% csrf_token %}
55+
<!-- The fileinput-button span is used to style the file input field as button -->
56+
<span class="btn btn-success fileinput-button">
57+
<i class="glyphicon glyphicon-plus"></i>
58+
<span>Select files...</span>
59+
<!-- The file input field used as target for the file upload widget -->
60+
<input id="fileupload" type="file" name="file" multiple>
61+
</span>
62+
<br>
63+
<br>
64+
<!-- The global progress bar -->
65+
<div id="progress" class="progress">
66+
<div class="progress-bar progress-bar-success"></div>
67+
</div>
68+
<!-- The container for the uploaded files -->
69+
<div id="files" class="files"></div>
70+
<br>
71+
<div class="panel panel-default">
72+
<div class="panel-heading">
73+
<h3 class="panel-title">Demo Notes</h3>
74+
</div>
75+
<div class="panel-body">
76+
<ul>
77+
<li>You can <strong>drag &amp; drop</strong> files from your desktop on this webpage (see <a href="https://github.com/blueimp/jQuery-File-Upload/wiki/Browser-support">Browser support</a>).</li>
78+
<li>Please refer to the <a href="https://github.com/blueimp/jQuery-File-Upload">project website</a> and <a href="https://github.com/blueimp/jQuery-File-Upload/wiki">documentation</a> for more information.</li>
79+
<li>Built with Twitter's <a href="http://twitter.github.com/bootstrap/">Bootstrap</a> CSS framework and Icons from <a href="http://glyphicons.com/">Glyphicons</a>.</li>
80+
</ul>
81+
</div>
82+
</div>
83+
</div>
84+
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
85+
<!-- The jQuery UI widget factory, can be omitted if jQuery UI is already included -->
86+
<script src="{{ STATIC_URL }}js/vendor/jquery.ui.widget.js"></script>
87+
<!-- The Iframe Transport is required for browsers without support for XHR file uploads -->
88+
<script src="{{ STATIC_URL }}js/jquery.iframe-transport.js"></script>
89+
<!-- The basic File Upload plugin -->
90+
<script src="{{ STATIC_URL }}js/jquery.fileupload.js"></script>
91+
<!-- Bootstrap JS is not required, but included for the responsive demo navigation -->
92+
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
93+
<script src="{{ STATIC_URL }}js/csrf.js"></script>
94+
<script src="{{ STATIC_URL }}js/jquery.cookie.js"></script>
95+
<script>
96+
/*jslint unparam: true */
97+
/*global window, $ */
98+
function csrfSafeMethod(method) {
99+
// these HTTP methods do not require CSRF protection
100+
return (/^(GET|HEAD|OPTIONS|TRACE)$/.test(method));
101+
}
102+
$(function () {
103+
'use strict';
104+
// Change this to the location of your server-side upload handler:
105+
var url = '/upload/basic/';
106+
var csrftoken = $.cookie('csrftoken');
107+
$('#fileupload').fileupload({
108+
url: url,
109+
crossDomain: false,
110+
beforeSend: function(xhr, settings) {
111+
if (!csrfSafeMethod(settings.type)) {
112+
xhr.setRequestHeader("X-CSRFToken", csrftoken);
113+
}
114+
},
115+
dataType: 'json',
116+
done: function (e, data) {
117+
$.each(data.result.files, function (index, file) {
118+
$('<p/>').text(file.name).appendTo('#files');
119+
});
120+
},
121+
progressall: function (e, data) {
122+
var progress = parseInt(data.loaded / data.total * 100, 10);
123+
$('#progress .progress-bar').css(
124+
'width',
125+
progress + '%'
126+
);
127+
}
128+
}).prop('disabled', !$.support.fileInput)
129+
.parent().addClass($.support.fileInput ? undefined : 'disabled');
130+
});
131+
</script>
132+
</body>
133+
</html>

fileupload/templates/fileupload/picture_form.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<h1>jQuery File Upload Demo</h1>
77
<h2 class="lead">Basic Plus UI version</h2>
88
<ul class="nav nav-tabs">
9-
<li><a href="basic.html" style="display:none;">Basic</a></li>
9+
<li><a href="/upload/basic">Basic</a></li>
1010
<li><a href="basic-plus.html" style="display:none;">Basic Plus</a></li>
1111
<li class="active"><a href="/upload/new/">Basic Plus UI</a></li>
1212
<li><a href="angularjs.html" style="display:none;">AngularJS</a></li>

fileupload/urls.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from django.conf.urls import patterns, url
2-
from fileupload.views import PictureCreateView, PictureDeleteView
2+
from fileupload.views import BasicVersionCreateView, PictureCreateView, PictureDeleteView
33

44
urlpatterns = patterns('',
5+
(r'^basic/$', BasicVersionCreateView.as_view(), {}, 'upload-basic'),
56
(r'^new/$', PictureCreateView.as_view(), {}, 'upload-new'),
67
(r'^delete/(?P<pk>\d+)$', PictureDeleteView.as_view(), {}, 'upload-delete'),
78
url(r'^view/$', 'fileupload.views.PictureListView', name='upload-view'),

fileupload/views.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ def form_valid(self, form):
4141
response['Content-Disposition'] = 'inline; filename=files.json'
4242
return response
4343

44-
44+
class BasicVersionCreateView(PictureCreateView):
45+
model = Picture
46+
template_name_suffix = '_basic_form'
47+
4548
class PictureDeleteView(DeleteView):
4649
model = Picture
4750

0 commit comments

Comments
 (0)