Ticket #4565: template-iter-render-r3369.patch
File template-iter-render-r3369.patch, 38.3 KB (added by , 17 years ago) |
---|
-
django/contrib/admin/templatetags/admin_modify.py
=== modified file 'django/contrib/admin/templatetags/admin_modify.py'
94 94 return cls.nodelists[klass] 95 95 get_nodelist = classmethod(get_nodelist) 96 96 97 def render(self, context):97 def iter_render(self, context): 98 98 bound_field = template.resolve_variable(self.bound_field_var, context) 99 99 100 100 context.push() 101 101 context['bound_field'] = bound_field 102 102 103 output = self.get_nodelist(bound_field.field.__class__).render(context) 103 for chunk in self.get_nodelist(bound_field.field.__class__).iter_render(context): 104 yield chunk 104 105 context.pop() 105 return output106 106 107 107 class FieldWrapper(object): 108 108 def __init__(self, field ): … … 157 157 def __init__(self, rel_var): 158 158 self.rel_var = rel_var 159 159 160 def render(self, context):160 def iter_render(self, context): 161 161 relation = template.resolve_variable(self.rel_var, context) 162 162 context.push() 163 163 if relation.field.rel.edit_inline == models.TABULAR: … … 169 169 original = context.get('original', None) 170 170 bound_related_object = relation.bind(context['form'], original, bound_related_object_class) 171 171 context['bound_related_object'] = bound_related_object 172 t = loader.get_template(bound_related_object.template_name())173 output = t.render(context)172 for chunk in loader.get_template(bound_related_object.template_name()).iter_render(context): 173 yield chunk 174 174 context.pop() 175 return output176 175 177 176 def output_all(form_fields): 178 177 return ''.join([str(f) for f in form_fields]) -
django/contrib/admin/templatetags/adminapplist.py
=== modified file 'django/contrib/admin/templatetags/adminapplist.py'
7 7 def __init__(self, varname): 8 8 self.varname = varname 9 9 10 def render(self, context):10 def iter_render(self, context): 11 11 from django.db import models 12 12 from django.utils.text import capfirst 13 13 app_list = [] … … 54 54 'models': model_list, 55 55 }) 56 56 context[self.varname] = app_list 57 return ''57 return () 58 58 59 59 def get_admin_app_list(parser, token): 60 60 """ -
django/contrib/admin/templatetags/log.py
=== modified file 'django/contrib/admin/templatetags/log.py'
10 10 def __repr__(self): 11 11 return "<GetAdminLog Node>" 12 12 13 def render(self, context):13 def iter_render(self, context): 14 14 if self.user is None: 15 15 context[self.varname] = LogEntry.objects.all().select_related()[:self.limit] 16 16 else: 17 17 if not self.user.isdigit(): 18 18 self.user = context[self.user].id 19 19 context[self.varname] = LogEntry.objects.filter(user__id__exact=self.user).select_related()[:self.limit] 20 return ''20 return () 21 21 22 22 class DoGetAdminLog: 23 23 """ -
django/contrib/comments/templatetags/comments.py
=== modified file 'django/contrib/comments/templatetags/comments.py'
24 24 self.photo_options, self.rating_options = photo_options, rating_options 25 25 self.is_public = is_public 26 26 27 def render(self, context):27 def iter_render(self, context): 28 28 from django.conf import settings 29 29 from django.utils.text import normalize_newlines 30 30 import base64 … … 33 33 try: 34 34 self.obj_id = template.resolve_variable(self.obj_id_lookup_var, context) 35 35 except template.VariableDoesNotExist: 36 return ''36 return 37 37 # Validate that this object ID is valid for this content-type. 38 38 # We only have to do this validation if obj_id_lookup_var is provided, 39 39 # because do_comment_form() validates hard-coded object IDs. … … 67 67 context['hash'] = Comment.objects.get_security_hash(context['options'], context['photo_options'], context['rating_options'], context['target']) 68 68 context['logout_url'] = settings.LOGOUT_URL 69 69 default_form = loader.get_template(COMMENT_FORM) 70 output = default_form.render(context) 70 for chunk in default_form.iter_render(context): 71 yield chunk 71 72 context.pop() 72 return output73 73 74 74 class CommentCountNode(template.Node): 75 75 def __init__(self, package, module, context_var_name, obj_id, var_name, free): … … 77 77 self.context_var_name, self.obj_id = context_var_name, obj_id 78 78 self.var_name, self.free = var_name, free 79 79 80 def render(self, context):80 def iter_render(self, context): 81 81 from django.conf import settings 82 82 manager = self.free and FreeComment.objects or Comment.objects 83 83 if self.context_var_name is not None: … … 86 86 content_type__app_label__exact=self.package, 87 87 content_type__model__exact=self.module, site__id__exact=settings.SITE_ID).count() 88 88 context[self.var_name] = comment_count 89 return ''89 return () 90 90 91 91 class CommentListNode(template.Node): 92 92 def __init__(self, package, module, context_var_name, obj_id, var_name, free, ordering, extra_kwargs=None): … … 96 96 self.ordering = ordering 97 97 self.extra_kwargs = extra_kwargs or {} 98 98 99 def render(self, context):99 def iter_render(self, context): 100 100 from django.conf import settings 101 101 get_list_function = self.free and FreeComment.objects.filter or Comment.objects.get_list_with_karma 102 102 if self.context_var_name is not None: 103 103 try: 104 104 self.obj_id = template.resolve_variable(self.context_var_name, context) 105 105 except template.VariableDoesNotExist: 106 return ''106 return () 107 107 kwargs = { 108 108 'object_id__exact': self.obj_id, 109 109 'content_type__app_label__exact': self.package, … … 127 127 comment_list = [c for c in comment_list if not c.is_hidden or (user_id == c.user_id)] 128 128 129 129 context[self.var_name] = comment_list 130 return ''130 return () 131 131 132 132 class DoCommentForm: 133 133 """ -
django/core/servers/basehttp.py
=== modified file 'django/core/servers/basehttp.py'
309 309 """ 310 310 if not self.result_is_file() and not self.sendfile(): 311 311 for data in self.result: 312 self.write(data )312 self.write(data, False) 313 313 self.finish_content() 314 314 self.close() 315 315 … … 377 377 else: 378 378 self._write('Status: %s\r\n' % self.status) 379 379 380 def write(self, data ):380 def write(self, data, flush=True): 381 381 """'write()' callable as specified by PEP 333""" 382 382 383 383 assert type(data) is StringType,"write() argument must be string" … … 394 394 395 395 # XXX check Content-Length and truncate if too many bytes written? 396 396 self._write(data) 397 self._flush() 397 if flush: 398 self._flush() 398 399 399 400 def sendfile(self): 400 401 """Platform-specific file transmission … … 421 422 if not self.headers_sent: 422 423 self.headers['Content-Length'] = "0" 423 424 self.send_headers() 424 else:425 pass # XXX check if content-length was too short?426 425 427 426 def close(self): 428 427 try: -
django/http/__init__.py
=== modified file 'django/http/__init__.py'
231 231 content = property(_get_content, _set_content) 232 232 233 233 def __iter__(self): 234 self._iterator = self._container.__iter__() 235 return self 236 237 def next(self): 238 chunk = self._iterator.next() 239 if isinstance(chunk, unicode): 240 chunk = chunk.encode(self._charset) 241 return chunk 234 for chunk in self._container: 235 if isinstance(chunk, unicode): 236 chunk = chunk.encode(self._charset) 237 yield chunk 242 238 243 239 def close(self): 244 240 if hasattr(self._container, 'close'): -
django/oldforms/__init__.py
=== modified file 'django/oldforms/__init__.py'
309 309 return data 310 310 html2python = staticmethod(html2python) 311 311 312 def iter_render(self, data): 313 # this even needed? 314 return (self.render(data),) 315 312 316 def render(self, data): 313 317 raise NotImplementedError 314 318 -
django/shortcuts/__init__.py
=== modified file 'django/shortcuts/__init__.py'
7 7 from django.db.models.manager import Manager 8 8 9 9 def render_to_response(*args, **kwargs): 10 return HttpResponse(loader.render_to_ string(*args, **kwargs))10 return HttpResponse(loader.render_to_iter(*args, **kwargs)) 11 11 load_and_render = render_to_response # For backwards compatibility. 12 12 13 13 def get_object_or_404(klass, *args, **kwargs): -
django/template/__init__.py
=== modified file 'django/template/__init__.py'
167 167 for subnode in node: 168 168 yield subnode 169 169 170 def render(self, context):170 def iter_render(self, context): 171 171 "Display stage -- can be called many times" 172 return self.nodelist.render(context) 172 return self.nodelist.iter_render(context) 173 174 def render(self, context): 175 return ''.join(self.iter_render(context)) 173 176 174 177 def compile_string(template_string, origin): 175 178 "Compiles template_string into NodeList ready for rendering" … … 699 702 return current 700 703 701 704 class Node(object): 705 def iter_render(self, context): 706 return (self.render(context),) 707 702 708 def render(self, context): 703 709 "Return the node rendered as a string" 704 pass710 return ''.join(self.iter_render(context)) 705 711 706 712 def __iter__(self): 707 713 yield self … … 716 722 return nodes 717 723 718 724 class NodeList(list): 725 719 726 def render(self, context): 720 bits = [] 727 return ''.join(self.iter_render(context)) 728 729 def iter_render(self, context): 721 730 for node in self: 722 if isinstance(node, Node): 723 bits.append(self.render_node(node, context)) 724 else: 725 bits.append(node) 726 return ''.join(bits) 731 for chunk in node.iter_render(context): 732 yield chunk 727 733 728 734 def get_nodes_by_type(self, nodetype): 729 735 "Return a list of all nodes of the given type" … … 732 738 nodes.extend(node.get_nodes_by_type(nodetype)) 733 739 return nodes 734 740 735 def render_node(self, node, context):736 return(node.render(context))737 741 738 742 class DebugNodeList(NodeList): 739 def render_node(self, node, context): 740 try: 741 result = node.render(context) 742 except TemplateSyntaxError, e: 743 if not hasattr(e, 'source'): 744 e.source = node.source 745 raise 746 except Exception, e: 747 from sys import exc_info 748 wrapped = TemplateSyntaxError('Caught an exception while rendering: %s' % e) 749 wrapped.source = node.source 750 wrapped.exc_info = exc_info() 751 raise wrapped 752 return result 743 744 def iter_render(self, node, context): 745 for node in self: 746 if not isinstance(node, Node): 747 yield node 748 continue 749 try: 750 for chunk in node.iter_render(context): 751 yield chunk 752 except TemplateSyntaxError, e: 753 if not hasattr(e, 'source'): 754 e.source = node.source 755 raise 756 except Exception, e: 757 from sys import exc_info 758 wrapped = TemplateSyntaxError('Caught an exception while rendering: %s' % e) 759 wrapped.source = node.source 760 wrapped.exc_info = exc_info() 761 raise wrapped 753 762 754 763 class TextNode(Node): 755 764 def __init__(self, s): … … 758 767 def __repr__(self): 759 768 return "<Text Node: '%s'>" % self.s[:25] 760 769 770 def iter_render(self, context): 771 return (self.s,) 772 761 773 def render(self, context): 762 774 return self.s 763 775 … … 781 793 else: 782 794 return output 783 795 796 def iter_render(self, context): 797 return (self.render(context),) 798 784 799 def render(self, context): 785 800 output = self.filter_expression.resolve(context) 786 801 return self.encode_output(output) 787 802 788 803 class DebugVariableNode(VariableNode): 804 789 805 def render(self, context): 790 806 try: 791 807 output = self.filter_expression.resolve(context) … … 869 885 def __init__(self, vars_to_resolve): 870 886 self.vars_to_resolve = vars_to_resolve 871 887 888 def iter_render(self, context): 889 return (self.render(context),) 890 872 891 def render(self, context): 873 892 resolved_vars = [resolve_variable(var, context) for var in self.vars_to_resolve] 874 893 return func(*resolved_vars) … … 891 910 def __init__(self, vars_to_resolve): 892 911 self.vars_to_resolve = vars_to_resolve 893 912 894 def render(self, context):913 def iter_render(self, context): 895 914 resolved_vars = [resolve_variable(var, context) for var in self.vars_to_resolve] 896 915 if takes_context: 897 916 args = [context] + resolved_vars … … 907 926 else: 908 927 t = get_template(file_name) 909 928 self.nodelist = t.nodelist 910 return self.nodelist. render(context_class(dict))929 return self.nodelist.iter_render(context_class(dict)) 911 930 912 931 compile_func = curry(generic_tag_compiler, params, defaults, getattr(func, "_decorated_function", func).__name__, InclusionNode) 913 932 compile_func.__doc__ = func.__doc__ -
django/template/defaulttags.py
=== modified file 'django/template/defaulttags.py'
14 14 for index in xrange(len(data)-1, -1, -1): 15 15 yield data[index] 16 16 17 18 17 register = Library() 19 18 20 19 class CommentNode(Node): 21 def render(self, context):22 return ''20 def iter_render(self, context): 21 return () 23 22 24 23 class CycleNode(Node): 25 24 def __init__(self, cyclevars, variable_name=None): … … 28 27 self.counter = -1 29 28 self.variable_name = variable_name 30 29 30 def iter_render(self, context): 31 return (self.render(context),) 32 31 33 def render(self, context): 32 34 self.counter += 1 33 35 value = self.cyclevars[self.counter % self.cyclevars_len] … … 36 38 return value 37 39 38 40 class DebugNode(Node): 39 def render(self, context):41 def iter_render(self, context): 40 42 from pprint import pformat 41 output = [pformat(val) for val in context]42 output.append('\n\n')43 output.append(pformat(sys.modules))44 return ''.join(output)43 for val in context: 44 yield pformat(val) 45 yield "\n\n" 46 yield pformat(sys.modules) 45 47 46 48 class FilterNode(Node): 47 49 def __init__(self, filter_expr, nodelist): 48 50 self.filter_expr, self.nodelist = filter_expr, nodelist 49 51 50 def render(self, context):52 def iter_render(self, context): 51 53 output = self.nodelist.render(context) 52 54 # apply filters 53 55 context.update({'var': output}) 54 56 filtered = self.filter_expr.resolve(context) 55 57 context.pop() 56 return filtered58 return (filtered,) 57 59 58 60 class FirstOfNode(Node): 59 61 def __init__(self, vars): 60 62 self.vars = vars 61 63 64 def iter_render(self, context): 65 return (self.render(context),) 66 62 67 def render(self, context): 63 68 for var in self.vars: 64 69 try: … … 94 99 nodes.extend(self.nodelist_loop.get_nodes_by_type(nodetype)) 95 100 return nodes 96 101 97 def render(self, context): 98 nodelist = NodeList() 102 def iter_render(self, context): 99 103 if 'forloop' in context: 100 104 parentloop = context['forloop'] 101 105 else: … … 103 107 context.push() 104 108 try: 105 109 values = self.sequence.resolve(context, True) 110 if values is None: 111 values = () 112 elif not hasattr(values, '__len__'): 113 values = list(values) 106 114 except VariableDoesNotExist: 107 values = [] 108 if values is None: 109 values = [] 110 if not hasattr(values, '__len__'): 111 values = list(values) 115 values = () 112 116 len_values = len(values) 113 117 if self.reversed: 114 118 values = reversed(values) … … 131 135 context.update(dict(zip(self.loopvars, item))) 132 136 else: 133 137 context[self.loopvars[0]] = item 138 # we inline this to avoid the overhead since fornode is pretty common. 134 139 for node in self.nodelist_loop: 135 nodelist.append(node.render(context)) 140 for chunk in node.iter_render(context): 141 yield chunk 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 146 151 class IfChangedNode(Node): 147 152 def __init__(self, nodelist, *varlist): … … 149 154 self._last_seen = None 150 155 self._varlist = varlist 151 156 152 def render(self, context):157 def iter_render(self, context): 153 158 if 'forloop' in context and context['forloop']['first']: 154 159 self._last_seen = None 155 160 try: … … 167 172 self._last_seen = compare_to 168 173 context.push() 169 174 context['ifchanged'] = {'firstloop': firstloop} 170 content = self.nodelist.render(context) 175 for chunk in self.nodelist.iter_render(context): 176 yield chunk 171 177 context.pop() 172 return content173 else:174 return ''175 178 176 179 class IfEqualNode(Node): 177 180 def __init__(self, var1, var2, nodelist_true, nodelist_false, negate): … … 182 185 def __repr__(self): 183 186 return "<IfEqualNode>" 184 187 185 def render(self, context):188 def iter_render(self, context): 186 189 try: 187 190 val1 = resolve_variable(self.var1, context) 188 191 except VariableDoesNotExist: … … 192 195 except VariableDoesNotExist: 193 196 val2 = None 194 197 if (self.negate and val1 != val2) or (not self.negate and val1 == val2): 195 return self.nodelist_true. render(context)196 return self.nodelist_false. render(context)198 return self.nodelist_true.iter_render(context) 199 return self.nodelist_false.iter_render(context) 197 200 198 201 class IfNode(Node): 199 202 def __init__(self, bool_exprs, nodelist_true, nodelist_false, link_type): … … 218 221 nodes.extend(self.nodelist_false.get_nodes_by_type(nodetype)) 219 222 return nodes 220 223 221 def render(self, context):224 def iter_render(self, context): 222 225 if self.link_type == IfNode.LinkTypes.or_: 223 226 for ifnot, bool_expr in self.bool_exprs: 224 227 try: … … 226 229 except VariableDoesNotExist: 227 230 value = None 228 231 if (value and not ifnot) or (ifnot and not value): 229 return self.nodelist_true. render(context)230 return self.nodelist_false. render(context)232 return self.nodelist_true.iter_render(context) 233 return self.nodelist_false.iter_render(context) 231 234 else: 232 235 for ifnot, bool_expr in self.bool_exprs: 233 236 try: … … 235 238 except VariableDoesNotExist: 236 239 value = None 237 240 if not ((value and not ifnot) or (ifnot and not value)): 238 return self.nodelist_false. render(context)239 return self.nodelist_true. render(context)241 return self.nodelist_false.iter_render(context) 242 return self.nodelist_true.iter_render(context) 240 243 241 244 class LinkTypes: 242 245 and_ = 0, … … 247 250 self.target, self.expression = target, expression 248 251 self.var_name = var_name 249 252 250 def render(self, context):253 def iter_render(self, context): 251 254 obj_list = self.target.resolve(context, True) 252 255 if obj_list == None: # target_var wasn't found in context; fail silently 253 256 context[self.var_name] = [] 254 return ''257 return () 255 258 output = [] # list of dictionaries in the format {'grouper': 'key', 'list': [list of contents]} 256 259 for obj in obj_list: 257 260 grouper = self.expression.resolve(obj, True) … … 261 264 else: 262 265 output.append({'grouper': grouper, 'list': [obj]}) 263 266 context[self.var_name] = output 264 return ''267 return () 265 268 266 269 def include_is_allowed(filepath): 267 270 for root in settings.ALLOWED_INCLUDE_ROOTS: … … 273 276 def __init__(self, filepath, parsed): 274 277 self.filepath, self.parsed = filepath, parsed 275 278 276 def render(self, context):279 def iter_render(self, context): 277 280 if not include_is_allowed(self.filepath): 278 281 if settings.DEBUG: 279 return "[Didn't have permission to include file]"282 return ("[Didn't have permission to include file]",) 280 283 else: 281 284 return '' # Fail silently for invalid includes. 282 285 try: … … 287 290 output = '' 288 291 if self.parsed: 289 292 try: 290 t = Template(output, name=self.filepath) 291 return t.render(context) 293 return Template(output, name=self.filepath).iter_render(context) 292 294 except TemplateSyntaxError, e: 293 295 if settings.DEBUG: 294 296 return "[Included template had syntax error: %s]" % e 295 297 else: 296 298 return '' # Fail silently for invalid included templates. 297 return output299 return (output,) 298 300 299 301 class LoadNode(Node): 300 def render(self, context):301 return ''302 def iter_render(self, context): 303 return () 302 304 303 305 class NowNode(Node): 304 306 def __init__(self, format_string): 305 307 self.format_string = format_string 306 308 309 def iter_render(self, context): 310 return (self.render(context),) 311 307 312 def render(self, context): 308 313 from datetime import datetime 309 314 from django.utils.dateformat import DateFormat … … 332 337 def __init__(self, tagtype): 333 338 self.tagtype = tagtype 334 339 340 def iter_render(self, context): 341 return (self.render(context),) 342 335 343 def render(self, context): 336 344 return self.mapping.get(self.tagtype, '') 337 345 … … 341 349 self.args = args 342 350 self.kwargs = kwargs 343 351 344 def render(self, context):352 def iter_render(self, context): 345 353 from django.core.urlresolvers import reverse, NoReverseMatch 346 354 args = [arg.resolve(context) for arg in self.args] 347 355 kwargs = dict([(k, v.resolve(context)) for k, v in self.kwargs.items()]) 348 356 try: 349 return reverse(self.view_name, args=args, kwargs=kwargs)357 return (reverse(self.view_name, args=args, kwargs=kwargs),) 350 358 except NoReverseMatch: 351 359 try: 352 360 project_name = settings.SETTINGS_MODULE.split('.')[0] 353 361 return reverse(project_name + '.' + self.view_name, args=args, kwargs=kwargs) 354 362 except NoReverseMatch: 355 return ''363 return () 356 364 357 365 class WidthRatioNode(Node): 358 366 def __init__(self, val_expr, max_expr, max_width): … … 360 368 self.max_expr = max_expr 361 369 self.max_width = max_width 362 370 371 def iter_render(self, context): 372 return (self.render(context),) 373 363 374 def render(self, context): 364 375 try: 365 376 value = self.val_expr.resolve(context) … … 383 394 def __repr__(self): 384 395 return "<WithNode>" 385 396 386 def render(self, context):397 def iter_render(self, context): 387 398 val = self.var.resolve(context) 388 399 context.push() 389 400 context[self.name] = val 390 output = self.nodelist.render(context) 401 for chunk in self.nodelist.iter_render(context): 402 yield chunk 391 403 context.pop() 392 return output393 404 394 405 #@register.tag 395 406 def comment(parser, token): -
django/template/loader.py
=== modified file 'django/template/loader.py'
87 87 """ 88 88 return Template(source, origin, name) 89 89 90 def render_to_string(template_name, dictionary=None, context_instance=None): 91 """ 92 Loads the given template_name and renders it with the given dictionary as 93 context. The template_name may be a string to load a single template using 94 get_template, or it may be a tuple to use select_template to find one of 95 the templates in the list. Returns a string. 96 """ 97 dictionary = dictionary or {} 90 def _render_setup(template_name, dictionary=None, context_instance=None): 91 """ 92 common setup code for render_to_string and render_to_iter 93 """ 94 if dictionary is None: 95 dictionary = {} 98 96 if isinstance(template_name, (list, tuple)): 99 97 t = select_template(template_name) 100 98 else: … … 103 101 context_instance.update(dictionary) 104 102 else: 105 103 context_instance = Context(dictionary) 106 return t.render(context_instance) 104 return t, context_instance 105 106 def render_to_string(template_name, dictionary=None, context_instance=None): 107 """ 108 Loads the given template_name and renders it with the given dictionary as 109 context. The template_name may be a string to load a single template using 110 get_template, or it may be a tuple to use select_template to find one of 111 the templates in the list. Returns a string. 112 """ 113 t, c = _render_setup(template_name, dictionary=dictionary, context_instance=context_instance) 114 return t.render(c) 115 116 def render_to_iter(template_name, dictionary=None, context_instance=None): 117 """ 118 Loads the given template_name and renders it with the given dictionary as 119 context. The template_name may be a string to load a single template using 120 get_template, or it may be a tuple to use select_template to find one of 121 the templates in the list. Returns a string. 122 """ 123 t, c = _render_setup(template_name, dictionary=dictionary, context_instance=context_instance) 124 return t.iter_render(c) 125 107 126 108 127 def select_template(template_name_list): 109 128 "Given a list of template names, returns the first that can be loaded." -
django/template/loader_tags.py
=== modified file 'django/template/loader_tags.py'
15 15 def __repr__(self): 16 16 return "<Block Node: %s. Contents: %r>" % (self.name, self.nodelist) 17 17 18 def render(self, context):18 def iter_render(self, context): 19 19 context.push() 20 20 # Save context in case of block.super(). 21 21 self.context = context 22 22 context['block'] = self 23 result = self.nodelist.render(context) 23 for chunk in self.nodelist.iter_render(context): 24 yield chunk 24 25 context.pop() 25 return result26 26 27 27 def super(self): 28 28 if self.parent: … … 59 59 else: 60 60 return get_template_from_string(source, origin, parent) 61 61 62 def render(self, context):62 def iter_render(self, context): 63 63 compiled_parent = self.get_parent(context) 64 64 parent_is_child = isinstance(compiled_parent.nodelist[0], ExtendsNode) 65 65 parent_blocks = dict([(n.name, n) for n in compiled_parent.nodelist.get_nodes_by_type(BlockNode)]) … … 79 79 parent_block.parent = block_node.parent 80 80 parent_block.add_parent(parent_block.nodelist) 81 81 parent_block.nodelist = block_node.nodelist 82 return compiled_parent. render(context)82 return compiled_parent.iter_render(context) 83 83 84 84 class ConstantIncludeNode(Node): 85 85 def __init__(self, template_path): … … 91 91 raise 92 92 self.template = None 93 93 94 def render(self, context):94 def iter_render(self, context): 95 95 if self.template: 96 return self.template.render(context) 97 else: 98 return '' 96 return self.template.iter_render(context) 97 return () 99 98 100 99 class IncludeNode(Node): 101 100 def __init__(self, template_name): 102 101 self.template_name = template_name 103 102 104 def render(self, context):103 def iter_render(self, context): 105 104 try: 106 105 template_name = resolve_variable(self.template_name, context) 107 106 t = get_template(template_name) 108 return t. render(context)107 return t.iter_render(context) 109 108 except TemplateSyntaxError, e: 110 109 if settings.TEMPLATE_DEBUG: 111 110 raise 112 return ''111 return () 113 112 except: 114 return ''# Fail silently for invalid included templates.113 return () # Fail silently for invalid included templates. 115 114 116 115 def do_block(parser, token): 117 116 """ -
django/test/utils.py
=== modified file 'django/test/utils.py'
17 17 """ 18 18 dispatcher.send(signal=signals.template_rendered, sender=self, template=self, context=context) 19 19 return self.nodelist.render(context) 20 21 def instrumented_test_iter_render(self, context): 22 """An instrumented Template iter_render method, providing a signal 23 that can be intercepted by the test system Client 24 25 """ 26 for chunk in self.nodelist.iter_render(context): 27 yield chunk 28 dispatcher.send(signal=signals.template_rendered, sender=self, template=self, context=context) 20 29 21 30 class TestSMTPConnection(object): 22 31 """A substitute SMTP connection for use during test sessions. … … 44 53 45 54 """ 46 55 Template.original_render = Template.render 56 Template.original_iter_render = Template.iter_render 47 57 Template.render = instrumented_test_render 58 Template.iter_render = instrumented_test_render 48 59 49 60 mail.original_SMTPConnection = mail.SMTPConnection 50 61 mail.SMTPConnection = TestSMTPConnection … … 59 70 60 71 """ 61 72 Template.render = Template.original_render 62 del Template.original_render 73 Template.iter_render = Template.original_iter_render 74 del Template.original_render, Template.original_iter_render 63 75 64 76 mail.SMTPConnection = mail.original_SMTPConnection 65 77 del mail.original_SMTPConnection -
django/views/debug.py
=== modified file 'django/views/debug.py'
137 137 'template_does_not_exist': template_does_not_exist, 138 138 'loader_debug_info': loader_debug_info, 139 139 }) 140 return HttpResponseServerError(t. render(c), mimetype='text/html')140 return HttpResponseServerError(t.iter_render(c), mimetype='text/html') 141 141 142 142 def technical_404_response(request, exception): 143 143 "Create a technical 404 error response. The exception should be the Http404." … … 160 160 'request_protocol': request.is_secure() and "https" or "http", 161 161 'settings': get_safe_settings(), 162 162 }) 163 return HttpResponseNotFound(t. render(c), mimetype='text/html')163 return HttpResponseNotFound(t.iter_render(c), mimetype='text/html') 164 164 165 165 def empty_urlconf(request): 166 166 "Create an empty URLconf 404 error response." … … 168 168 c = Context({ 169 169 'project_name': settings.SETTINGS_MODULE.split('.')[0] 170 170 }) 171 return HttpResponseNotFound(t. render(c), mimetype='text/html')171 return HttpResponseNotFound(t.iter_render(c), mimetype='text/html') 172 172 173 173 def _get_lines_from_file(filename, lineno, context_lines, loader=None, module_name=None): 174 174 """ -
django/views/defaults.py
=== modified file 'django/views/defaults.py'
76 76 The path of the requested URL (e.g., '/app/pages/bad_page/') 77 77 """ 78 78 t = loader.get_template(template_name) # You need to create a 404.html template. 79 return http.HttpResponseNotFound(t. render(RequestContext(request, {'request_path': request.path})))79 return http.HttpResponseNotFound(t.iter_render(RequestContext(request, {'request_path': request.path}))) 80 80 81 81 def server_error(request, template_name='500.html'): 82 82 """ … … 86 86 Context: None 87 87 """ 88 88 t = loader.get_template(template_name) # You need to create a 500.html template. 89 return http.HttpResponseServerError(t. render(Context({})))89 return http.HttpResponseServerError(t.iter_render(Context({}))) -
django/views/generic/create_update.py
=== modified file 'django/views/generic/create_update.py'
68 68 c[key] = value() 69 69 else: 70 70 c[key] = value 71 return HttpResponse(t. render(c))71 return HttpResponse(t.iter_render(c)) 72 72 73 73 def update_object(request, model, object_id=None, slug=None, 74 74 slug_field=None, template_name=None, template_loader=loader, … … 141 141 c[key] = value() 142 142 else: 143 143 c[key] = value 144 response = HttpResponse(t. render(c))144 response = HttpResponse(t.iter_render(c)) 145 145 populate_xheaders(request, response, model, getattr(object, object._meta.pk.attname)) 146 146 return response 147 147 … … 195 195 c[key] = value() 196 196 else: 197 197 c[key] = value 198 response = HttpResponse(t. render(c))198 response = HttpResponse(t.iter_render(c)) 199 199 populate_xheaders(request, response, model, getattr(object, object._meta.pk.attname)) 200 200 return response -
django/views/generic/date_based.py
=== modified file 'django/views/generic/date_based.py'
44 44 c[key] = value() 45 45 else: 46 46 c[key] = value 47 return HttpResponse(t. render(c), mimetype=mimetype)47 return HttpResponse(t.iter_render(c), mimetype=mimetype) 48 48 49 49 def archive_year(request, year, queryset, date_field, template_name=None, 50 50 template_loader=loader, extra_context=None, allow_empty=False, … … 92 92 c[key] = value() 93 93 else: 94 94 c[key] = value 95 return HttpResponse(t. render(c), mimetype=mimetype)95 return HttpResponse(t.iter_render(c), mimetype=mimetype) 96 96 97 97 def archive_month(request, year, month, queryset, date_field, 98 98 month_format='%b', template_name=None, template_loader=loader, … … 158 158 c[key] = value() 159 159 else: 160 160 c[key] = value 161 return HttpResponse(t. render(c), mimetype=mimetype)161 return HttpResponse(t.iter_render(c), mimetype=mimetype) 162 162 163 163 def archive_week(request, year, week, queryset, date_field, 164 164 template_name=None, template_loader=loader, … … 206 206 c[key] = value() 207 207 else: 208 208 c[key] = value 209 return HttpResponse(t. render(c), mimetype=mimetype)209 return HttpResponse(t.iter_render(c), mimetype=mimetype) 210 210 211 211 def archive_day(request, year, month, day, queryset, date_field, 212 212 month_format='%b', day_format='%d', template_name=None, … … 270 270 c[key] = value() 271 271 else: 272 272 c[key] = value 273 return HttpResponse(t. render(c), mimetype=mimetype)273 return HttpResponse(t.iter_render(c), mimetype=mimetype) 274 274 275 275 def archive_today(request, **kwargs): 276 276 """ … … 339 339 c[key] = value() 340 340 else: 341 341 c[key] = value 342 response = HttpResponse(t. render(c), mimetype=mimetype)342 response = HttpResponse(t.iter_render(c), mimetype=mimetype) 343 343 populate_xheaders(request, response, model, getattr(obj, obj._meta.pk.name)) 344 344 return response -
django/views/generic/list_detail.py
=== modified file 'django/views/generic/list_detail.py'
84 84 model = queryset.model 85 85 template_name = "%s/%s_list.html" % (model._meta.app_label, model._meta.object_name.lower()) 86 86 t = template_loader.get_template(template_name) 87 return HttpResponse(t. render(c), mimetype=mimetype)87 return HttpResponse(t.iter_render(c), mimetype=mimetype) 88 88 89 89 def object_detail(request, queryset, object_id=None, slug=None, 90 90 slug_field=None, template_name=None, template_name_field=None, … … 126 126 c[key] = value() 127 127 else: 128 128 c[key] = value 129 response = HttpResponse(t. render(c), mimetype=mimetype)129 response = HttpResponse(t.iter_render(c), mimetype=mimetype) 130 130 populate_xheaders(request, response, model, getattr(obj, obj._meta.pk.name)) 131 131 return response -
django/views/generic/simple.py
=== modified file 'django/views/generic/simple.py'
15 15 dictionary[key] = value 16 16 c = RequestContext(request, dictionary) 17 17 t = loader.get_template(template) 18 return HttpResponse(t. render(c), mimetype=mimetype)18 return HttpResponse(t.iter_render(c), mimetype=mimetype) 19 19 20 20 def redirect_to(request, url, **kwargs): 21 21 """ -
django/views/static.py
=== modified file 'django/views/static.py'
92 92 'directory' : path + '/', 93 93 'file_list' : files, 94 94 }) 95 return HttpResponse(t. render(c))95 return HttpResponse(t.iter_render(c)) 96 96 97 97 def was_modified_since(header=None, mtime=0, size=0): 98 98 """