diff --git a/ietf/idtracker/templatetags/myifchanged.py b/ietf/idtracker/templatetags/myifchanged.py new file mode 100644 index 000000000..e3d2ede9a --- /dev/null +++ b/ietf/idtracker/templatetags/myifchanged.py @@ -0,0 +1,85 @@ +"""A copy of the IfChanged standard node, updated with +SmileyChris's patch in http://code.djangoproject.com/ticket/4534 +and with the context push removed.""" + + +from django.template import Node, NodeList, resolve_variable +from django.template import VariableDoesNotExist +from django.template import Library +from django.conf import settings +import sys + +register = Library() + +class MyIfChangedNode(Node): + def __init__(self, nodelist_true, nodelist_false, *varlist): + self.nodelist_true, self.nodelist_false = nodelist_true, nodelist_false + self._last_seen = None + self._varlist = varlist + + def render(self, context): + if context.has_key('forloop') and context['forloop']['first']: + self._last_seen = None + try: + if self._varlist: + # Consider multiple parameters. + # This automatically behaves like a OR evaluation of the multiple variables. + compare_to = [resolve_variable(var, context) for var in self._varlist] + else: + compare_to = self.nodelist_true.render(context) + except VariableDoesNotExist: + compare_to = None + + if compare_to != self._last_seen: + firstloop = (self._last_seen == None) + self._last_seen = compare_to + #context.push() + #context['ifchanged'] = {'firstloop': firstloop} + content = self.nodelist_true.render(context) + #context.pop() + return content + else: + if self.nodelist_false: + return self.nodelist_false.render(context) + else: + return '' + +#@register.tag +def myifchanged(parser, token): + """ + Check if a value has changed from the last iteration of a loop. + + The 'myifchanged' block tag is used within a loop. It has two possible uses. + + 1. Checks its own rendered contents against its previous state and only + displays the content if it has changed. For example, this displays a list of + days, only displaying the month if it changes:: + +