Skip to content

Commit

Permalink
Merge pull request #223 from B2SHARE/deposit/fast-ingest-#109
Browse files Browse the repository at this point in the history
fixed #109: faster ingest, proper message while waiting
  • Loading branch information
llehtine committed Apr 3, 2014
2 parents 1bc7e89 + 8a44a6e commit 4c1e38c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
6 changes: 4 additions & 2 deletions invenio/lib/record_blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions simplestore/lib/b2share_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
3 changes: 2 additions & 1 deletion simplestore/lib/simplestore_deposit_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 4c1e38c

Please sign in to comment.