Ticket #14765: little_tweak_of_tempate_rendering2.patch

File little_tweak_of_tempate_rendering2.patch, 2.3 KB (added by traff, 4 years ago)

patch improved

  • django/template/base.py

     
    735735                nodes.extend(nodelist.get_nodes_by_type(nodetype))
    736736        return nodes
    737737
     738def mark_safe_unicode(bits):
     739    return mark_safe(''.join([force_unicode(b) for b in bits]))
     740
    738741class NodeList(list):
    739742    # Set to True the first time a non-TextNode is inserted by
    740743    # extend_nodelist().
     
    747750                bits.append(self.render_node(node, context))
    748751            else:
    749752                bits.append(node)
    750         return mark_safe(''.join([force_unicode(b) for b in bits]))
     753        return mark_safe_unicode(bits)
    751754
    752755    def get_nodes_by_type(self, nodetype):
    753756        "Return a list of all nodes of the given type"
  • django/template/defaulttags.py

     
    55from datetime import datetime
    66from itertools import groupby, cycle as itertools_cycle
    77
    8 from django.template.base import Node, NodeList, Template, Context, Variable
     8from django.template.base import Node, NodeList, Template, Context, Variable, mark_safe_unicode
    99from django.template.base import TemplateSyntaxError, VariableDoesNotExist, BLOCK_TAG_START, BLOCK_TAG_END, VARIABLE_TAG_START, VARIABLE_TAG_END, SINGLE_BRACE_START, SINGLE_BRACE_END, COMMENT_TAG_START, COMMENT_TAG_END
    1010from django.template.base import get_library, Library, InvalidTemplateLibrary
    1111from django.template.smartif import IfParser, Literal
     
    194194        if len_values < 1:
    195195            context.pop()
    196196            return self.nodelist_empty.render(context)
    197         nodelist = NodeList()
     197        nodelist = []
    198198        if self.is_reversed:
    199199            values = reversed(values)
    200200        unpack = len(self.loopvars) > 1
     
    235235                # context.
    236236                context.pop()
    237237        context.pop()
    238         return nodelist.render(context)
     238        return mark_safe_unicode(nodelist)
    239239
    240240class IfChangedNode(Node):
    241241    child_nodelists = ('nodelist_true', 'nodelist_false')
Back to Top