Docker-in-Docker (DinD) capabilities of public runners deactivated. More info

Commit b070f03d authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Add the method RecordPubli.find_affiliation.

parent a128635b
......@@ -118,6 +118,42 @@ class RecordPubli(Record):
li = self._get(u"710", 'g', force_list=True)
return CLEAN_COLLABORATION(', '.join(li))
def find_affiliation(self, pattern):
"""Find author affiliation matching the regular expression C{pattern}.
@type pattern: unicode
@param pattern: regular expression defining the affiliation names.
@rtype: unicode
@return:
- the affiliation
- empty string when nothing is found.
"""
reg_affiliation = re.compile(pattern)
for field in (u"100", u"700"):
if field not in self:
continue
dictionaries = self[field]
if isinstance(dictionaries, dict):
dictionaries = [dictionaries]
for di in dictionaries:
if "u" not in di:
continue
li = di["u"]
if isinstance(li, unicode):
li = [li]
for affiliation in li:
if reg_affiliation.search(affiliation):
return affiliation
return u""
def find_authors(self, pattern):
"""Find authors matching the regular expression C{pattern}.
......
......@@ -59,6 +59,11 @@ def test_collaboration(record):
assert record.collaboration() == "LHCb Collaboration"
def test_find_affiliation(record):
affiliation = record.find_affiliation(r"Marseille, CPPM|CPPM, Marseille")
assert affiliation == "Marseille, CPPM"
def test_first_author(record):
assert record.first_author() == "Aaij, Roel"
......
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