<s> from __future__ import unicode_literals <EOL> import importlib <EOL> import re <EOL> from django . conf import settings <EOL> from django . utils import six <EOL> from haystack . constants import ID , DJANGO_CT , DJANGO_ID <EOL> from haystack . utils . highlighting import Highlighter <EOL> IDENTIFIER_REGEX = re . compile ( '<STR_LIT>' ) <EOL> def default_get_identifier ( obj_or_string ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( obj_or_string , six . string_types ) : <EOL> if not IDENTIFIER_REGEX . match ( obj_or_string ) : <EOL> raise AttributeError ( u"<STR_LIT>" % obj_or_string ) <EOL> return obj_or_string <EOL> return u"<STR_LIT>" % ( get_model_ct ( obj_or_string ) , <EOL> obj_or_string . _get_pk_val ( ) ) <EOL> def _lookup_identifier_method ( ) : <EOL> """<STR_LIT>""" <EOL> if not hasattr ( settings , '<STR_LIT>' ) : <EOL> return default_get_identifier <EOL> module_path , method_name = settings . HAYSTACK_IDENTIFIER_METHOD . rsplit ( "<STR_LIT:.>" , <NUM_LIT:1> ) <EOL> try : <EOL> module = importlib . import_module ( module_path ) <EOL> except ImportError : <EOL> raise ImportError ( u"<STR_LIT>" % module_path ) <EOL> identifier_method = getattr ( module , method_name , None ) <EOL> if not identifier_method : <EOL> raise AttributeError ( <EOL> u"<STR_LIT>" % ( method_name , module_path ) <EOL> ) <EOL> return identifier_method <EOL> get_identifier = _lookup_identifier_method ( ) <EOL> def get_model_ct_tuple ( model ) : <EOL> return ( model . _meta . app_label , model . _meta . model_name ) <EOL> def get_model_ct ( model ) : <EOL> return "<STR_LIT>" % get_model_ct_tuple ( model ) <EOL> def get_facet_field_name ( fieldname ) : <EOL> if fieldname in [ ID , DJANGO_ID , DJANGO_CT ] : <EOL> return fieldname <EOL> return "<STR_LIT>" % fieldname </s>
