def test_copes_with_null_publication_date(self): b = BibliographicRecord() self.assertEqual(b.get_publication_date(), "")
def _create_biblio_object(biblio_element, publication_object): """ Takes an XML biblio-record element lifted from a Symplectic Publication file (which contains the FULL info about each biblio-record unlike a User XML file) extracts full info about that biblio-record, loads/creates biblio-object, populates it with this new info and saves it """ # ++++++BIBLIOGRAPHIC-RECORD++++++ # check Bibliographical-record Element # print " creating", biblio_element if biblio_element is None: # print " giving up in _create_biblio_object" return # make blank Biblio Object biblio_object = BibliographicRecord() # Bibliographic-record sub-elements (used to read XML) if biblio_element is not None: bibliometric_data_element = biblio_element.find( SYMPLECTIC_NAMESPACE + 'bibliometric-data' ) bibliographic_data_element = biblio_element.find( SYMPLECTIC_NAMESPACE + 'bibliographic-data' ) if bibliographic_data_element is not None: native_element = bibliographic_data_element.find( SYMPLECTIC_NAMESPACE + 'native' ) if native_element is not None: authors_subtree = native_element.find(SYMPLECTIC_NAMESPACE + 'authors') keywords_subtree = native_element.find( SYMPLECTIC_NAMESPACE + 'keywords' ) # bibliographic-record attribs if biblio_element is not None: biblio_object.data_source = biblio_element.get('data-source', '') biblio_object.id_at_source = biblio_element.get('id-at-source', '') biblio_object.verification_status = _get_element_text( biblio_element.find(SYMPLECTIC_NAMESPACE + 'verification-status') ) # bibliometric data if bibliometric_data_element is not None: biblio_object.times_cited = _get_element_text( bibliometric_data_element.find( SYMPLECTIC_NAMESPACE + 'times-cited' ) ) biblio_object.reference_count = _get_element_text( bibliometric_data_element.find( SYMPLECTIC_NAMESPACE + 'reference-count' ) ) # native if native_element is not None: attr_names = [ 'abstract', 'associated-authors', 'awarded-date', 'begin-page', 'book-author-type', 'commissioning-body', 'confidential', 'doi', 'edition', 'editors', 'end-page', 'filed-date', 'finish-date', 'isbn-10', 'isbn-13', 'issn', 'issue', 'journal', 'journal-article-type', 'language', 'location', 'medium', 'name-of-conference', 'notes', 'number', 'number-of-pages', 'number-of-pieces', 'parent-title', 'patent-number', 'pii', 'place-of-publication', 'publication-date', 'publication-status', 'publication-status', 'series', 'start-date', 'title', 'version', 'volume' ] for attr_name in attr_names: element = native_element.find(SYMPLECTIC_NAMESPACE + attr_name) attr_value = _get_element_text(element) setattr(biblio_object, attr_name.replace("-", "_"), attr_value) # authors if authors_subtree is not None: biblio_object.authors = '' author_list = [] for author_element in authors_subtree.getchildren(): name = _get_element_text( author_element.find(SYMPLECTIC_NAMESPACE + 'name') ) initials = _get_element_text( author_element.find(SYMPLECTIC_NAMESPACE + 'initials') ) author_list.append(unicode(name) + ' ' + unicode(initials)) biblio_object.authors = ", ".join(author_list) print biblio_object.authors #derived authors biblio_object.number_of_authors = len(author_list) if len(author_list) > 0: biblio_object.first_author = author_list[0] if len(author_list) > 1: biblio_object.last_author = author_list[-1] # keywords if keywords_subtree is not None: biblio_object.keywords = '' for keyword_element in keywords_subtree.getchildren(): biblio_object.keywords = "|".join([ biblio_object.keywords, unicode(keyword_element.text) ]) # link bibliographic-record object and passed-in publication object biblio_object.publication = publication_object # save # print " going to save biblio_object", biblio_object, \ # "publication_id", biblio_object.publication_id biblio_object.save() # ++++++URLS++++++ # delete all existing URLs for this biblio-record biblio_object.urls.all().delete() # URL elements are held in a subtree url_subtree = biblio_element.find(SYMPLECTIC_NAMESPACE + 'urls') # check if any url elements in subtree if url_subtree is None or len(url_subtree) < 1: return # for each url element in subtree for url_element in url_subtree.getchildren(): _create_url_object(url_element, biblio_object)
def test_copes_with_null_start_date(self): b = BibliographicRecord() self.assertEqual(b.get_start_date(), "")
def _create_authored(publication_element, researcher_object): """ Takes an XML publication element lifted from a Symplectic User file (which does not contain as much info about each publication/biblio-record as a proper publication XML file) extracts the minimum info (key-fields: guid) about publication, and links publication to researcher extracts the minimum info (key-fields: data-source) about indicated favourite biblio-record for that publication and links biblio-record to researcher extracts full preferences (visible, favourite, sort-order) that researcher has for that publication NOTE: an attempt is made to load an existing publication/biblio-record based on the key-fields extracted if that fails then a new one is created with only the key-fields populated and is then saved """ #++++++PUBLICATION LITE++++++ #check publication Element if publication_element is None: return #publication guid if publication_element is not None: guid = publication_element.get('id', '') if guid == '': return # load Publication from db or create (flagged as needing refetch from # symplectic) if doesnt exist publication_object = Publication.getOrCreatePublication(guid) # ++++++BIBLIOGRAPHICRECORD LITE++++++ # bibliographic-record element -> publication sub element (used to # read XML) if publication_element is not None: # only ONE biblio element per publication will be returned when querying # by User_id this is in contrast to the multiple biblios elements per # publication returned when querying by a Publication_guid biblio_element = publication_element.find( SYMPLECTIC_NAMESPACE + 'bibliographic-record' ) #biblio data-source if biblio_element is not None: data_source = biblio_element.get('data-source', '') # load BibliographicRecord from db or create if doesnt exist (NB # links biblio & publication) # print " going to get or create a BibliographicRecord" biblio_object = BibliographicRecord.getOrCreateBibliographicRecord( publication_object, data_source ) # ++++++AUTHORED++++++ # authored preferences -> publication sub-elements (used to read XML) if publication_element is not None: preferences_element = publication_element.find( SYMPLECTIC_NAMESPACE + 'preferences-for-this-publication' ) # load Authored from db or create if doesnt exist (NB links authored # & publication & researcher & bibliographic-record) authored_object = Authored.getOrCreateAuthored( publication_object, researcher_object, biblio_object ) # preferences if preferences_element is not None: # Show this publication if preferences_element.get('visible', 'false') == 'true': authored_object.visible = True else: authored_object.visible = False # Favourite publication if preferences_element.get('is-a-favourite', 'false') == 'true': authored_object.is_a_favourite = True else: authored_object.is_a_favourite = False # Display order authored_object.reverse_sort_cue = preferences_element.get( 'reverse-sort-cue', '' ) authored_object.save()