"""
Exporters for the Shelflist app are defined here. See export.exporter
for the base Exporter classes and export.basic_exporters for some
implementations. Here we pretty much just need to define the
final_callback method for item exporters so that any locations
represented in the items have their shelflist row manifest document in
Solr updated automatically whenever items are loaded.
"""

from __future__ import unicode_literals
import logging

from export import exporter, basic_exporters as exporters
from shelflist.search_indexes import ShelflistItemIndex
from utils import solr, redisobjs


# set up logger, for debugging
logger = logging.getLogger('sierra.custom')


class ItemsToSolr(exporters.ItemsToSolr):

    Index = exporters.ItemsToSolr.Index
    index_config = (
        Index('Items', ShelflistItemIndex,
              exporters.SOLR_CONNS['ItemsToSolr']),
    )
    max_rec_chunk = 500
    app_name = 'shelflist'
    redis_shelflist_prefix = 'shelflistitem_manifest'

    def export_records(self, records):
        super(ItemsToSolr, self).export_records(records)
        return { 'seen_lcodes': self.indexes['Items'].location_set }

    def delete_records(self, records):
        seen_lcodes = self.indexes['Items'].get_location_set_from_recs(records)
        super(ItemsToSolr, self).delete_records(records)
        return { 'seen_lcodes': seen_lcodes }

    def compile_vals(self, results):
        if results is not None:
            vals = { 'seen_lcodes': set() }
            for result in results:
                result = result or {}
                vals['seen_lcodes'] |= result.get('seen_lcodes', set())
            return vals

    def final_callback(self, vals=None, status='success'):
        vals = vals or {}
        super(ItemsToSolr, self).final_callback(vals, status)
        lcodes = list(vals.get('seen_lcodes', []))
        total = len(lcodes)
        for i, lcode in enumerate(lcodes):
            msg = ('Rebuilding shelflist item manifest for location {} '
                   '({} of {}) ...'.format(lcode, i + 1, total))
            self.log('Info', msg)
            manifest = self.indexes['Items'].get_location_manifest(lcode)
            r = redisobjs.RedisObject(self.redis_shelflist_prefix, lcode)
            r.set(manifest)

@@ -1883,55 +1883,8 @@
 es)%0A
-        for i, lcode in enumerate(lcodes):%0A    
     
@@ -1899,11 +1899,9 @@
 = ('
-Reb
+B
 uild
@@ -1931,16 +1931,19 @@
 fest for
+ %7B%7D
  locatio
@@ -1943,20 +1943,23 @@
 location
+(s):
  %7B%7D
- 
 '%0A      
@@ -1971,91 +1971,117 @@
     
-    '(%7B%7D of %7B%7D) ...'.format(lcode, i + 1, total))%0A            self.log('Info', msg)
+''.format(total, ', '.join(lcodes)))%0A        self.log('Info', msg)%0A        for i, lcode in enumerate(lcodes):
 %0A   

Make log messages less verbose