#NEWLINE# def lookup_translations( language_code = None ) : #NEWLINE# #INDENT# "\n    Pass the return value of this function to .transform() to automatically\n    resolve translation objects\n\n    The current language is used if ``language_code`` isn't specified.\n    " #NEWLINE# def _transform( qs ) : #NEWLINE# #INDENT# lang_ = ( language_code if language_code else translation . get_language ( ) ) #NEWLINE# instance_dict = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for instance in qs : #NEWLINE# #INDENT# trans = cache . get ( instance . get_translation_cache_key ( lang_ ) ) #NEWLINE# if trans : #NEWLINE# #INDENT# if ( trans is _NoTranslation ) : #NEWLINE# #INDENT# instance . _cached_translation = None #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# instance . _cached_translation = trans #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# instance_dict [ instance . pk ] = instance #NEWLINE# #UNINDENT# #UNINDENT# if ( not instance_dict ) : #NEWLINE# #INDENT# return #NEWLINE# #UNINDENT# candidates = list ( instance_dict . values ( ) ) [ 0 ] . translations . model . _default_manager . all ( ) #NEWLINE# if instance_dict : #NEWLINE# #INDENT# _process ( candidates , instance_dict , lang_ , 'iexact' ) #NEWLINE# #UNINDENT# if instance_dict : #NEWLINE# #INDENT# _process ( candidates , instance_dict , settings . LANGUAGE_CODE , 'istartswith' ) #NEWLINE# #UNINDENT# if instance_dict : #NEWLINE# #INDENT# for candidate in candidates . filter ( parent__pk__in = instance_dict . keys ( ) ) : #NEWLINE# #INDENT# if ( candidate . parent_id in instance_dict ) : #NEWLINE# #INDENT# _found ( instance_dict , candidate ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# for instance in instance_dict . values ( ) : #NEWLINE# #INDENT# instance . _cached_translation = None #NEWLINE# #UNINDENT# #UNINDENT# def _found( instance_dict , candidate ) : #NEWLINE# #INDENT# parent = instance_dict [ candidate . parent_id ] #NEWLINE# cache . set ( parent . get_translation_cache_key ( ) , candidate ) #NEWLINE# parent . _cached_translation = candidate #NEWLINE# candidate . parent = parent #NEWLINE# del instance_dict [ candidate . parent_id ] #NEWLINE# #UNINDENT# def _process( candidates , instance_dict , lang_ , op_ ) : #NEWLINE# #INDENT# candidates = candidates . filter ( Q ( parent__pk__in = instance_dict . keys ( ) ) , ( Q ( ** { #NEWLINE# #INDENT# ( 'language_code__' + op_ ) : lang_ , #NEWLINE# #UNINDENT# } ) | Q ( ** { #NEWLINE# #INDENT# ( 'language_code__' + op_ ) : short_language_code ( lang_ ) , #NEWLINE# #UNINDENT# } ) ) ) . order_by ( '-language_code' ) #NEWLINE# for candidate in candidates : #NEWLINE# #INDENT# if ( candidate . parent_id in instance_dict ) : #NEWLINE# #INDENT# _found ( instance_dict , candidate ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return _process