Changeset 7768 for django/branches/gis/django/template
- Timestamp:
- 06/26/08 10:11:55 (7 months ago)
- Files:
-
- django/branches/gis (modified) (1 prop)
- django/branches/gis/django/template/defaulttags.py (modified) (6 diffs)
- django/branches/gis/django/template/loader_tags.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/branches/gis
- Property svnmerge-integrated changed from /django/trunk:1-7641 to /django/trunk:1-7767
django/branches/gis/django/template/defaulttags.py
r7573 r7768 40 40 class CycleNode(Node): 41 41 def __init__(self, cyclevars, variable_name=None): 42 self.cycle_iter = itertools_cycle( cyclevars)42 self.cycle_iter = itertools_cycle([Variable(v) for v in cyclevars]) 43 43 self.variable_name = variable_name 44 44 45 45 def render(self, context): 46 value = self.cycle_iter.next() 47 value = Variable(value).resolve(context) 46 value = self.cycle_iter.next().resolve(context) 48 47 if self.variable_name: 49 48 context[self.variable_name] = value … … 163 162 self._last_seen = None 164 163 self._varlist = map(Variable, varlist) 165 166 def render(self, context): 167 if 'forloop' in context and context['forloop']['first']: 164 self._id = str(id(self)) 165 166 def render(self, context): 167 if 'forloop' in context and self._id not in context['forloop']: 168 168 self._last_seen = None 169 context['forloop'][self._id] = 1 169 170 try: 170 171 if self._varlist: … … 453 454 <tr class="{% cycle rowcolors %}">...</tr> 454 455 455 You can use any number of values, sep erated by spaces. Commas can also456 You can use any number of values, separated by spaces. Commas can also 456 457 be used to separate values; if a comma is used, the cycle values are 457 458 interpreted as literal strings. … … 460 461 # Note: This returns the exact same node on each {% cycle name %} call; 461 462 # that is, the node object returned from {% cycle a b c as name %} and the 462 # one returned from {% cycle name %} are the exact same object. This463 # one returned from {% cycle name %} are the exact same object. This 463 464 # shouldn't cause problems (heh), but if it does, now you know. 464 465 # 465 # Ugly hack warning: this stuffs the named template dict into parser so466 # Ugly hack warning: This stuffs the named template dict into parser so 466 467 # that names are only unique within each template (as opposed to using 467 468 # a global variable, which would make cycle names have to be unique across … … 482 483 name = args[1] 483 484 if not hasattr(parser, '_namedCycleNodes'): 484 raise TemplateSyntaxError("No named cycles in template." 485 " '%s' is not defined" % name) 485 raise TemplateSyntaxError("No named cycles in template. '%s' is not defined" % name) 486 486 if not name in parser._namedCycleNodes: 487 487 raise TemplateSyntaxError("Named cycle '%s' does not exist" % name) … … 683 683 """ 684 684 The ``{% if %}`` tag evaluates a variable, and if that variable is "true" 685 (i.e. exists, is not empty, and is not a false boolean value) the contents 686 of the block are output:: 685 (i.e., exists, is not empty, and is not a false boolean value), the 686 contents of the block are output: 687 688 :: 687 689 688 690 {% if athlete_list %} django/branches/gis/django/template/loader_tags.py
r7103 r7768 70 70 def render(self, context): 71 71 compiled_parent = self.get_parent(context) 72 pos = 073 while isinstance(compiled_parent.nodelist[pos], TextNode):74 pos += 175 parent_is_child = isinstance(compiled_parent.nodelist[pos], ExtendsNode)76 72 parent_blocks = dict([(n.name, n) for n in compiled_parent.nodelist.get_nodes_by_type(BlockNode)]) 77 73 for block_node in self.nodelist.get_nodes_by_type(BlockNode): … … 84 80 # add this BlockNode to the parent's ExtendsNode nodelist, so 85 81 # it'll be checked when the parent node's render() is called. 86 if parent_is_child: 87 compiled_parent.nodelist[pos].nodelist.append(block_node) 82 83 # Find out if the parent template has a parent itself 84 for node in compiled_parent.nodelist: 85 if not isinstance(node, TextNode): 86 # If the first non-text node is an extends, handle it. 87 if isinstance(node, ExtendsNode): 88 node.nodelist.append(block_node) 89 # Extends must be the first non-text node, so once you find 90 # the first non-text node you can stop looking. 91 break 88 92 else: 89 93 # Keep any existing parents and add a new one. Used by BlockNode.
