Commit 921aa615 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update RecordThesis in order to use author iterators.

parent de6390e7
...@@ -4,9 +4,15 @@ ...@@ -4,9 +4,15 @@
""" """
from base import REG_AUTHOR, THESIS_DIR from base import REG_AUTHOR, THESIS_DIR
from filters import CLEAN_THESIS_DEFENSE from filters import CLEAN_THESIS_DEFENSE
from iterauthors import author_name, iter_author_fields
from itertools import ifilter, ifilterfalse, imap
from recordpubli import RecordPubli from recordpubli import RecordPubli
# the argument x is a dict corresponding to the field 100 or 700 for one author
is_thesis_dir = lambda x: "e" in x and x["e"] == THESIS_DIR
class RecordThesis(RecordPubli): class RecordThesis(RecordPubli):
"""The MARC record describing a thesis. """The MARC record describing a thesis.
The relation between methods and MARC fields are the following:: The relation between methods and MARC fields are the following::
...@@ -28,50 +34,11 @@ class RecordThesis(RecordPubli): ...@@ -28,50 +34,11 @@ class RecordThesis(RecordPubli):
list: the list is empty when authors are not defined. list: the list is empty when authors are not defined.
""" """
authors = [] # for a thesis, the author field 700 can contains names of director.
first_author = self.first_author() # they have to be removed.
# NOTE iter_filter = ifilterfalse(is_thesis_dir, iter_author_fields(self))
# the content of the 700 field depend on the record type. return list(imap(author_name, iter_filter))
# For thesis it also contains the name of the director
if u"700" in self and isinstance(self[u"700"], dict):
if not ("e" in self[u"700"] and self[u"700"]["e"] == THESIS_DIR):
if "a" in self[u"700"]:
authors.append(self[u"700"]["a"])
elif u"700" in self and isinstance(self[u"700"], list):
for di in self[u"700"]:
if "e" in di and di["e"] == THESIS_DIR:
continue
if "a" in di:
author = di["a"]
# PROTECTION
# in most of the case the author is a string
# but it can be a list, e.g inspirehep.net/138663:
# [u'Zuniga, J.', u'(the A.N.T.ARES. Collaboration)']
if isinstance(author, unicode):
authors.append(di["a"])
elif isinstance(author, list):
for elt in author:
if REG_AUTHOR.match(elt):
authors.append(elt)
break
# the first author is defined not the other one
elif u"100" in self:
authors.append(first_author)
# sometime the first author is missing
if len(authors) == 0:
authors = [first_author]
elif first_author != authors[0]:
authors.insert(0, first_author)
return authors
def these_defense(self): def these_defense(self):
"""The defence date for a master/phd thesis. """The defence date for a master/phd thesis.
...@@ -109,21 +76,11 @@ class RecordThesis(RecordPubli): ...@@ -109,21 +76,11 @@ class RecordThesis(RecordPubli):
* Empty string when it is not defined. * Empty string when it is not defined.
""" """
# NOTE director are stored in the author field # for a thesis, the author field 700 field can contains
# the first author is not a director ! # names of the director.
li = []
if u"700" in self and isinstance(self[u"700"], dict): iter_filter = ifilter(is_thesis_dir, iter_author_fields(self))
if "e" in self[u"700"] and self[u"700"]["e"] == THESIS_DIR: return u", ".join(list(imap(author_name, iter_filter)))
if "a" in self[u"700"]:
li.append(self[u"700"]["a"])
elif u"700" in self and isinstance(self[u"700"], list):
for di in self[u"700"]:
if "e" in di and di["e"] == THESIS_DIR:
if "a" in di:
li.append(di["a"])
return ', '.join(li)
def these_town(self): def these_town(self):
"""The town where the thesis took place. """The town where the thesis took place.
......
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