Ticket #5831: forloop.nodelist.patch
File forloop.nodelist.patch, 1.6 KB (added by , 17 years ago) |
---|
-
defaulttags.py
95 95 return nodes 96 96 97 97 def render(self, context): 98 nodelist = NodeList() 98 results = [] 99 99 100 if 'forloop' in context: 100 101 parentloop = context['forloop'] 101 102 else: 102 103 parentloop = {} 104 103 105 context.push() 106 104 107 try: 105 108 values = self.sequence.resolve(context, True) 106 109 except VariableDoesNotExist: … … 112 115 len_values = len(values) 113 116 if self.reversed: 114 117 values = reversed(values) 118 115 119 unpack = len(self.loopvars) > 1 120 116 121 for i, item in enumerate(values): 117 122 context['forloop'] = { 118 123 # shortcuts for current loop iteration number … … 131 136 context.update(dict(zip(self.loopvars, item))) 132 137 else: 133 138 context[self.loopvars[0]] = item 134 for node in self.nodelist_loop: 135 nodelist.append(node.render(context)) 139 140 results.append(self.nodelist_loop.render(context)) 141 136 142 if unpack: 137 143 # The loop variables were pushed on to the context so pop them 138 144 # off again. This is necessary because the tag lets the length … … 141 147 # context. 142 148 context.pop() 143 149 context.pop() 144 return nodelist.render(context)145 150 151 return ''.join(results) 152 146 153 class IfChangedNode(Node): 147 154 def __init__(self, nodelist, *varlist): 148 155 self.nodelist = nodelist