#NEWLINE# def ajax_lookup( request , channel ) : #NEWLINE# #INDENT# ' this view supplies results for both foreign keys and many to many fields ' #NEWLINE# if ( request . method == 'GET' ) : #NEWLINE# #INDENT# if ( 'q' not in request . GET ) : #NEWLINE# #INDENT# return HttpResponse ( '' ) #NEWLINE# #UNINDENT# query = request . GET [ 'q' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( 'q' not in request . POST ) : #NEWLINE# #INDENT# return HttpResponse ( '' ) #NEWLINE# #UNINDENT# query = request . POST [ 'q' ] #NEWLINE# #UNINDENT# lookup_channel = get_lookup ( channel ) #NEWLINE# if query : #NEWLINE# #INDENT# instances = lookup_channel . get_query ( query , request ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# instances = [ ] #NEWLINE# #UNINDENT# results = [ ] #NEWLINE# for item in instances : #NEWLINE# #INDENT# itemf = lookup_channel . format_item ( request ) #NEWLINE# itemf = itemf . replace ( '\n' , '' ) . replace ( '|' , '&brvbar;' ) #NEWLINE# resultf = lookup_channel . format_result ( item ) #NEWLINE# resultf = resultf . replace ( '\n' , '' ) . replace ( '|' , '&brvbar;' ) #NEWLINE# results . append ( '|' . join ( ( unicode ( item . pk ) , itemf , resultf ) ) ) #NEWLINE# #UNINDENT# return HttpResponse ( '\n' . join ( results ) )