#NEWLINE# def render( self , name , value , attrs = None , choices = ( ) ) : #NEWLINE# #INDENT# if ( len ( name . split ( '-' ) ) > 1 ) : #NEWLINE# #INDENT# chained_field = '-' . join ( ( name . split ( '-' ) [ : ( - 1 ) ] + [ self . chained_field ] ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# chained_field = self . chained_field #NEWLINE# #UNINDENT# if ( not self . view_name ) : #NEWLINE# #INDENT# if self . show_all : #NEWLINE# #INDENT# view_name = 'chained_filter_all' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# view_name = 'chained_filter' #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# view_name = self . view_name #NEWLINE# #UNINDENT# kwargs = { #NEWLINE# #INDENT# 'app' : self . to_app_name , #NEWLINE# 'model' : self . to_model_name , #NEWLINE# 'field' : self . chained_model_field , #NEWLINE# 'foreign_key_app_name' : self . foreign_key_app_name , #NEWLINE# 'foreign_key_model_name' : self . foreign_key_model_name , #NEWLINE# 'foreign_key_field_name' : self . foreign_key_field_name , #NEWLINE# 'value' : '1' , #NEWLINE# #UNINDENT# } #NEWLINE# if ( self . manager is not None ) : #NEWLINE# #INDENT# kwargs . update ( { #NEWLINE# #INDENT# 'manager' : self . manager , #NEWLINE# #UNINDENT# } ) #NEWLINE# #UNINDENT# url = ( URL_PREFIX + '/' . join ( reverse ( view_name , kwargs = kwargs ) . split ( '/' ) [ : ( - 2 ) ] ) ) #NEWLINE# if self . auto_choose : #NEWLINE# #INDENT# auto_choose = 'true' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# auto_choose = 'false' #NEWLINE# #UNINDENT# iterator = iter ( self . choices ) #NEWLINE# if hasattr ( iterator , '__next__' ) : #NEWLINE# #INDENT# empty_label = iterator . __next__ ( ) [ 1 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# empty_label = iterator . next ( ) [ 1 ] #NEWLINE# #UNINDENT# js = '\n        <script type="text/javascript">\n        (function($) {\n            var chainfield = "#id_%(chainfield)s";\n            var url = "%(url)s";\n            var id = "#%(id)s";\n            var value = %(value)s;\n            var auto_choose = %(auto_choose)s;\n            var empty_label = "%(empty_label)s";\n\n            $(document).ready(function() {\n                chainedfk.init(chainfield, url, id, value, empty_label, auto_choose);\n            });\n        })(jQuery || django.jQuery);\n        </script>\n\n        ' #NEWLINE# js = ( js % { #NEWLINE# #INDENT# 'chainfield' : chained_field , #NEWLINE# 'url' : url , #NEWLINE# 'id' : attrs [ 'id' ] , #NEWLINE# 'value' : ( 'undefined' if ( ( value is None ) or ( value == '' ) ) else value ) , #NEWLINE# 'auto_choose' : auto_choose , #NEWLINE# 'empty_label' : escape ( empty_label ) , #NEWLINE# #UNINDENT# } ) #NEWLINE# final_choices = [ ] #NEWLINE# if value : #NEWLINE# #INDENT# available_choices = self . _get_available_choices ( self . queryset , value ) #NEWLINE# for choice in available_choices : #NEWLINE# #INDENT# final_choices . append ( ( choice . pk , force_text ( choice ) ) ) #NEWLINE# #UNINDENT# #UNINDENT# if ( len ( final_choices ) > 1 ) : #NEWLINE# #INDENT# final_choices = ( [ ( '' , empty_label ) ] + final_choices ) #NEWLINE# #UNINDENT# if self . show_all : #NEWLINE# #INDENT# final_choices . append ( ( '' , empty_label ) ) #NEWLINE# self . choices = list ( self . choices ) #NEWLINE# self . choices . sort ( key = ( lambda x : unicode_sorter ( x [ 1 ] ) ) ) #NEWLINE# for ch in self . choices : #NEWLINE# #INDENT# if ( ch not in choice ) : #NEWLINE# #INDENT# final_choices . append ( ch ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# self . choices = ( ) #NEWLINE# final_attrs = self . build_attrs ( attrs , name = name ) #NEWLINE# if ( 'class' in final_attrs ) : #NEWLINE# #INDENT# final_attrs [ 'class' ] += ' chained' #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# final_attrs [ 'class' ] = 'chained' #NEWLINE# #UNINDENT# output = js #NEWLINE# output += super ( ChainedSelect , self ) . render ( name , value , final_attrs , choices = final_choices ) #NEWLINE# return mark_safe ( output )