# -*- coding: utf-8 -*- """ invenio_tools.recordthesis """ from base import THESIS_DIR from filters import CLEAN_THESIS_DEFENSE from recordpubli import RecordPubli class RecordThesis(RecordPubli): """MARC record describing a thesis. The relation between methods and MARC fields are the following:: | CDS | INSPIREP ----------------------+---------+---------- these defense | 500 a | these level | 502 a | these director | 700 a | these universities | 502 b | ----------------------+---------+---------- """ def authors_as_list(self): """The list of author(s) signing the publication. @rtype: list @return: - The list is empty when authors are not defined. """ authors = [] first_author = self.first_author() # NOTE # the content of the 700 field depend on the record type. # 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): """The defense date for a master/phd thesis. @rtype: unicode @return: - The format is '5 March 2012'. - The format is not standardize and can varies between records and between stores. - The value is not a standardize C{date}. - The filter L{CLEAN_THESIS_DEFENSE} is applied. """ val = self._get(u"500", "a") return CLEAN_THESIS_DEFENSE(val) def these_level(self): """The level of the thesis. @rtype: unicode @return: - The format is "master" or "PhD". - The format is not standardize and can varies between records and between stores. - Empty string when not defined """ return self._get(u"502", "a") def these_directors(self): """The list of director(s) @rtype: unicode @return: - Names are separated by ", ". - Empty string when not defined. """ # NOTE director are stored in the author field # the first author is not a director ! li = [] if u"700" in self and isinstance(self[u"700"], dict): if "e" in self[u"700"] and self[u"700"]["e"] == THESIS_DIR: 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): """The town where the thesis took place. @rtype: unicode @return: - Empty string when not defined. """ return self._get(u"260", "a") def these_universities(self): """The university(ies) delivering the thesis diploma. @rtype: list @return: - Empty list when not defined """ return self._get(u"502", "b", force_list=True)