def test_index_solr_doc(): from opencontext_py.apps.ocitems.manifest.models import Manifest from opencontext_py.apps.indexer.reindex import SolrReIndex uuids = ['3FAAA477-5572-4B05-8DC1-CA264FE1FC10'] sri = SolrReIndex() sri.reindex_uuids(uuids)
def index_linked_dinaa_sites(self): """ indexes DINAA sites liked to the federal registry """ uuids = [] links = LinkAnnotation.objects\ .filter(source_id=self.source_id, subject_type='subjects') for link in links: if link.subject not in uuids: uuids.append(link.subject) # reindex those links sri = SolrReIndex() sri.reindex_uuids(uuids)
def create_update(self, field_data): """ creates or updates an item with post data """ # first check to see if the item exists item_type = None label = None try: item_man = Manifest.objects.get(uuid=self.edit_uuid) action = 'update-profle-item' note = 'Item found, updating.' self.new_item = False except Manifest.DoesNotExist: item_man = False action = 'create-profle-item' note = 'Item not found, creating.' self.new_item = True if isinstance(field_data, dict): # now collect the required field data required_make_data = self.get_required_make_data(field_data) if item_man is not False: # we've found a record for this item, so we can # update any of the required fields. self.update_required_make_data(item_man, required_make_data) else: item_man = self.create_item(required_make_data) if item_man is not False: label = item_man.label item_type = item_man.item_type # the act_sub_field below is a field from field_data # submitted by the user for sub_field_key, act_sub_field in field_data.items(): self.profile_field_update(item_man, sub_field_key, act_sub_field) if self.do_solr_index: if item_man.uuid not in self.solr_reindex_uuids: self.solr_reindex_uuids.append(item_man.uuid) sri = SolrReIndex() num_reindexed = sri.reindex_uuids(self.solr_reindex_uuids) note += ' Indexed ' + str(num_reindexed) + ' items.' else: self.ok = False label = 'No item' note += '.. FAILED!' else: self.ok = False label = 'No item' note += '.. "field_data" needs to be a dictionary object (parsed from JSON)' if self.ok: # now clear the cache a change was made self.clear_caches() self.response = { 'action': action, 'ok': self.ok, 'change': { 'uuid': self.edit_uuid, 'item_type': item_type, 'label': label, 'note': note } } return self.response
def create_update(self, field_data): """ creates or updates an item with post data """ # first check to see if the item exists item_type = None label = None try: item_man = Manifest.objects.get(uuid=self.edit_uuid) action = 'update-profle-item' note = 'Item found, updating.' self.new_item = False except Manifest.DoesNotExist: item_man = False action = 'create-profle-item' note = 'Item not found, creating.' self.new_item = True if isinstance(field_data, dict): # now collect the required field data required_make_data = self.get_required_make_data(field_data) if item_man is not False: # we've found a record for this item, so we can # update any of the required fields. self.update_required_make_data(item_man, required_make_data) else: item_man = self.create_item(required_make_data) if item_man is not False: label = item_man.label item_type = item_man.item_type # the act_sub_field below is a field from field_data # submitted by the user for sub_field_key, act_sub_field in field_data.items(): self.profile_field_update(item_man, sub_field_key, act_sub_field) if self.do_solr_index: if item_man.uuid not in self.solr_reindex_uuids: self.solr_reindex_uuids.append(item_man.uuid) sri = SolrReIndex() num_reindexed = sri.reindex_uuids(self.solr_reindex_uuids) note += ' Indexed ' + str(num_reindexed) + ' items.' else: self.ok = False label = 'No item' note += '.. FAILED!' else: self.ok = False label = 'No item' note += '.. "field_data" needs to be a dictionary object (parsed from JSON)' if self.ok: # now clear the cache a change was made self.clear_caches() self.response = {'action': action, 'ok': self.ok, 'change': {'uuid': self.edit_uuid, 'item_type': item_type, 'label': label, 'note': note}} return self.response
def create_update(self, field_data): """ creates or updates an item with post data """ # first check to see if the item exists try: item_man = Manifest.objects.get(uuid=self.edit_uuid) action = 'update-profle-item' note = 'Item found, updating.' self.new_item = False except Manifest.DoesNotExist: item_man = False action = 'create-profle-item' note = 'Item not found, creating.' self.new_item = True # now collect the required field data required_make_data = self.get_required_make_data(field_data) if item_man is not False: # we've found a record for this item, so we can # update any of the required fields. self.update_required_make_data(item_man, required_make_data) else: item_man = self.create_item(required_make_data) if item_man is not False: label = item_man.label for field_uuid, field_values in field_data.items(): self.profile_field_update(item_man, field_uuid, field_values) if self.do_solr_index: if item_man.uuid not in self.solr_reindex_uuids: self.solr_reindex_uuids.append(item_man.uuid) sri = SolrReIndex() num_reindexed = sri.reindex_uuids(self.solr_reindex_uuids) note += ' Indexed ' + str(num_reindexed) + ' items.' else: self.ok = False label = 'No item' note += '.. FAILED!' self.response = { 'action': action, 'ok': self.ok, 'change': { 'uuid': self.edit_uuid, 'label': label, 'note': note } } return self.response
def create_update(self, field_data): """ creates or updates an item with post data """ # first check to see if the item exists try: item_man = Manifest.objects.get(uuid=self.edit_uuid) action = 'update-profle-item' note = 'Item found, updating.' self.new_item = False except Manifest.DoesNotExist: item_man = False action = 'create-profle-item' note = 'Item not found, creating.' self.new_item = True # now collect the required field data required_make_data = self.get_required_make_data(field_data) if item_man is not False: # we've found a record for this item, so we can # update any of the required fields. self.update_required_make_data(item_man, required_make_data) else: item_man = self.create_item(required_make_data) if item_man is not False: label = item_man.label for field_uuid, field_values in field_data.items(): self.profile_field_update(item_man, field_uuid, field_values) if self.do_solr_index: if item_man.uuid not in self.solr_reindex_uuids: self.solr_reindex_uuids.append(item_man.uuid) sri = SolrReIndex() num_reindexed = sri.reindex_uuids(self.solr_reindex_uuids) note += ' Indexed ' + str(num_reindexed) + ' items.' else: self.ok = False label = 'No item' note += '.. FAILED!' self.response = {'action': action, 'ok': self.ok, 'change': {'uuid': self.edit_uuid, 'label': label, 'note': note}} return self.response