Skip to content
This repository has been archived by the owner on Mar 13, 2019. It is now read-only.

Commit

Permalink
Fix multiple upload problem
Browse files Browse the repository at this point in the history
  • Loading branch information
josecolella committed Jun 30, 2014
1 parent a3f1143 commit c5e01ea
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 52 deletions.
9 changes: 5 additions & 4 deletions visualization/static/visualization/js/authenticate.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ $(function () {
}
clearForm();
},
error: function(data) {
error: function() {
vex.dialog.alert("User could not be saved");
}
})
Expand Down Expand Up @@ -186,13 +186,14 @@ $(function () {
success: function(response) {
console.log(response);
if(response.status == 1) {
location.href = '/';
vex.dialog.alert('Account Created. Sign In');
$("#signin").click();
} else if(data.status == 0) {
vex.dialog.alert("Unable to create account");
}
},
error: function(data) {
vex.dialog.alert("User could not be saved");
error: function() {
vex.dialog.alert("Invalid Sign Up");
}
})
.done(function() {
Expand Down
70 changes: 35 additions & 35 deletions visualization/templates/visualization/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
{% load staticfiles %}
<!-- Project CSS-->

{# <link rel="stylesheet" href="{% static "visualization/css/dropzone.css" %}"/>#}
{# <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/dropzone/3.9.0/css/dropzone.css"/>#}
{# <link rel="stylesheet" href="{% static "visualization/css/dropzone.css" %}"/>#}
{# <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/dropzone/3.9.0/css/dropzone.css"/>#}
<link rel="stylesheet" href="{% static "visualization/dropzone-3.8.4/css/dropzone.min.css" %}"/>
<link rel="stylesheet" href="{% static "visualization/codemirror/lib/codemirror.css" %}"/>
<link rel="stylesheet" href="{% static "visualization/css/dashboard.css"%}" />
Expand All @@ -16,14 +16,14 @@
<link rel="stylesheet" href="{% static 'visualization/jquery/jquery.handsontable.full.css' %}"/>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/dc/1.7.0/dc.css"/>

{# <link rel="stylesheet" href="http://dc-js.github.io/dc.js/css/dc.css"/>#}
{# <link rel="stylesheet" href="http://dc-js.github.io/dc.js/css/dc.css"/>#}
{% endblock stylesheets %}
{% block headjs %}
<script src="{% static "visualization/jquery/jquery.handsontable.full.js" %}"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/d3/3.4.8/d3.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/crossfilter/1.3.7/crossfilter.min.js"></script>
{# <script src="{% static 'visualization/dc/dc.min.js' %}"></script>#}
{# <script src="//dc-js.github.io/dc.js/js/dc.js"></script>#}
{# <script src="{% static 'visualization/dc/dc.min.js' %}"></script>#}
{# <script src="//dc-js.github.io/dc.js/js/dc.js"></script>#}
<script src="//cdnjs.cloudflare.com/ajax/libs/dc/1.7.0/dc.min.js"></script>
<script src="{% static "visualization/js/visualize.js" %}"></script>
<script src="{% static "visualization/js/exports.js" %}"></script>
Expand Down Expand Up @@ -178,10 +178,11 @@ <h4 class="panel-title">
{% block javascript %}
{% load staticfiles %}
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.4/jquery-ui.min.js"></script>
{# <script src="//cdnjs.cloudflare.com/ajax/libs/dropzone/3.9.0/dropzone.min.js"></script>#}
{# <script src="//cdnjs.cloudflare.com/ajax/libs/dropzone/3.9.0/dropzone.min.js"></script>#}
<script src="{% static "visualization/dropzone-3.8.4/dropzone.min.js" %}"></script>
<script type="text/javascript">
var limit = 15;
var responses = [];
var emptyFileMessage = function(file) {
var message = "Uploaded Files cannot be empty<br/>File: " + "<i>"+file["name"] +"</i> "+ 'Size: '+ file["size"];
return message;
Expand All @@ -194,12 +195,12 @@ <h4 class="panel-title">
Dropzone.options.myDropzone = {

// Prevents Dropzone from uploading dropped files immediately
autoProcessQueue : false,
autoProcessQueue : true,
// The filter for the accepted files
acceptedFiles: '.xls,.xlsx,.txt,.json,.csv,.xml',
parallelUploads: limit -1 ,
parallelUploads: 1,
maxFiles: limit,

uploadMultiple: false,
init : function() {
var submitButton = document.querySelector("#uploadButton");
var clearAllButton = document.querySelector("#clearAllButton");
Expand Down Expand Up @@ -260,19 +261,18 @@ <h4 class="panel-title">
}
});

//Even for when the file is successfully sent to server
this.on("success", function(file, response) {
this.on('success', function(file, response) {
if (response.success !== undefined && response.success == 0) {
vex.dialog.alert(response.message);
myDropzone.removeAllFiles();
}

if (this.getUploadingFiles().length === 0 && this.getQueuedFiles().length === 0) {
{# location.reload(true);#}

if (response.success !== undefined && response.success == 0) {
vex.dialog.alert(response.message);
myDropzone.removeAllFiles();
}
location.reload(true);
}
});


//When max file upload has been reached
this.on("maxfilesreached", function(file) {
vex.dialog.alert({
Expand All @@ -281,7 +281,7 @@ <h4 class="panel-title">
closeClassName: 'alert-vex-close'
});

});
})

}
};
Expand All @@ -293,22 +293,22 @@ <h4 class="panel-title">
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js" async></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/Base64/0.3.0/base64.min.js" async></script>

{# <script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/4.2.0/codemirror.min.js"></script>#}
{# <script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/4.2.0/addon/dialog/dialog.js" async></script>#}
{# <script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/4.2.0/mode/javascript/javascript.js" async></script>#}
{# <script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/4.2.0/mode/python/python.js" async></script>#}
{# <script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/4.2.0/mode/r/r.js" async></script>#}
{# <script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/4.2.0/addon/hint/show-hint.js" async></script>#}
{# <script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/4.2.0/addon/tern/tern.js" async></script>#}
{# <script src="http://marijnhaverbeke.nl/acorn/acorn.js" async></script>#}
{# <script src="http://marijnhaverbeke.nl/acorn/acorn_loose.js" async></script>#}
{# <script src="http://marijnhaverbeke.nl/acorn/util/walk.js" async></script>#}
{# <script src="http://ternjs.net/doc/demo/polyfill.js" async></script>#}
{# <script src="http://ternjs.net/lib/signal.js" async></script>#}
{# <script src="http://ternjs.net/lib/tern.js" async></script>#}
{# <script src="http://ternjs.net/lib/def.js" async></script>#}
{# <script src="http://ternjs.net/lib/comment.js" async></script>#}
{# <script src="http://ternjs.net/lib/infer.js" async></script>#}
{# <script src="http://ternjs.net/plugin/doc_comment.js" async></script>#}
{# <script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/4.2.0/codemirror.min.js"></script>#}
{# <script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/4.2.0/addon/dialog/dialog.js" async></script>#}
{# <script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/4.2.0/mode/javascript/javascript.js" async></script>#}
{# <script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/4.2.0/mode/python/python.js" async></script>#}
{# <script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/4.2.0/mode/r/r.js" async></script>#}
{# <script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/4.2.0/addon/hint/show-hint.js" async></script>#}
{# <script src="//cdnjs.cloudflare.com/ajax/libs/codemirror/4.2.0/addon/tern/tern.js" async></script>#}
{# <script src="http://marijnhaverbeke.nl/acorn/acorn.js" async></script>#}
{# <script src="http://marijnhaverbeke.nl/acorn/acorn_loose.js" async></script>#}
{# <script src="http://marijnhaverbeke.nl/acorn/util/walk.js" async></script>#}
{# <script src="http://ternjs.net/doc/demo/polyfill.js" async></script>#}
{# <script src="http://ternjs.net/lib/signal.js" async></script>#}
{# <script src="http://ternjs.net/lib/tern.js" async></script>#}
{# <script src="http://ternjs.net/lib/def.js" async></script>#}
{# <script src="http://ternjs.net/lib/comment.js" async></script>#}
{# <script src="http://ternjs.net/lib/infer.js" async></script>#}
{# <script src="http://ternjs.net/plugin/doc_comment.js" async></script>#}

{% endblock javascript %}
28 changes: 15 additions & 13 deletions visualization/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,30 +55,33 @@ def post(self, request):
form = self.form_class(request.POST, request.FILES)
if request.user.is_authenticated():
if form.is_valid():

#Get file
new_file = UploadFile(file=request.FILES['file'])

# Add to file for useruploadedfiles
userUploadedFiles = UserUploadedFiles.objects.get(user=request.user)
userUploadedFiles.uploadedFiles.append({
'filename': new_file.file.name,
'fileurl': re.sub(r'/media/', r'/media/files/', new_file.file.url),
'filesize': new_file.file.size
})


new_file.save()
userUploadedFiles.save()
files = userUploadedFiles.uploadedFiles

data = {
'form': form,
'files': userUploadedFiles.uploadedFiles
}

return render_to_response(self.template_name, data, context_instance=RequestContext(request))
# Save to DB
# new_file.save()
userUploadedFiles.save()
response_data = {
'success': 1,
'files': files
}
return HttpResponse(json.dumps(response_data), content_type='application/json')
else:
response_data = {'success': 0, 'message': 'Invalid Upload'}
return HttpResponse(json.dumps(response_data), content_type='application/json')
else:
print('Here2')
response_data = {'success': 0, 'message': 'Only authenticated user can upload files'}
return HttpResponse(json.dumps(response_data), content_type='application/json');
return HttpResponse(json.dumps(response_data), content_type='application/json')


def fileview(request):
Expand Down Expand Up @@ -304,7 +307,6 @@ def createSVGView(request, filename):
This view receives the svg information from the workspace and saves the file
"""
if request.is_ajax():
print('here')
filenameRegex = re.search(r'(?P<filename>[a-zA-Z]+[\d\.]*)\.(?P<extension>[a-zA-Z]{1,4}$)', filename)
cleanFileName = filenameRegex.group('filename')
cleanFileExtension = filenameRegex.group('extension')
Expand Down

0 comments on commit c5e01ea

Please sign in to comment.