#NEWLINE# def render( self , context ) : #NEWLINE# #INDENT# if ( 'forloop' in context ) : #NEWLINE# #INDENT# parentloop = context [ 'forloop' ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# parentloop = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# context . push ( ) #NEWLINE# try : #NEWLINE# #INDENT# values = self . sequence . resolve ( context , True ) #NEWLINE# #UNINDENT# except VariableDoesNotExist : #NEWLINE# #INDENT# values = [ ] #NEWLINE# #UNINDENT# if ( values is None ) : #NEWLINE# #INDENT# values = [ ] #NEWLINE# #UNINDENT# if ( not hasattr ( values , '__len__' ) ) : #NEWLINE# #INDENT# values = list ( values ) #NEWLINE# #UNINDENT# len_values = len ( values ) #NEWLINE# if ( len_values < 1 ) : #NEWLINE# #INDENT# context . pop ( ) #NEWLINE# return self . nodelist_empty . render ( context ) #NEWLINE# #UNINDENT# nodelist = NodeList ( ) #NEWLINE# if self . is_reversed : #NEWLINE# #INDENT# values = reversed ( values ) #NEWLINE# #UNINDENT# unpack = ( len ( self . loopvars ) > 1 ) #NEWLINE# loop_dict = context [ 'forloop' ] = { #NEWLINE# #INDENT# 'parentloop' : parentloop , #NEWLINE# #UNINDENT# } #NEWLINE# for ( i , item ) in enumerate ( values ) : #NEWLINE# #INDENT# loop_dict [ 'counter0' ] = i #NEWLINE# loop_dict [ 'counter' ] = ( i + 1 ) #NEWLINE# loop_dict [ 'revcounter' ] = ( len_values - i ) #NEWLINE# loop_dict [ 'revcounter0' ] = ( ( len_values - i ) - 1 ) #NEWLINE# loop_dict [ 'first' ] = ( i == 0 ) #NEWLINE# loop_dict [ 'last' ] = ( i == ( len_values - 1 ) ) #NEWLINE# pop_context = False #NEWLINE# if unpack : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# unpacked_vars = dict ( zip ( item . loopvars , item ) ) #NEWLINE# #UNINDENT# except TypeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# pop_context = True #NEWLINE# context . update ( unpacked_vars ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# context [ self . loopvars [ 0 ] ] = item #NEWLINE# #UNINDENT# if settings . TEMPLATE_DEBUG : #NEWLINE# #INDENT# for node in self . nodelist_loop : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# nodelist . append ( node . render ( context ) ) #NEWLINE# #UNINDENT# except Exception as e : #NEWLINE# #INDENT# if ( not hasattr ( e , 'django_template_source' ) ) : #NEWLINE# #INDENT# e . django_template_source = node . source #NEWLINE# #UNINDENT# raise #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# for node in self . nodelist_loop : #NEWLINE# #INDENT# nodelist . append ( node . render ( context ) ) #NEWLINE# #UNINDENT# #UNINDENT# if pop_context : #NEWLINE# #INDENT# context . pop ( ) #NEWLINE# #UNINDENT# #UNINDENT# context . pop ( ) #NEWLINE# return nodelist . render ( context )