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

Propagate improved Record.authors method in CheckAndFix.

parent 088f072c
......@@ -211,51 +211,12 @@ class CheckAndFix(object):
"""
if u"100" not in record and u"700" not in record:
if not record.is_authors():
raise CheckException(MSG_NO_AUTHOR)
if u"100" in record and isinstance(record[u"100"], list):
# from time to time first authors is duplicated
li = []
for di in record[u"100"]:
if di not in li:
li.append(di)
if len(li) == 1:
record[u"100"] = li[0]
else:
if isinstance(record.first_author(), list):
raise CheckException(MSG_TO_MANY_FAUTHOR)
# alias
authors, first_author = None, None
if u"700" in record:
authors = record[u"700"]
if u"100" in record:
first_author = record[u"100"]
# first author not defined
if not first_author and authors:
if isinstance(record[u"700"], list):
record[u"100"] = record[u"700"][0]
else:
record[u"100"] = record[u"700"]
# first author not in the authors list
elif first_author and authors:
if isinstance(record[u"700"], list):
if record[u"100"]["a"] != record[u"700"][0]["a"]:
record[u"700"].insert(0, record[u"100"])
elif record[u"700"]["a"] != record[u"100"]["a"]:
record[u"700"] = [record[u"100"], record[u"700"]]
# only the first author is defined
elif first_author and not authors:
record[u"700"] = record[u"100"]
def clean_erratum(self, record):
"""Clean record with erratum by removing them.
......
......@@ -203,9 +203,10 @@ class RecordPubli(Record):
def first_author(self):
"""The name of the first author.
@rtype: unicode
@rtype: unicode or list
@return:
- Empty string when the first author is not defined.
- List of name when there is more than one.
"""
# standard case
......@@ -215,7 +216,11 @@ class RecordPubli(Record):
# PROTECTION
# It happens that the first author is duplicate, remove it
if isinstance(value, list):
value = ", ".join(set(value))
s = set(value)
if len(s) == 1:
return s[0]
else:
return list(s)
return value
......
......@@ -51,34 +51,19 @@ def recordfix(record):
svc.authors(rec)
svc.format_authors(rec, format_author_fr)
svc.format_editor(rec)
svc.my_authors(rec)
svc.my_authors(rec, cmpFct=family_name_fr)
svc.submitted(rec)
svc.year(rec)
return rec
def test_authors(record, recordfix):
authors = record.authors_as_list()
assert len(authors) == 703
assert authors[0] == "Adeva, Bernardo"
assert authors[-1] == "Zvyagin, Alexander"
authors = recordfix.authors_as_list()
assert len(authors) == 704
assert authors[0] == "R. Aaij"
assert authors[55] == "M.-O. Bettler"
assert authors[344] == "R. Le Gac"
assert authors[-1] == "A. Zvyagin"
def test_find_authors_by_institute(recordfix):
rex = current.app.reg_institute
assert rex == "Marseille, CPPM|CPPM, Marseille"
authors = recordfix.find_authors_by_institute(rex, family_name_fr)
authors = authors.split(", ")
assert authors == CPPM_AUTHORS
assert authors.split(', ') == CPPM_AUTHORS
def test_first_author(record, recordfix):
......
......@@ -47,7 +47,7 @@ def recordfix(record):
def test_authors(record, recordfix):
assert record.authors() == ""
assert record.authors() == "Leroy, Olivier"
assert recordfix.authors() == "O. Leroy"
......@@ -67,8 +67,8 @@ def test_first_institutes(record, recordfix):
def test_institutes(record, recordfix):
assert record.institutes() == []
assert record.is_affiliation_for_all() == False
assert record.institutes() == ['Marseille, CPPM']
assert record.is_affiliation_for_all() == True
assert recordfix.institutes() == ["Marseille, CPPM"]
assert recordfix.is_affiliation_for_all() == True
......
......@@ -49,7 +49,7 @@ def recordfix(record):
def test_authors(record, recordfix):
assert record.authors() == ""
assert record.authors() == "Hubaut, F."
assert recordfix.authors() == "F. Hubaut"
......
......@@ -41,7 +41,7 @@ def recordfix(record):
def test_authors(record, recordfix):
assert record.authors() == ""
assert record.authors() == "Le Gac, R"
assert recordfix.authors() == "R. Le Gac"
......
......@@ -43,7 +43,7 @@ def recordfix(record):
def test_authors(record, recordfix):
assert record.authors() == ""
assert record.authors() == "Chen, Liming"
assert recordfix.authors() == "L. Chen"
......
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