def index_shelflist_rows(exp): ''' This is what does the work of determining the locations that need to be updated (based on what locations appear in the exporter object's record set) and stuff. ''' exp.log('Info', 'Creating shelflist item manifests.') solr = pysolr.Solr(settings.HAYSTACK_CONNECTIONS[exp.hs_conn]['URL']) records = exp.get_records() locations = records.order_by('location__code').distinct( 'location__code').values_list('location__code', flat=True) for location in locations: if location: params = { 'q': '*:*', 'fq': ['type:Item', 'location_code:{}'.format(location)], 'fl': 'id', 'sort': 'call_number_type asc, call_number_sort asc, volume_sort ' 'asc, copy_number asc', } hits = solr.search(rows=0, **params).hits results = solr.search(rows=hits, **params) data = [i['id'] for i in results] r = RedisObject('shelflistitem_manifest', location) r.set(data)
def index_shelflist_rows(exp): ''' This is what does the work of determining the locations that need to be updated (based on what locations appear in the exporter object's record set) and stuff. ''' exp.log('Info', 'Creating shelflist item manifests.') solr = pysolr.Solr(settings.HAYSTACK_CONNECTIONS[exp.hs_conn]['URL']) records = exp.get_records() locations = records.order_by('location__code').distinct('location__code' ).values_list('location__code', flat=True) for location in locations: if location: params = { 'q': '*:*', 'fq': ['type:Item', 'location_code:{}'.format(location)], 'fl': 'id', 'sort': 'call_number_type asc, call_number_sort asc, volume_sort ' 'asc, copy_number asc', } hits = solr.search(rows=0, **params).hits results = solr.search(rows=hits, **params) data = [i['id'] for i in results] r = RedisObject('shelflistitem_manifest', location) r.set(data)
def paginate(self, queryset, request): data = super(FirstItemPerLocationList, self).paginate(queryset, request) for item in data['_embedded']['items']: l_code = item['locationCode'] this_id = item['id'] item['_links']['shelflistItem'] = { 'href': ShelflistAPIUris.get_uri( 'shelflistitems-detail', req=request, absolute=True, v=self.api_version, code=l_code, id=this_id) } r = RedisObject('shelflistitem_manifest', l_code) item['rowNumber'] = r.get_index(this_id) return data
def get_page_data(self, queryset, request): data = super(FirstItemPerLocationList, self).get_page_data(queryset, request) for item in data['_embedded']['items']: l_code = item['locationCode'] this_id = item['id'] item['_links']['shelflistItem'] = { 'href': ShelflistAPIUris.get_uri('shelflistitems-detail', req=request, absolute=True, v=self.api_version, code=l_code, id=this_id) } r = RedisObject('shelflistitem_manifest', l_code) item['rowNumber'] = r.get_index(this_id) return data
def process_row_number(self, value, obj): r = RedisObject('shelflistitem_manifest', obj.location_code) return r.get_index(obj.id)
def _get_chunk_obj(self, chunk_id): return RedisObject(self.redis_job_chunk_key, chunk_id)
def _get_totals_obj(self): return RedisObject(self.redis_job_totals_key, self.instance_pk)
def _get_reg_obj(self): return RedisObject(self.redis_job_reg_key, self.instance_pk)
def __call__(self, key): return RedisObject(*key.split(':'))