From c5e01ea74735143e69965099b001cf41d8b1699c Mon Sep 17 00:00:00 2001 From: josecolella Date: Mon, 30 Jun 2014 22:52:41 +0200 Subject: [PATCH] Fix multiple upload problem --- .../static/visualization/js/authenticate.js | 9 +-- .../templates/visualization/index.html | 70 +++++++++---------- visualization/views.py | 28 ++++---- 3 files changed, 55 insertions(+), 52 deletions(-) diff --git a/visualization/static/visualization/js/authenticate.js b/visualization/static/visualization/js/authenticate.js index 071e1fb..2e67d04 100644 --- a/visualization/static/visualization/js/authenticate.js +++ b/visualization/static/visualization/js/authenticate.js @@ -124,7 +124,7 @@ $(function () { } clearForm(); }, - error: function(data) { + error: function() { vex.dialog.alert("User could not be saved"); } }) @@ -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() { diff --git a/visualization/templates/visualization/index.html b/visualization/templates/visualization/index.html index ce2ab37..ed5c3a6 100644 --- a/visualization/templates/visualization/index.html +++ b/visualization/templates/visualization/index.html @@ -4,8 +4,8 @@ {% load staticfiles %} -{# #} -{# #} + {# #} + {# #} @@ -16,14 +16,14 @@ -{# #} + {# #} {% endblock stylesheets %} {% block headjs %} -{# #} -{# #} + {# #} + {# #} @@ -178,10 +178,11 @@

{% block javascript %} {% load staticfiles %} -{# #} + {# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} -{# #} + {# #} + {# #} + {# #} + {# #} + {# #} + {# #} + {# #} + {# #} + {# #} + {# #} + {# #} + {# #} + {# #} + {# #} + {# #} + {# #} + {# #} {% endblock javascript %} diff --git a/visualization/views.py b/visualization/views.py index 5c4b79e..9a6286b 100644 --- a/visualization/views.py +++ b/visualization/views.py @@ -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): @@ -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[a-zA-Z]+[\d\.]*)\.(?P[a-zA-Z]{1,4}$)', filename) cleanFileName = filenameRegex.group('filename') cleanFileExtension = filenameRegex.group('extension')