def test_aa_check(self): # Make sure that some other test hasn't set it try: del model.AttributeAssignment.set_assigned_property except: pass t = model.Type() aa = model.AttributeAssignment() # First check that aa accepts a type aa.assigned_property = t # And will not accept a string self.assertRaises(model.DataError, aa.__setattr__, "assigned_property", "classified_as") # Check we can set anything to assigned / assigned_to aa.assigned_property = None aa.assigned = aa aa.assigned_to = aa self.assertEqual(aa.assigned, aa) self.assertEqual(aa.assigned_to, aa) vocab.add_attribute_assignment_check() # This should fail right now as can't classify as an AA self.assertRaises(model.DataError, aa.__setattr__, "assigned_property", "classified_as") aa.assigned = None aa.assigned_to = None aa.assigned = t aa.assigned_to = t aa.assigned_property = "classified_as" self.assertEqual(aa.assigned_property, 'classified_as')
def knoedler_number_id(self, content): k_id = vocab.LocalNumber(ident='', content=content) assignment = model.AttributeAssignment(ident='') assignment.carried_out_by = self.static_instances.get_instance( 'Group', 'knoedler') k_id.assigned_by = assignment return k_id
def lugt_number_id(self, content): lugt_number = str(content) lugt_id = vocab.LocalNumber(ident='', label=f'Lugt Number: {lugt_number}', content=lugt_number) assignment = model.AttributeAssignment(ident='') assignment.carried_out_by = self.static_instances.get_instance( 'Person', 'lugt') lugt_id.assigned_by = assignment return lugt_id
def gri_number_id(self, content, id_class=None): if id_class is None: id_class = vocab.LocalNumber catalog_id = id_class(ident='', content=content) assignment = model.AttributeAssignment( ident=self.make_shared_uri('__gri_attribute_assignment')) assignment.carried_out_by = self.static_instances.get_instance( 'Group', 'gri') catalog_id.assigned_by = assignment return catalog_id
def _populate_object_present_location(self, data: dict, now_key, destruction_types_map): hmo = get_crom_object(data) location = data.get('present_location') if location: loc = location.get('geog') note = location.get('note') if loc: if 'destroyed ' in loc.lower(): self.populate_destruction_events( data, loc, type_map=destruction_types_map) elif isinstance(note, str) and 'destroyed ' in note.lower(): # the object was destroyed, so any "present location" data is actually # an indication of the location of destruction. self.populate_destruction_events( data, note, type_map=destruction_types_map, location=loc) else: # TODO: if `parse_location_name` fails, still preserve the location string somehow current = parse_location_name( loc, uri_base=self.helper.uid_tag_prefix) inst = location.get('inst') if inst: owner_data = { 'label': f'{inst} ({loc})', 'identifiers': [model.Name(ident='', content=inst)] } ulan = None with suppress(ValueError, TypeError): ulan = int(location.get('insi')) if ulan: owner_data['ulan'] = ulan owner_data['uri'] = self.helper.make_proj_uri( 'ORG', 'ULAN', ulan) else: owner_data['uri'] = self.helper.make_proj_uri( 'ORG', 'NAME', inst, 'PLACE', loc) else: owner_data = { 'label': '(Anonymous organization)', 'uri': self.helper.make_proj_uri('ORG', 'CURR-OWN', *now_key), } if note: owner_data['note'] = note base_uri = hmo.id + '-Place,' place_data = self.helper.make_place(current, base_uri=base_uri) place = get_crom_object(place_data) make_la_org = pipeline.linkedart.MakeLinkedArtOrganization( ) owner_data = make_la_org(owner_data) owner = get_crom_object(owner_data) acc = location.get('acc') if acc: acc_number = vocab.AccessionNumber(ident='', content=acc) hmo.identified_by = acc_number assignment = model.AttributeAssignment(ident='') assignment.carried_out_by = owner acc_number.assigned_by = assignment owner.residence = place data['_locations'].append(place_data) data['_final_org'] = owner_data else: pass # there is no present location place string
def _populate_object_present_location(self, data: dict, now_key, destruction_types_map): hmo = get_crom_object(data) location = data.get('present_location') if location: loc = location.get('geog') note = location.get('note') # in these two if blocks, the object was destroyed, so any "present location" # data is actually an indication of the location of destruction. if isinstance(loc, str) and 'destroyed ' in loc.lower(): self.populate_destruction_events( data, loc, type_map=destruction_types_map) loc = None elif isinstance(note, str) and 'destroyed ' in note.lower(): self.populate_destruction_events( data, note, type_map=destruction_types_map, location=loc) note = None if loc: # TODO: if `parse_location_name` fails, still preserve the location string somehow current = parse_location_name( loc, uri_base=self.helper.uid_tag_prefix) inst = location.get('inst') if inst: owner_data = { 'label': f'{inst} ({loc})', 'identifiers': [model.Name(ident='', content=inst)] } ulan = None with suppress(ValueError, TypeError): ulan = int(location.get('insi')) if ulan: owner_data['ulan'] = ulan owner_data['uri'] = self.helper.make_proj_uri( 'ORG', 'ULAN', ulan) else: owner_data['uri'] = self.helper.make_proj_uri( 'ORG', 'NAME', inst, 'PLACE', loc) else: owner_data = { 'label': '(Anonymous organization)', 'uri': self.helper.make_proj_uri('ORG', 'CURR-OWN', *now_key), } if note: owner_data['note'] = note # It's conceivable that there could be more than one "present location" # for an object that is reconciled based on prev/post sale rewriting. # Therefore, the place URI must not share a prefix with the object URI, # otherwise all such places are liable to be merged during URI # reconciliation as part of the prev/post sale rewriting. base_uri = self.helper.prepend_uri_key(hmo.id, 'PLACE') place_data = self.helper.make_place(current, base_uri=base_uri) place = get_crom_object(place_data) make_la_org = pipeline.linkedart.MakeLinkedArtOrganization() owner_data = make_la_org(owner_data) owner = get_crom_object(owner_data) acc = location.get('acc') if acc: acc_number = vocab.AccessionNumber(ident='', content=acc) hmo.identified_by = acc_number assignment = model.AttributeAssignment(ident='') assignment.carried_out_by = owner acc_number.assigned_by = assignment owner.residence = place data['_locations'].append(place_data) data['_final_org'] = owner_data else: pass # there is no present location place string