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

Commit

Permalink
Update changes
Browse files Browse the repository at this point in the history
  • Loading branch information
aguilerapy committed Aug 8, 2020
1 parent 70291be commit 778486d
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 30 deletions.
2 changes: 1 addition & 1 deletion default/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def wrap(request, *args, **kwargs):
prefix, ext = os.path.splitext(f.filename)
new_file = DataFile(prefix, ext)
path, f.filename = os.path.split(new_file.path)
zipfile.extract(f, 'media/' + new_file.folder)
zipfile.extract(f, path)
# Open the file to check if it is the correct type
with open(new_file.path, 'rb') as h:
file_type = request.GET.get('type', None)
Expand Down
36 changes: 24 additions & 12 deletions default/static/js/uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,12 @@ var app = {};

/* check if results were sent and performAction directly, otherwise files are uploaded first */
if ($('#upload-button').hasClass('sendResult') == true) {
params = '?sendResult=true&type=' + JSON.parse($('#fileupload').attr('data-form-data')).type
performAction($('#fileupload').attr('data-perform-action') + params);
app.setParams(function(params){
params['sendResult'] = 'true';
params['type'] = JSON.parse($('#fileupload').attr('data-form-data')).type;
return params;
});
performAction($('#fileupload').attr('data-perform-action'));
} else {
var promises = $.map(_fileItems, function (val) {
return val.submit();
Expand Down Expand Up @@ -255,16 +259,24 @@ var app = {};
/* check if results were sent to this page */
if (window.location.search == '?sendResult=true') {
showProcessingModal();
disableAddFiles();
enableUploadButton();
$('.drop-area').removeClass('empty');
$('.drop-area').addClass('single');
$('.drop-area .file-selector-empty').addClass('hidden');
$('.drop-area .drop-area-received-msg').removeClass('hidden');
$('.drop-area .drop-area-received-msg .file-result').html('result.zip');
$('.actions').removeClass('hidden');
$('#upload-button').addClass('sendResult');
hideProcessingModal();
$.ajax('/send-result/validate/', {'dataType': 'json', type: 'GET'})
.done(function (data) {
disableAddFiles();
enableUploadButton();
$('.drop-area').removeClass('empty');
$('.drop-area').addClass('single');
$('.drop-area .file-selector-empty').addClass('hidden');
$('.drop-area .drop-area-received-msg').removeClass('hidden');
$('.drop-area .drop-area-received-msg .file-result').html(data);
$('.actions').removeClass('hidden');
$('#upload-button').addClass('sendResult');
})
.fail(function () {
$('.response-fail').removeClass('hidden');
})
.always(function () {
hideProcessingModal();
});
}

/* add warning before closing/navigating away from page */
Expand Down
33 changes: 21 additions & 12 deletions default/templates/default/to-spreadsheet.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@
/** click upload-button behaviour if results where sent **/
$('#upload-button').click(function(){
if ($('#upload-button').hasClass('sendResult') == true) {
params = '?sendResult=true&type=' + JSON.parse($('#fileupload').attr('data-form-data')).type
performAction('/to-spreadsheet/go/' + params);
params = {sendResult: 'true', type: JSON.parse($('#fileupload').attr('data-form-data')).type}
performAction('/to-spreadsheet/go/', params);
}
});

Expand Down Expand Up @@ -212,9 +212,9 @@
});
});

function performAction(url) {
function performAction(url, params) {
$('#processing-modal').modal('show');
$.ajax(url, { 'dataType': 'json' })
$.ajax(url, { 'data': params, 'dataType': 'json' })
.done(function(data){
$('.response-success .download-xlsx').attr('href', data.xlsx.url);
$('.response-success .download-csv').attr('href', data.csv.url);
Expand Down Expand Up @@ -249,14 +249,23 @@
/* check if results were sent to this page */
if (window.location.search == '?sendResult=true') {
$('#processing-modal').modal('show');
$('.drop-area').removeClass('empty');
$('.drop-area .file-selector-empty').addClass('hidden');
$('.drop-area .drop-area-received-msg').removeClass('hidden');
$('.drop-area .drop-area-received-msg .file-result').html('result.zip');
$('.actions').removeClass('hidden');
$('#upload-button').removeClass('hidden');
$('#upload-button').addClass('sendResult');
$('#processing-modal').modal('hide');
$.ajax('/send-result/validate/', {'dataType': 'json', type: 'GET'})
.done(function (data) {
$('.drop-area').removeClass('empty');
$('.drop-area .file-selector-empty').addClass('hidden');
$('.drop-area .drop-area-received-msg').removeClass('hidden');
$('.drop-area .drop-area-received-msg .file-result').html(data);
$('.actions').removeClass('hidden');
$('#upload-button').removeClass('hidden');
$('#upload-button').addClass('sendResult');
$('#processing-modal').modal('hide');
})
.fail(function () {
$('.response-fail').removeClass('hidden');
})
.always(function () {
$('#processing-modal').modal('hide');
});
}
}
</script>
Expand Down
1 change: 1 addition & 0 deletions default/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
path('upload/', views.uploadfile, name='upload'),
path('upload-url/', views.upload_url, name='upload_url'),
path('upload-url/status/', views.upload_url_status, name='upload_url_status'),
path('send-result/validate/', views.validate_send_result, name='validate_send_result'),
path('delete/<uuid:id>', views.deletefile, name='delete_file'),
path('result/<str:folder>/<uuid:id>/', views.retrieve_result, name='retrieve_result'),
path('result/<str:folder>/<uuid:id>/<str:format>/', views.retrieve_result, name='retrieve_result'),
Expand Down
8 changes: 8 additions & 0 deletions default/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,14 @@ def upload_url_status(request):
return JsonResponse(len(request.session['files']), safe=False)


@require_GET
def validate_send_result(request):
if 'results' in request.session and request.session['results']:
file = request.session['results'][0] # always one result is saved
return JsonResponse(file['prefix'] + file['ext'], safe=False)
return HttpResponse(status=400)


@require_POST
def uploadfile(request):
request_file = request.FILES['file']
Expand Down
6 changes: 3 additions & 3 deletions locale/es/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2020-08-04 14:50-0400\n"
"POT-Creation-Date: 2020-08-07 21:36-0400\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand Down Expand Up @@ -682,11 +682,11 @@ msgstr ""
"Se produjo un error al intentar acceder a esta URL. Favor verifique que la "
"URL sea correcta y el archivo tenga el formato esperado."

#: default/views.py:347 default/views.py:355
#: default/views.py:355 default/views.py:363
msgid "File not found"
msgstr "Archivo no encontrado"

#: default/views.py:353
#: default/views.py:361
msgid "File deleted"
msgstr "Archivo eliminado"

Expand Down
11 changes: 9 additions & 2 deletions tests/test_send_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,25 @@ def test_send_result(self):
self.url = '/upgrade/'
content = self.upload_and_go({'type': 'release-package'})

response = self.client.get(content['url'] + '?sendResult=true')
response = self.client.get(content['url'], data={'sendResult': 'true'})
self.assertEqual(response.status_code, 200)

response = self.client.get('/send-result/validate/')
self.assertEqual(response.status_code, 200)

response = self.client.get(self.send_to_url)
self.assertEqual(response.status_code, 200)
self.assertEqual(response['Content-Type'], 'application/json')

def test_send_result_error(self):
response = self.client.get('/send-result/validate/')
self.assertEqual(response.status_code, 400)

def test_send_result_invalid_type(self):
self.url = '/compile/'
content = self.upload_and_go({'type': 'release-package'})

response = self.client.get(content['url'] + '?sendResult=true')
response = self.client.get(content['url'], data={'sendResult': 'true'})
self.assertEqual(response.status_code, 200)

response = self.client.get(self.send_to_url)
Expand Down

0 comments on commit 778486d

Please sign in to comment.