Exemplo n.º 1
0
 def test_mods_add_topic_already_exists(self):
     #if the topic already exists, just return and don't do anything
     mods_obj = mods.make_mods()
     mods_obj.title = 'title'
     mods_obj.subjects.append(mods.Subject(topic='random'))
     mods.add_topic(mods_obj, 'random')
     self.assertEqual(len(mods_obj.subjects), 1)
     self.assertEqual(mods_obj.subjects[0].topic, 'random')
Exemplo n.º 2
0
 def test_mods_add_topic_incompatible(self):
     #if topic is there, but with different label or authority info, raise an exception
     mods_obj = mods.make_mods()
     mods_obj.title = 'title'
     mods_obj.subjects.append(mods.Subject(topic='random', label='label1'))
     with self.assertRaises(Exception) as cm:
         mods.add_topic(mods_obj, 'random', label='label2')
     self.assertEqual(str(cm.exception), 'mods object already has topic "random"')
Exemplo n.º 3
0
 def _initialize_mods( self, mods_id ):
     """ Initialize empty self.mods element; also sets namespace reference.
         Switching from previous straight etree.Element() build for better bdr compatibility going forward. """
     MODS_NAMESPACE = 'http://www.loc.gov/mods/v3'
     self.MODS = '{%s}' % MODS_NAMESPACE
     bdrxml_mods_obj = mods.make_mods()
     utf8_xml = bdrxml_mods_obj.serialize()
     self.mods = etree.fromstring( utf8_xml )
     return self.mods
Exemplo n.º 4
0
 def test_mods_add_topic_label_and_fast(self):
     mods_obj = mods.make_mods()
     mods_obj.title = 'title'
     mods.add_topic(mods_obj, 'random', label='Label:', fast_uri='http://id.worldcat.org/fast/902025')
     self.assertEqual(mods_obj.subjects[0].topic, 'random')
     self.assertEqual(mods_obj.subjects[0].label, 'Label:')
     self.assertEqual(mods_obj.subjects[0].value_uri, 'http://id.worldcat.org/fast/902025')
     self.assertEqual(mods_obj.subjects[0].authority_uri, 'http://id.worldcat.org/fast')
     self.assertEqual(mods_obj.subjects[0].authority, 'fast')
Exemplo n.º 5
0
 def __init__(self, encoding='utf-8', parent_mods=None):
     self.dataSeparator = u'||'
     self.encoding = encoding
     self._parent_mods = parent_mods
     #dict for keeping track of which fields we've cleared out the parent
     # info for. So we can have multiple columns in the spreadsheet w/ the same field.
     self._cleared_fields = {}
     if parent_mods:
         self._mods = parent_mods
     else:
         self._mods = mods.make_mods()
Exemplo n.º 6
0
 def test_mods_add_topic_partial(self):
     #if topic is partially there, finish adding whatever's missing
     mods_obj = mods.make_mods()
     mods_obj.title = 'title'
     mods_obj.subjects.append(mods.Subject(topic='random', label='label1'))
     mods.add_topic(mods_obj, 'random', label='label1', fast_uri='http://id.worldcat.org/fast/902025')
     self.assertEqual(len(mods_obj.subjects), 1)
     s = mods_obj.subjects[0]
     self.assertEqual(s.topic, 'random')
     self.assertEqual(s.label, 'label1')
     self.assertEqual(s.authority, 'fast')
     self.assertEqual(s.authority_uri, 'http://id.worldcat.org/fast')
     self.assertEqual(s.value_uri, 'http://id.worldcat.org/fast/902025')
 def __init__(self, record_type, field_data, parent_mods=None):
     self.dataSeparator = u'||'
     self._parent_mods = parent_mods
     #dict for keeping track of which fields we've cleared out the parent
     # info for. So we can have multiple columns in the spreadsheet w/ the same field.
     self._cleared_fields = {}
     self._record_type = record_type
     if record_type == 'dwc':
         self._xml_obj = darwincore.make_simple_darwin_record_set()
         self._xml_obj.create_simple_darwin_record()
     else:
         if parent_mods:
             self._xml_obj = parent_mods
         else:
             self._xml_obj = mods.make_mods()
     for field in field_data:
         self.add_data(field['xml_path'], field['data'])
Exemplo n.º 8
0
 def __init__(self, record_type, field_data, parent_mods=None):
     self.dataSeparator = u'||'
     self._parent_mods = parent_mods
     #dict for keeping track of which fields we've cleared out the parent
     # info for. So we can have multiple columns in the spreadsheet w/ the same field.
     self._cleared_fields = {}
     self._record_type = record_type
     if record_type == 'dwc':
         self._xml_obj = darwincore.make_simple_darwin_record_set()
         self._xml_obj.create_simple_darwin_record()
     else:
         if parent_mods:
             self._xml_obj = parent_mods
         else:
             self._xml_obj = mods.make_mods()
     for field in field_data:
         self.add_data(field['xml_path'], field['data'])
Exemplo n.º 9
0
 def test_create(self):
     mets = make_mets()
     #mods
     mods_section = make_mods()
     mods_section.title = 'sample'
     mets.create_mods()
     mets.mods = mods_section
     #dwc
     dwc_section = make_simple_darwin_record_set()
     dwc_section.create_simple_darwin_record()
     dwc_section.simple_darwin_record.catalog_number = 'catalog number'
     mets.create_dwc()
     mets.dwc = dwc_section
     #ir
     mets.create_ir()
     mets.ir.filename = 'sample.txt'
     #filesec -> filegrp
     mets.create_filesec()
     fg = FileGrp()
     fg.id = u'GID1'
     fg.use = u'image-tiff'
     fi = File()
     fi.admid = u'TMD1'
     fi.groupid = u'GRP1'
     fi.id = u'FID1'
     fi.MIMETYPE = u'image/tiff'
     fi.loctype = u'URL'
     fi.href = u'/the/path.tif'
     fg.file.append( fi )
     mets.filesec.filegrp.append( fg )
     #structMap
     mets.create_structmap()  # not used but required for valid mets
     #serialize
     created_string = mets.serialize( pretty=True )
     #load
     loaded = load_xmlobject_from_string(created_string, BDRMets)
     #test
     self.assertEqual(loaded.mods.title, 'sample')
     self.assertEqual(loaded.dwc.simple_darwin_record.catalog_number, 'catalog number')
     self.assertEqual(loaded.ir.filename, 'sample.txt')
     self.assertEqual( type(loaded.structmap), StructMap )
     self.assertEqual( loaded.filesec.filegrp[0].file[0].node.items(), [('ADMID', 'TMD1'), ('GROUPID', 'GRP1'), ('ID', 'FID1')] )
Exemplo n.º 10
0
 def test_create(self):
     import bdrxml
     from bdrxml.foxml import make
     from bdrxml import mods
     from bdrxml.foxml import Datastream, DatastreamVersion, InlineMets
     mets = make_mets()
     #mods
     mods_section = mods.make_mods()
     mods_section.title = 'sample'
     mets.create_mdwrap()
     mets.mdwrap.id = 'MODS'
     mets.mods = mods_section
     #ir
     mets.create_ir()
     mets.ir.filename = 'sample.txt'
     #filesec -> filegrp
     mets.create_filesec()
     fg = FileGrp()
     fg.id = u'GID1'
     fg.use = u'image-tiff'
     fi = File()
     fi.admid = u'TMD1'
     fi.groupid = u'GRP1'
     fi.id = u'FID1'
     fi.MIMETYPE = u'image/tiff'
     fi.loctype = u'URL'
     fi.href = u'/the/path.tif'
     fg.file.append( fi )
     mets.filesec.filegrp.append( fg )
     #structMap
     mets.create_structmap()  # not used but required for valid mets
     #serialize
     created_string = mets.serialize( pretty=True )
     # print created_string
     #load
     loaded = load_xmlobject_from_string(created_string, BDRMets)
     #test
     self.assertEqual(loaded.mods.title, 'sample')
     self.assertEqual(loaded.ir.filename, 'sample.txt')
     self.assertEqual( type(loaded.structmap), bdrxml.mets.StructMap )
     self.assertEqual( loaded.filesec.filegrp[0].file[0].node.items(), [('ADMID', 'TMD1'), ('GROUPID', 'GRP1'), ('ID', 'FID1')] )
Exemplo n.º 11
0
 def get_mods_obj(self, update=False):
     if self._mods_obj:
         #if we have mods already, and we're not updating, just return it
         if not update:
             return self._mods_obj
     else:  #no self._mods_obj
         if update:
             raise Exception('no mods obj - can\'t update')
         self._mods_obj = mods.make_mods()
     #at this point, we want to put the form data into the mods obj (could be update or new)
     self._mods_obj.title_info_list = []  #clear out any old titles
     title = mods.TitleInfo()
     title.title = self._form_data['title']
     if self._form_data['title_language']:
         title.node.set('lang', self._form_data['title_language'])
     self._mods_obj.title_info_list.append(title)
     if self._form_data['english_title']:
         english_title = mods.TitleInfo()
         english_title.title = self._form_data['english_title']
         english_title.node.set('lang', 'en')
         self._mods_obj.title_info_list.append(english_title)
     if self._form_data['genre']:
         self._mods_obj.genres = []  #clear out any old genres
         genre = mods.Genre(text=self._form_data['genre'].text)
         genre.authority = 'aat'
         self._mods_obj.genres.append(genre)
     if self._form_data['abstract']:
         if not self._mods_obj.abstract:
             self._mods_obj.create_abstract()
         self._mods_obj.abstract.text = self._form_data[
             'abstract']  #overwrites old abstract if present
     if self._form_data['impression_date']:
         #clear out old dateOther data, or create originInfo if needed
         if self._mods_obj.origin_info:
             self._mods_obj.origin_info.other = []
         else:
             self._mods_obj.create_origin_info()
         date_other = mods.DateOther(
             date=self._form_data['impression_date'])
         date_other.type = 'impression'
         self._mods_obj.origin_info.other.append(date_other)
     #clear out any old names:
     #   if this is a new object, there aren't any names anyway.
     #   if this is an update, either the new names will be put in, or they don't want any names.
     self._mods_obj.names = []
     for p in self._person_formset_data:
         name = mods.Name()
         np = mods.NamePart(text=p['person'].name)
         name.name_parts.append(np)
         role = mods.Role(text=p['role'].text)
         name.roles.append(role)
         href = '{%s}href' % app_settings.XLINK_NAMESPACE
         name.node.set(href, p['person'].trp_id)
         self._mods_obj.names.append(name)
     #clear out old notes data, preserving any annotor info
     self._mods_obj.notes = [
         note for note in self._mods_obj.notes if note.type == 'resp'
     ]
     for i in self._inscription_formset_data:
         note = mods.Note(text=i['text'])
         note.type = 'inscription'
         note.label = i['location']
         self._mods_obj.notes.append(note)
     annotator_note = mods.Note(text=self._annotator)
     annotator_note.type = 'resp'
     self._mods_obj.notes.append(annotator_note)
     return self._mods_obj
Exemplo n.º 12
0
 def test_mods_add_topic(self):
     mods_obj = mods.make_mods()
     mods_obj.title = 'title'
     mods.add_topic(mods_obj, 'random')
     self.assertEqual(mods_obj.subjects[0].topic, 'random')
Exemplo n.º 13
0
 def setUp(self):
     #basic fox
     self.mods = make_mods()
Exemplo n.º 14
0
 def __init__(self, thesis):
     self.thesis = thesis
     self.mods_obj = mods.make_mods()
     self._map_to_mods()
Exemplo n.º 15
0
 def get_mods_obj(self, update=False):
     if self._mods_obj:
         # if we have mods already, and we're not updating, just return it
         if not update:
             return self._mods_obj
     else:  # no self._mods_obj
         if update:
             raise Exception("no mods obj - can't update")
         self._mods_obj = mods.make_mods()
     # at this point, we want to put the form data into the mods obj (could be update or new)
     self._mods_obj.title_info_list = []  # clear out any old titles
     title = mods.TitleInfo()
     title.title = self._form_data["title"]
     if self._form_data["title_language"]:
         title.node.set("lang", self._form_data["title_language"])
     self._mods_obj.title_info_list.append(title)
     if self._form_data["english_title"]:
         english_title = mods.TitleInfo()
         english_title.title = self._form_data["english_title"]
         english_title.node.set("lang", "en")
         self._mods_obj.title_info_list.append(english_title)
     if self._form_data["genre"]:
         self._mods_obj.genres = []  # clear out any old genres
         genre = mods.Genre(text=self._form_data["genre"].text)
         genre.authority = "aat"
         self._mods_obj.genres.append(genre)
     if self._form_data["abstract"]:
         if not self._mods_obj.abstract:
             self._mods_obj.create_abstract()
         self._mods_obj.abstract.text = self._form_data["abstract"]  # overwrites old abstract if present
     if self._form_data["impression_date"]:
         # clear out old dateOther data, or create originInfo if needed
         if self._mods_obj.origin_info:
             self._mods_obj.origin_info.other = []
         else:
             self._mods_obj.create_origin_info()
         date_other = mods.DateOther(date=self._form_data["impression_date"])
         date_other.type = "impression"
         self._mods_obj.origin_info.other.append(date_other)
     # clear out any old names:
     #   if this is a new object, there aren't any names anyway.
     #   if this is an update, either the new names will be put in, or they don't want any names.
     self._mods_obj.names = []
     for p in self._person_formset_data:
         name = mods.Name()
         np = mods.NamePart(text=p["person"].name)
         name.name_parts.append(np)
         role = mods.Role(text=p["role"].text)
         name.roles.append(role)
         href = "{%s}href" % app_settings.XLINK_NAMESPACE
         name.node.set(href, p["person"].trp_id)
         self._mods_obj.names.append(name)
     # clear out old notes data, preserving any annotor info
     self._mods_obj.notes = [note for note in self._mods_obj.notes if note.type == "resp"]
     for i in self._inscription_formset_data:
         note = mods.Note(text=i["text"])
         note.type = "inscription"
         note.label = i["location"]
         self._mods_obj.notes.append(note)
     annotator_note = mods.Note(text=self._annotator)
     annotator_note.type = "resp"
     self._mods_obj.notes.append(annotator_note)
     return self._mods_obj
Exemplo n.º 16
0
 def setUp(self):
     #basic mods
     self.mods = mods.make_mods()
Exemplo n.º 17
0
 def __init__(self, thesis):
     self.thesis = thesis
     self.mods_obj = mods.make_mods()
     self._map_to_mods()