From ce234bdea54957eef0523d7d872c2ddb5ed319a8 Mon Sep 17 00:00:00 2001 From: j Date: Mon, 5 Nov 2018 20:27:03 +0000 Subject: [PATCH] fix document import --- static/js/importDocumentsDialog.amp.js | 17 ++++++++++++----- static/js/localInit.amp.js | 4 ++-- tasks.py | 3 ++- views.py | 5 +++-- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/static/js/importDocumentsDialog.amp.js b/static/js/importDocumentsDialog.amp.js index fccd08c..7f13620 100644 --- a/static/js/importDocumentsDialog.amp.js +++ b/static/js/importDocumentsDialog.amp.js @@ -2,7 +2,7 @@ pandora.ui.importDocumentsDialog = function() { - var dialogHeight = 100, + var dialogHeight = 128 + 16, dialogWidth = 512 + 16, formWidth = getFormWidth(), @@ -10,8 +10,9 @@ pandora.ui.importDocumentsDialog = function() { $content = Ox.Element(), value, $input = [ - Ox.TextArea({ - labelWidth: 96, + Ox.Input({ + type: 'textarea', + height: 128, width: 512 }).css({ margin: '8px' @@ -35,7 +36,7 @@ pandora.ui.importDocumentsDialog = function() { } }), $button = Ox.Button({ - disabled: true, + disabled: false, id: 'import', title: Ox._('Import URLs') }) @@ -73,10 +74,16 @@ pandora.ui.importDocumentsDialog = function() { pandora.api.importDocuments({ urls: urls }, function(result) { + Ox.Request.clearCache() if (result.data.taskId) { pandora.wait(result.data.taskId, function(result) { that.close(); - } + if (pandora.user.ui.section == 'documents' && !pandora.user.ui.document.length) { + pandora.$ui.list.reloadList() + } else { + pandora.URL.push('/documents/grid/created') + } + }) } else { that.options({content: 'Failed'}); } diff --git a/static/js/localInit.amp.js b/static/js/localInit.amp.js index f75dfee..b552335 100644 --- a/static/js/localInit.amp.js +++ b/static/js/localInit.amp.js @@ -27,7 +27,7 @@ pandora.localInit = function() { $item = Ox.MenuButton({ items: [ ].concat(pandora.user.level == 'admin' ? [ - ] : [], [ + ] : [], pandora.user.level == 'gurest' ? [] : [ {id: 'import_documents', title: 'Import Documents...'}, ]), style: 'rounded', @@ -37,7 +37,7 @@ pandora.localInit = function() { }).css(css).bindEvent({ click: function(data) { if (data.id == 'import_documents') { - pandora.ui.importDocumentsDialog().open() + pandora.ui.importDocumentsDialog().open(); } }, }), diff --git a/tasks.py b/tasks.py index 1dd8a6f..a1984d7 100644 --- a/tasks.py +++ b/tasks.py @@ -8,5 +8,6 @@ base = os.path.dirname(__file__) @task(queue="encoding") def import_documents(urls): for url in urls: - if url.startswith('http'): + url = url.strip() + if url and url.startswith('http'): subprocess.call(['/srv/pandora/bin/python', os.path.join(base, 'add_website_as_pdf.py'), url]) diff --git a/views.py b/views.py index 68d0ef7..d142065 100644 --- a/views.py +++ b/views.py @@ -2,14 +2,15 @@ from __future__ import division, print_function, absolute_import from oxdjango.decorators import login_required_json -from oxdjango.shortcuts import render_to_json_response +from oxdjango.shortcuts import render_to_json_response, json_response from oxdjango.api import actions from .tasks import import_documents @login_required_json def importDocuments(request, data): - t = tasks.import_documents.delay(urls=data['urls']) + response = json_response({}) + t = import_documents.delay(urls=data['urls']) response['data']['taskId'] = t.task_id return render_to_json_response(response) actions.register(importDocuments)