Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
limbra
limbra
Commits
ed8affdc
Commit
ed8affdc
authored
Jul 03, 2017
by
LE GAC Renaud
Browse files
Migrate controller related to affiliations.
parent
6e9f0f9f
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
27 deletions
+39
-27
controllers/wizards.py
controllers/wizards.py
+38
-26
modules/invenio_tools/inveniostore.py
modules/invenio_tools/inveniostore.py
+1
-1
No files found.
controllers/wizards.py
View file @
ed8affdc
...
...
@@ -24,11 +24,14 @@ 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_AFFILIATION
=
"Affiliation is not defined for the selected author."
MSG_NO_AUTHOR
=
"Author not found!"
MSG_NO_KEYS
=
"Affiliation keys are not defined!"
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!"
MSG_TO_MANY_AFFILIATION
=
"More than one affiliation for the selected author!"
MSG_TO0_MANY_AFFILIATION
=
"More than one affiliation for the selected author!"
MSG_TO0_MANY_AUTHOR
=
"More than one author found!"
def
affiliation_institute
():
...
...
@@ -49,9 +52,21 @@ def affiliation_institute():
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
keys
=
(
record
[
"110"
][
k
]
for
k
in
(
"u"
,
"t"
,
"b"
)
if
k
in
record
[
"110"
])
# subfields are identifier and futur_identifier
# they are not part of the standard JSON record but add by the factory
if
u
"corporate_note"
not
in
record
:
raise
HTTP
(
500
,
T
(
MSG_NO_KEYS
))
di
=
record
[
u
"corporate_note"
]
keys
=
[
di
[
k
]
for
k
in
di
]
# some time the name of the institute is used (ATLAS NOte, ...)
obj
=
record
[
u
"corporate_name"
]
di
=
(
obj
[
0
]
if
isinstance
(
obj
,
list
)
else
obj
)
if
u
"name"
in
di
:
keys
.
append
(
di
[
u
"name"
])
keys
=
(
dict
(
key_u
=
key
,
key_v
=
""
)
for
key
in
keys
)
# check that the rules does not exist
...
...
@@ -89,36 +104,33 @@ def affiliation_publication():
if
record
is
None
:
raise
HTTP
(
500
,
T
(
MSG_NO_PUBLICATION
))
# find the author
# 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
)
# find the author and its affiliation
df
=
record
[
u
"authors"
]
key
=
None
if
"700"
in
record
and
isinstance
(
record
[
"700"
],
list
):
for
di
in
record
[
"700"
]:
author
=
di
[
"a"
]
query
=
\
(
df
.
last_name
.
str
.
lower
()
==
family_name
.
lower
())
&
\
(
df
.
first_name
.
str
.
lower
()
==
first_name
.
lower
())
if
reg
.
match
(
author
):
df
=
df
[
query
]
if
isinstance
(
di
[
"u"
],
list
)
:
raise
HTTP
(
500
,
T
(
MSG_
TO_MANY_AFFILIATION
))
if
len
(
df
)
==
0
:
raise
HTTP
(
500
,
T
(
MSG_
NO_AUTHOR
))
if
"v"
in
di
:
key
=
dict
(
key_u
=
di
[
"u"
],
key_v
=
di
[
"v"
])
else
:
key
=
dict
(
key_u
=
di
[
"u"
],
key_v
=
""
)
break
elif
len
(
df
)
>
1
:
raise
HTTP
(
500
,
T
(
MSG_TO0_MANY_AUTHOR
))
if
key
is
None
:
raise
HTTP
(
500
,
T
(
MSG_NO_AUTHOR
))
affiliation
=
df
.
affiliation
.
iloc
[
0
]
# reject author with several affiliations
if
"|"
in
affiliation
:
raise
HTTP
(
500
,
MSG_TO0_MANY_AFFILIATION
)
elif
len
(
affiliation
)
==
0
:
raise
HTTP
(
500
,
T
(
MSG_NO_AFFILIATION
))
# check that the rules does not exist
# load new rules
key
=
dict
(
key_u
=
affiliation
,
key_v
=
""
)
if
get_id
(
db
.
affiliation_keys
,
**
key
)
is
None
:
db
.
affiliation_keys
[
0
]
=
key
...
...
modules/invenio_tools/inveniostore.py
View file @
ed8affdc
...
...
@@ -64,7 +64,7 @@ class InvenioStore(object):
URL string, *e.g.*::
* ``http://cds.cern.ch/record/123456/of=recjson``
* ``http://cds.cern.ch/search?o
d
=id&....
* ``http://cds.cern.ch/search?o
f
=id&....
Keyword Args:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment