<s> from __future__ import unicode_literals <EOL> from django . core . exceptions import ImproperlyConfigured <EOL> from haystack import indexes <EOL> class BaseSearchIndex ( indexes . SearchIndex ) : <EOL> """<STR_LIT>""" <EOL> model = None <EOL> local_site_attr = None <EOL> text = indexes . CharField ( document = True , use_template = True ) <EOL> local_sites = indexes . MultiValueField ( null = True ) <EOL> NO_LOCAL_SITE_ID = <NUM_LIT:0> <EOL> def get_model ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . model <EOL> def prepare_local_sites ( self , obj ) : <EOL> """<STR_LIT>""" <EOL> if not self . local_site_attr : <EOL> raise ImproperlyConfigured ( '<STR_LIT>' <EOL> % self . __class__ ) <EOL> if not hasattr ( obj , self . local_site_attr ) : <EOL> raise ImproperlyConfigured ( <EOL> '<STR_LIT>' <EOL> % ( self . local_site_attr , obj . __class__ ) ) <EOL> local_sites = getattr ( obj , self . local_site_attr , None ) <EOL> if self . local_site_attr . endswith ( '<STR_LIT>' ) : <EOL> if local_sites is not None : <EOL> return [ local_sites ] <EOL> else : <EOL> return [ self . NO_LOCAL_SITE_ID ] <EOL> else : <EOL> return ( list ( local_sites . values_list ( '<STR_LIT>' , flat = True ) ) or <EOL> [ self . NO_LOCAL_SITE_ID ] ) </s>
