Commit 2347513d authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Improve the affiliation processing behind the wizards.

parent c9e603ad
......@@ -8,7 +8,7 @@ import re
from check_tools import check_publication
from gluon.storage import Storage
from harvest_tools import DRY_RUN
from invenio_tools import load_record
from invenio_tools import CdsException, load_record, Marc12Exception
from plugin_dbui import (CALLBACK_ERRORS,
inline_alert,
is_foreign_field,
......@@ -22,6 +22,12 @@ MODE_DRY_RUN = T(DRY_RUN)
MSG_NO_AUTHORS = "<br><br>Removing affiliation failed.<br>"\
"Use INSPIRES instead with the tool 'insert MARCXML'"
MSG_EXISTING_KEY = "Keys already exist!"
MSG_NO_AUTHOR = "Author not found!"
MSG_NO_INSTITUTE = "Institute not found in the inspirehep database!"
MSG_NO_PUBLICATION = "Publication not found!"
MSG_NO_SERVER = "Server is not reachable or respond badly!"
def affiliation_institute():
"""Determine affiliation keys using the institute database.
......@@ -31,19 +37,32 @@ def affiliation_institute():
institute_id = request.vars.institute_id
# find the record for the institute
try:
record = load_record("inspirehep.net", institute_id)
except (CdsException, Marc12Exception):
raise HTTP(500, T(MSG_NO_SERVER))
if record is None:
raise HTTP(500, "Record not found!")
raise HTTP(500, T(MSG_NO_INSTITUTE))
# extract keys defining the affiliation
# u and v are the main keys use in inspirehep and cds
# b is uses by some note in Atlas
key_1 = dict(key_u=record[u"110"]["u"], key_v="")
key_2 = dict(key_u=record[u"110"]["t"], key_v="")
key_3 = dict(key_u=record[u"110"]["b"], key_v="")
# check that the rules does not exist
# load new rules
for key in (key_1, key_2):
is_key_add = False
for key in (key_1, key_2, key_3):
if get_id(db.affiliation_keys, **key) is None:
db.affiliation_keys[0] = key
is_key_add = True
if not is_key_add:
raise HTTP(500, T(MSG_EXISTING_KEY))
return
......@@ -54,21 +73,31 @@ def affiliation_publication():
"""
# shortcuts
vars = request.vars
family_name = vars.family_name
first_name = vars.first_name
family_name = vars.family_name.strip()
first_name = vars.first_name.strip()
publication_id = vars.publication_id
publication_store = vars.publication_store
# find the publication
try:
record = load_record(publication_store, publication_id)
except (CdsException, Marc12Exception):
raise HTTP(500, T(MSG_NO_SERVER))
if record is None:
raise HTTP(500, "Record not found!")
raise HTTP(500, T(MSG_NO_PUBLICATION))
# find the author
pattern = "^%s, %s$" % (family_name.strip(), first_name.strip())
# test all possible patterns (John, Doe; Doe, John; J. Doe; Doe, J. etc)
# for simplicity ignore composed name, e.g. Jean-Pierre
pattern = "^%s, *%s$" % (family_name, first_name)
pattern = "%s|^%s, *%s$" % (pattern, first_name, family_name)
pattern = "%s|^%s, *%s\.?$" % (pattern, family_name, first_name[0])
pattern = "%s|^%s\.?, *%s$" % (pattern, first_name[0], family_name)
reg = re.compile(pattern, re.IGNORECASE)
key = None
key = None
if "700" in record and isinstance(record[u"700"], list):
for di in record[u"700"]:
author = di["a"]
......@@ -80,7 +109,7 @@ def affiliation_publication():
break
if key is None:
raise HTTP(500, "Author not found!")
raise HTTP(500, T(MSG_NO_AUTHOR))
# check that the rules does not exist
# load new rules
......@@ -88,7 +117,7 @@ def affiliation_publication():
db.affiliation_keys[0] = key
else:
raise HTTP(500, "Keys already exists!")
raise HTTP(500, T(MSG_EXISTING_KEY))
return
......
......@@ -45,6 +45,7 @@
'Articles published': 'Articles publiés',
'ASCL': 'ASCL',
'Associate a title to each section. Rule: section1: title1, secton2: title2,....': 'Associate a title to each section. Rule: section1: title1, secton2: title2,....',
'Author not found!': "L'auteur n'a pas été trouvé !",
'auth_cas': 'auth_cas',
'auth_event': 'auth_event',
'auth_group': 'auth_group',
......@@ -307,6 +308,7 @@
'install': 'installé',
'Institute': 'Institut',
'Institute identifier in inspirehep.net.': 'Identifiant du laboratoire dans inspirehep.net.',
'Institute not found in the inspirehep database!': "Le laboratoire n'a pas été trouvé !",
'Institute number associated to CPPM authors': "Numéro de l'Institut associé aux auteurs du CPPM",
'Invalid': 'Non conforme',
"Invalid database table '%s'": "Invalid database table '%s'",
......@@ -323,6 +325,7 @@
'ISBN': 'ISBN',
'ISSN': 'ISSN',
'Javascript API': 'Javascript API',
'Keys already exist!': 'La clé existe!',
'Key U': 'Clé U',
'Key V': 'Clé V',
'Last name': 'Last name',
......@@ -471,6 +474,7 @@
'Publication category associated to the found records.': 'Catégorie associée aux enregistrements.',
'publications': 'publications',
'Publications': 'Publications',
'Publication not found!': "La publication n'a pas été trouvé !",
'Publisher': 'Revue',
'publisher': 'revue',
'Publishers': 'Revues',
......@@ -589,6 +593,7 @@
'Serie': 'Serie',
'Serie Axis': 'Serie Axis',
'Serie Granularity': 'Serie Granularity',
'Server is not reachable or respond badly!': "Le serveur est injoignable ou répond mal !",
'Service': 'Service',
'Several publications refer to it.': 'Several publications refer to it.',
'Sign Up': 'Sign Up',
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment