def store_records(self, act_table, recs): """ stores records retrieved for a given table """ i = 0 for record in recs: i += 1 allow_write = self.check_allow_write(act_table, record) record = self.prep_update_keep_old(act_table, record) if (allow_write is False and self.update_keep_old is False): print('\n Not allowed to overwite record.' + str(i)) else: # print('\n Adding record:' + str(record)) newr = False if (act_table == 'link_annotations'): newr = LinkAnnotation(**record) elif (act_table == 'link_entities'): newr = LinkEntity(**record) elif (act_table == 'oc_assertions'): newr = Assertion(**record) elif (act_table == 'oc_manifest'): newr = Manifest(**record) elif (act_table == 'oc_subjects'): newr = Subject(**record) elif (act_table == 'oc_mediafiles'): newr = Mediafile(**record) elif (act_table == 'oc_documents'): newr = OCdocument(**record) elif (act_table == 'oc_persons'): newr = Person(**record) elif (act_table == 'oc_projects'): newr = Project(**record) elif (act_table == 'oc_strings'): newr = OCstring(**record) elif (act_table == 'oc_types'): newr = OCtype(**record) elif (act_table == 'oc_geospace'): newr = Geospace(**record) elif (act_table == 'oc_events'): newr = Event(**record) elif (act_table == 'oc_predicates'): newr = Predicate(**record) elif (act_table == 'oc_identifiers'): newr = StableIdentifer(**record) elif (act_table == 'oc_obsmetadata'): newr = ObsMetadata(**record) if (newr is not False): try: newr.save(force_insert=self.force_insert, force_update=self.update_keep_old) except Exception as error: print('Something slipped past in ' + act_table + '...' + str(error))
def store_records(self, act_table, recs): """ stores records retrieved for a given table """ for rkey, record in recs.items(): if (act_table == 'link_annotations'): newr = LinkAnnotation(**record) newr.save() elif (act_table == 'link_entities'): newr = LinkEntity(**record) newr.save() elif (act_table == 'link_hierarchies'): newr = LinkHierarchy(**record) newr.save() elif (act_table == 'oc_chronology'): newr = Chronology(**record) newr.save() elif (act_table == 'oc_geodata'): newr = Geodata(**record) newr.save() elif (act_table == 'oc_mediafiles'): newr = Mediafile(**record) newr.save() elif (act_table == 'oc_documents'): newr = OCdocument(**record) newr.save() elif (act_table == 'oc_persons'): newr = Person(**record) newr.save() elif (act_table == 'oc_projects'): newr = Project(**record) newr.save() elif (act_table == 'oc_strings'): newr = OCstring(**record) newr.save() elif (act_table == 'oc_types'): newr = OCtype(**record) newr.save() elif (act_table == 'oc_events'): newr = Event(**record) newr.save() elif (act_table == 'oc_predicates'): newr = Predicate(**record) newr.save() elif (act_table == 'oc_identifiers'): newr = StableIdentifer(**record) newr.save() elif (act_table == 'oc_obsmetadata'): newr = ObsMetadata(**record) newr.save()
def create_person_item(self): """ Create and save a new subject object""" new_pers = Person() new_pers.uuid = self.uuid # use the previously assigned temporary UUID new_pers.project_uuid = self.project_uuid new_pers.source_id = self.source_id new_pers.foaf_type = self.foaf_type new_pers.combined_name = self.combined_name new_pers.given_name = self.given_name new_pers.surname = self.surname new_pers.mid_init = self.mid_init new_pers.initials = self.initials new_pers.save() new_man = Manifest() new_man.uuid = self.uuid new_man.project_uuid = self.project_uuid new_man.source_id = self.source_id new_man.item_type = 'persons' new_man.repo = '' new_man.class_uri = self.foaf_type new_man.label = self.label new_man.des_predicate_uuid = '' new_man.views = 0 new_man.save()
def create_person(self, post_data): """ creates a person item into a project """ ok = True required_params = ['source_id', 'item_type', 'foaf_type', 'combined_name', 'given_name', 'surname', 'mid_init', 'initials'] for r_param in required_params: if r_param not in post_data: # we're missing some required data # don't create the item ok = False message = 'Missing paramater: ' + r_param + '' self.errors.append(message) uuid = self.create_or_validate_uuid(post_data) if uuid is False: ok = False note = '; '.join(self.errors) if ok: label = post_data['combined_name'] new_pers = Person() new_pers.uuid = uuid new_pers.project_uuid = self.project_uuid new_pers.source_id = post_data['source_id'] new_pers.foaf_type = post_data['foaf_type'] new_pers.combined_name = post_data['combined_name'] new_pers.given_name = post_data['given_name'] new_pers.surname = post_data['surname'] new_pers.mid_init = post_data['mid_init'] new_pers.initials = post_data['initials'] new_pers.save() new_man = Manifest() new_man.uuid = uuid new_man.project_uuid = self.project_uuid new_man.source_id = post_data['source_id'] new_man.item_type = 'persons' new_man.repo = '' new_man.class_uri = post_data['foaf_type'] new_man.label = post_data['combined_name'] new_man.des_predicate_uuid = '' new_man.views = 0 new_man.save() self.created_uuid = uuid else: label = '[Item not created]' uuid = False if ok: # now clear the cache a change was made self.clear_caches() self.response = {'action': 'create-item-into', 'ok': ok, 'change': {'uuid': uuid, 'label': label, 'note': self.add_creation_note(ok)}} return self.response
def create_person(self, post_data): """ creates a person item into a project """ ok = True required_params = [ 'source_id', 'item_type', 'foaf_type', 'combined_name', 'given_name', 'surname', 'mid_init', 'initials' ] for r_param in required_params: if r_param not in post_data: # we're missing some required data # don't create the item ok = False message = 'Missing paramater: ' + r_param + '' if self.errors['params'] is False: self.errors['params'] = message else: self.errors['params'] += '; ' + message uuid = self.create_or_validate_uuid(post_data) if uuid is False: ok = False note = self.errors['uuid'] if ok: label = post_data['combined_name'] new_pers = Person() new_pers.uuid = uuid new_pers.project_uuid = self.project_uuid new_pers.source_id = post_data['source_id'] new_pers.foaf_type = post_data['foaf_type'] new_pers.combined_name = post_data['combined_name'] new_pers.given_name = post_data['given_name'] new_pers.surname = post_data['surname'] new_pers.mid_init = post_data['mid_init'] new_pers.initials = post_data['initials'] new_pers.save() new_man = Manifest() new_man.uuid = uuid new_man.project_uuid = self.project_uuid new_man.source_id = post_data['source_id'] new_man.item_type = 'persons' new_man.repo = '' new_man.class_uri = post_data['foaf_type'] new_man.label = post_data['combined_name'] new_man.des_predicate_uuid = '' new_man.views = 0 new_man.save() else: label = '[Item not created]' uuid = False self.response = { 'action': 'create-item-into', 'ok': ok, 'change': { 'uuid': uuid, 'label': label, 'note': self.add_creation_note(ok) } } return self.response