From 8a44a6e04be5ce0ffb2ad01a9d8ae2ee41a27c05 Mon Sep 17 00:00:00 2001 From: Emanuel Dima Date: Wed, 2 Apr 2014 19:16:25 +0200 Subject: [PATCH] fixed #109: faster ingest, proper message while waiting --- invenio/lib/record_blueprint.py | 6 ++-- simplestore/lib/b2share_utils.py | 29 +++++++++++++++++++ .../lib/simplestore_deposit_handler.py | 3 +- 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/invenio/lib/record_blueprint.py b/invenio/lib/record_blueprint.py index 78faf9b29d..a96fa9d19e 100644 --- a/invenio/lib/record_blueprint.py +++ b/invenio/lib/record_blueprint.py @@ -46,6 +46,7 @@ get_detailed_page_tabs_counts from invenio.search_engine_utils import get_fieldvalues from invenio.bibrank_downloads_similarity import register_page_view_event +from invenio.b2share_utils import check_fresh_record blueprint = InvenioBlueprint('record', __name__, url_prefix="/" + CFG_SITE_RECORD, config='invenio.search_engine_config', @@ -76,8 +77,9 @@ def decorated(recid, *args, **kwargs): flash(_("Authorization failure"), 'error') return redirect(url_for('webaccount.login', **url_args)) elif auth_code: - flash(auth_msg, 'error') - abort(apache.HTTP_UNAUTHORIZED) + if not check_fresh_record(current_user, recid): + flash(auth_msg, 'error') + abort(apache.HTTP_UNAUTHORIZED) from invenio.bibfield import get_record from invenio.search_engine import record_exists, get_merged_recid diff --git a/simplestore/lib/b2share_utils.py b/simplestore/lib/b2share_utils.py index 25f7edc8da..c81b3efced 100644 --- a/simplestore/lib/b2share_utils.py +++ b/simplestore/lib/b2share_utils.py @@ -19,6 +19,7 @@ """Utility functions for b2share""" from invenio.search_engine import perform_request_search +from invenio.search_engine_utils import get_fieldvalues from invenio.bibformat_engine import BibFormatObject from invenio.bibformat_elements import bfe_authors, bfe_title, bfe_abstract, bfe_creation_date @@ -53,3 +54,31 @@ def get_latest_deposits(): "category": bfo.field("980__a"), } for bfo in bfo_list] return recs + + +def check_fresh_record(user_info, recid): + """ + Check if the record is just submitted (has a record id) but not yet fully in the database. + The check_user_can_view_record function is doing the same thing, but returns the + same error code for both cases where the user doesn't have the right to view + the record and the case when the record is not yet fully submitted. + + @param user_info: the user_info dictionary that describe the user. + @type user_info: user_info dictionary + @param recid: the record identifier. + @type recid: positive integer + @return: True if the record is fresh, False otherwise + @rtype: bool + """ + + if isinstance(recid, str): + recid = int(recid) + + if get_fieldvalues(recid, '8560_f'): + # The email field is set + return False + if get_fieldvalues(recid, '245__a'): + # It has a title + return False + + return True diff --git a/simplestore/lib/simplestore_deposit_handler.py b/simplestore/lib/simplestore_deposit_handler.py index 686c9049dc..60753f5993 100644 --- a/simplestore/lib/simplestore_deposit_handler.py +++ b/simplestore/lib/simplestore_deposit_handler.py @@ -109,7 +109,8 @@ def addmeta(request, sub_id): recid, marc = mh.create_marc( request.form, sub_id, current_user['email']) tmp_file = write_marc_to_temp_file(marc) - task_low_level_submission('bibupload', 'webdeposit', '-r', tmp_file) + # all usual tasks have priority 0; we want the bibuploads to run first + task_low_level_submission('bibupload', 'webdeposit', '--priority', '1', '-r', tmp_file) return jsonify(valid=True, html=render_template('simplestore-finalize.html', recid=recid, marc=marc))