Ticket #11730: ifequal-template-bug.diff

File ifequal-template-bug.diff, 1.5 KB (added by psmith, 15 years ago)

Patches defaulttags.py (ifchanged needs the same methods overridden)

  • django/template/defaulttags.py

     
    170170        self._varlist = varlist
    171171        self._id = str(id(self))
    172172
     173    def __iter__(self):
     174        for node in self.nodelist_true:
     175            yield node
     176        for node in self.nodelist_false:
     177            yield node
     178
     179    def get_nodes_by_type(self, nodetype):
     180        nodes = []
     181        if isinstance(self, nodetype):
     182            nodes.append(self)
     183        nodes.extend(self.nodelist_true.get_nodes_by_type(nodetype))
     184        nodes.extend(self.nodelist_false.get_nodes_by_type(nodetype))
     185        return nodes
     186
    173187    def render(self, context):
    174188        if 'forloop' in context and self._id not in context['forloop']:
    175189            self._last_seen = None
     
    202216    def __repr__(self):
    203217        return "<IfEqualNode>"
    204218
     219    def __iter__(self):
     220        for node in self.nodelist_true:
     221            yield node
     222        for node in self.nodelist_false:
     223            yield node
     224
     225    def get_nodes_by_type(self, nodetype):
     226        nodes = []
     227        if isinstance(self, nodetype):
     228            nodes.append(self)
     229        nodes.extend(self.nodelist_true.get_nodes_by_type(nodetype))
     230        nodes.extend(self.nodelist_false.get_nodes_by_type(nodetype))
     231        return nodes
     232
    205233    def render(self, context):
    206234        val1 = self.var1.resolve(context, True)
    207235        val2 = self.var2.resolve(context, True)
Back to Top