Changeset 6153
- Timestamp:
- 09/13/07 21:49:21 (2 years ago)
- Files:
-
- django/trunk/django/contrib/admin/templates/admin/change_list_results.html (modified) (1 diff)
- django/trunk/django/contrib/databrowse/templates/databrowse/calendar_day.html (modified) (1 diff)
- django/trunk/django/contrib/databrowse/templates/databrowse/calendar_homepage.html (modified) (1 diff)
- django/trunk/django/contrib/databrowse/templates/databrowse/calendar_main.html (modified) (1 diff)
- django/trunk/django/contrib/databrowse/templates/databrowse/calendar_month.html (modified) (1 diff)
- django/trunk/django/contrib/databrowse/templates/databrowse/calendar_year.html (modified) (1 diff)
- django/trunk/django/contrib/databrowse/templates/databrowse/choice_detail.html (modified) (1 diff)
- django/trunk/django/contrib/databrowse/templates/databrowse/choice_list.html (modified) (1 diff)
- django/trunk/django/contrib/databrowse/templates/databrowse/fieldchoice_detail.html (modified) (1 diff)
- django/trunk/django/contrib/databrowse/templates/databrowse/fieldchoice_homepage.html (modified) (1 diff)
- django/trunk/django/contrib/databrowse/templates/databrowse/fieldchoice_list.html (modified) (1 diff)
- django/trunk/django/contrib/databrowse/templates/databrowse/homepage.html (modified) (1 diff)
- django/trunk/django/contrib/databrowse/templates/databrowse/model_detail.html (modified) (1 diff)
- django/trunk/django/contrib/databrowse/templates/databrowse/object_detail.html (modified) (2 diffs)
- django/trunk/django/template/defaulttags.py (modified) (4 diffs)
- django/trunk/docs/templates.txt (modified) (1 diff)
- django/trunk/tests/regressiontests/templates/tests.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
django/trunk/django/contrib/admin/templates/admin/change_list_results.html
r1791 r6153 11 11 <tbody> 12 12 {% for result in results %} 13 <tr class="{% cycle row1,row2%}">{% for item in result %}{{ item }}{% endfor %}</tr>13 <tr class="{% cycle 'row1' 'row2' %}">{% for item in result %}{{ item }}{% endfor %}</tr> 14 14 {% endfor %} 15 15 </tbody> django/trunk/django/contrib/databrowse/templates/databrowse/calendar_day.html
r5947 r6153 11 11 <ul class="objectlist"> 12 12 {% for object in object_list %} 13 <li class="{% cycle odd,even%}"><a href="{{ object.url }}">{{ object|escape }}</a></li>13 <li class="{% cycle 'odd' 'even' %}"><a href="{{ object.url }}">{{ object|escape }}</a></li> 14 14 {% endfor %} 15 15 </ul> django/trunk/django/contrib/databrowse/templates/databrowse/calendar_homepage.html
r5947 r6153 11 11 <ul class="objectlist"> 12 12 {% for field in field_list %} 13 <li class="{% cycle odd,even%}"><a href="{{ field.name }}/">{{ model.verbose_name_plural|capfirst }} by {{ field.verbose_name }}</a></li>13 <li class="{% cycle 'odd' 'even' %}"><a href="{{ field.name }}/">{{ model.verbose_name_plural|capfirst }} by {{ field.verbose_name }}</a></li> 14 14 {% endfor %} 15 15 </ul> django/trunk/django/contrib/databrowse/templates/databrowse/calendar_main.html
r5947 r6153 11 11 <ul class="objectlist"> 12 12 {% for year in date_list %} 13 <li class="{% cycle odd,even%}"><a href="{{ year.year }}/">{{ year.year }}</a></li>13 <li class="{% cycle 'odd' 'even' %}"><a href="{{ year.year }}/">{{ year.year }}</a></li> 14 14 {% endfor %} 15 15 </ul> django/trunk/django/contrib/databrowse/templates/databrowse/calendar_month.html
r5947 r6153 11 11 <ul class="objectlist"> 12 12 {% for object in object_list %} 13 <li class="{% cycle odd,even%}"><a href="{{ object.url }}">{{ object|escape }}</a></li>13 <li class="{% cycle 'odd' 'even' %}"><a href="{{ object.url }}">{{ object|escape }}</a></li> 14 14 {% endfor %} 15 15 </ul> django/trunk/django/contrib/databrowse/templates/databrowse/calendar_year.html
r5947 r6153 11 11 <ul class="objectlist"> 12 12 {% for month in date_list %} 13 <li class="{% cycle odd,even%}"><a href="{{ month|date:"M"|lower }}/">{{ month|date:"F" }}</a></li>13 <li class="{% cycle 'odd' 'even' %}"><a href="{{ month|date:"M"|lower }}/">{{ month|date:"F" }}</a></li> 14 14 {% endfor %} 15 15 </ul> django/trunk/django/contrib/databrowse/templates/databrowse/choice_detail.html
r5947 r6153 11 11 <ul class="objectlist"> 12 12 {% for object in object_list %} 13 <li class="{% cycle odd,even%}"><a href="{{ object.url }}">{{ object|escape }}</a></li>13 <li class="{% cycle 'odd' 'even' %}"><a href="{{ object.url }}">{{ object|escape }}</a></li> 14 14 {% endfor %} 15 15 </ul> django/trunk/django/contrib/databrowse/templates/databrowse/choice_list.html
r5947 r6153 11 11 <ul class="objectlist"> 12 12 {% for choice in field.choices %} 13 <li class="{% cycle odd,even%}"><a href="{{ choice.url }}">{{ choice.label|escape }}</a></li>13 <li class="{% cycle 'odd' 'even' %}"><a href="{{ choice.url }}">{{ choice.label|escape }}</a></li> 14 14 {% endfor %} 15 15 </ul> django/trunk/django/contrib/databrowse/templates/databrowse/fieldchoice_detail.html
r5947 r6153 11 11 <ul class="objectlist"> 12 12 {% for object in object_list %} 13 <li class="{% cycle odd,even%}"><a href="{{ object.url }}">{{ object|escape }}</a></li>13 <li class="{% cycle 'odd' 'even' %}"><a href="{{ object.url }}">{{ object|escape }}</a></li> 14 14 {% endfor %} 15 15 </ul> django/trunk/django/contrib/databrowse/templates/databrowse/fieldchoice_homepage.html
r5947 r6153 11 11 <ul class="objectlist"> 12 12 {% for field in field_list %} 13 <li class="{% cycle odd,even%}"><a href="{{ field.name }}/">{{ model.verbose_name_plural|capfirst }} by {{ field.verbose_name }}</a></li>13 <li class="{% cycle 'odd' 'even' %}"><a href="{{ field.name }}/">{{ model.verbose_name_plural|capfirst }} by {{ field.verbose_name }}</a></li> 14 14 {% endfor %} 15 15 </ul> django/trunk/django/contrib/databrowse/templates/databrowse/fieldchoice_list.html
r5947 r6153 11 11 <ul class="objectlist"> 12 12 {% for object in object_list %} 13 <li class="{% cycle odd,even%}"><a href="{{ object|iriencode }}/">{{ object|escape }}</a></li>13 <li class="{% cycle 'odd' 'even' %}"><a href="{{ object|iriencode }}/">{{ object|escape }}</a></li> 14 14 {% endfor %} 15 15 </ul> django/trunk/django/contrib/databrowse/templates/databrowse/homepage.html
r5947 r6153 8 8 9 9 {% for model in model_list %} 10 <div class="modelgroup {% cycle even,odd%}">10 <div class="modelgroup {% cycle 'even' 'odd' %}"> 11 11 <h2><a href="{{ model.url }}">{{ model.verbose_name_plural|capfirst }}</a></h2> 12 12 <p> django/trunk/django/contrib/databrowse/templates/databrowse/model_detail.html
r5947 r6153 13 13 <ul class="objectlist"> 14 14 {% for object in model.objects %} 15 <li class="{% cycle odd,even%}"><a href="{{ object.url }}">{{ object|escape }}</a></li>15 <li class="{% cycle 'odd' 'even' %}"><a href="{{ object.url }}">{{ object|escape }}</a></li> 16 16 {% endfor %} 17 17 </ul> django/trunk/django/contrib/databrowse/templates/databrowse/object_detail.html
r5947 r6153 11 11 <table class="objectinfo"> 12 12 {% for field in object.fields %} 13 <tr class="{% cycle odd,even%}">13 <tr class="{% cycle 'odd' 'even' %}"> 14 14 <th>{{ field.field.verbose_name|capfirst }}</th> 15 15 <td> … … 30 30 <ul class="objectlist"> 31 31 {% for object in related_object.object_list %} 32 <li class="{% cycle odd,even%}"><a href="{{ object.url }}">{{ object|escape }}</a></li>32 <li class="{% cycle 'odd' 'even' %}"><a href="{{ object.url }}">{{ object|escape }}</a></li> 33 33 {% endfor %} 34 34 </ul> django/trunk/django/template/defaulttags.py
r5927 r6153 31 31 self.counter += 1 32 32 value = self.cyclevars[self.counter % self.cyclevars_len] 33 value = resolve_variable(value, context) 33 34 if self.variable_name: 34 35 context[self.variable_name] = value … … 404 405 405 406 {% for o in some_list %} 406 <tr class="{% cycle row1,row2%}">407 <tr class="{% cycle 'row1' 'row2' %}"> 407 408 ... 408 409 </tr> … … 412 413 it, then use that name each sucessive time through:: 413 414 414 <tr class="{% cycle row1,row2,row3as rowcolors %}">...</tr>415 <tr class="{% cycle 'row1' 'row2' 'row3' as rowcolors %}">...</tr> 415 416 <tr class="{% cycle rowcolors %}">...</tr> 416 417 <tr class="{% cycle rowcolors %}">...</tr> 417 418 418 You can use any number of values, seperated by commas. Make sure not to 419 put spaces between the values -- only commas. 419 You can use any number of values, seperated by spaces. Commas can also 420 be used to separate values; if a comma is used, the cycle values are 421 interpreted as literal strings. 420 422 """ 421 423 422 424 # Note: This returns the exact same node on each {% cycle name %} call; that 423 # is, the node object returned from {% cycle a ,b,c as name %} and the one425 # is, the node object returned from {% cycle a b c as name %} and the one 424 426 # returned from {% cycle name %} are the exact same object. This shouldn't 425 427 # cause problems (heh), but if it does, now you know. … … 430 432 # *all* templates. 431 433 432 args = token.contents.split() 434 args = token.split_contents() 435 433 436 if len(args) < 2: 434 raise TemplateSyntaxError("' Cycle' statementrequires at least two arguments")435 436 elif len(args) == 2 and ","in args[1]:437 # {% cycle a,b,c%}438 cyclevars = [v for v in args[1].split(",") if v] # split and kill blanks439 return CycleNode(cyclevars)440 # {% cycle name %} 441 442 elif len(args) == 2:437 raise TemplateSyntaxError("'cycle' tag requires at least two arguments") 438 439 if ',' in args[1]: 440 # Backwards compatibility: {% cycle a,b %} or {% cycle a,b as foo %} 441 # case. 442 args[1:2] = ['"%s"' % arg for arg in args[1].split(",")] 443 444 if len(args) == 2: 445 # {% cycle foo %} case 443 446 name = args[1] 444 447 if not hasattr(parser, '_namedCycleNodes'): 445 448 raise TemplateSyntaxError("No named cycles in template: '%s' is not defined" % name) 446 if n ame notin parser._namedCycleNodes:449 if not name in parser._namedCycleNodes: 447 450 raise TemplateSyntaxError("Named cycle '%s' does not exist" % name) 448 451 return parser._namedCycleNodes[name] 449 452 450 elif len(args) == 4: 451 # {% cycle a,b,c as name %} 452 if args[2] != 'as': 453 raise TemplateSyntaxError("Second 'cycle' argument must be 'as'") 454 cyclevars = [v for v in args[1].split(",") if v] # split and kill blanks 455 name = args[3] 456 node = CycleNode(cyclevars, name) 457 453 if len(args) > 4 and args[-2] == 'as': 454 name = args[-1] 455 node = CycleNode(args[1:-2], name) 458 456 if not hasattr(parser, '_namedCycleNodes'): 459 457 parser._namedCycleNodes = {} 460 461 458 parser._namedCycleNodes[name] = node 462 return node463 464 459 else: 465 raise TemplateSyntaxError("Invalid arguments to 'cycle': %s" % args) 460 node = CycleNode(args[1:]) 461 return node 466 462 cycle = register.tag(cycle) 467 463 django/trunk/docs/templates.txt
r6070 r6153 367 367 ~~~~~ 368 368 369 Cycle among the given strings each time this tag is encountered. 370 371 Within a loop, cycles among the given strings each time through the loop:: 369 **Changed in Django development version** 370 Cycle among the given strings or variables each time this tag is encountered. 371 372 Within a loop, cycles among the given strings/variables each time through the 373 loop:: 372 374 373 375 {% for o in some_list %} 374 <tr class="{% cycle row1,row2%}">376 <tr class="{% cycle 'row1' 'row2' rowvar %}"> 375 377 ... 376 378 </tr> 377 379 {% endfor %} 378 380 379 381 Outside of a loop, give the values a unique name the first time you call it, 380 382 then use that name each successive time through:: 381 383 382 <tr class="{% cycle row1,row2,row3as rowcolors %}">...</tr>384 <tr class="{% cycle 'row1' 'row2' rowvar as rowcolors %}">...</tr> 383 385 <tr class="{% cycle rowcolors %}">...</tr> 384 386 <tr class="{% cycle rowcolors %}">...</tr> 385 387 386 You can use any number of values, separated by commas. Make sure not to put 387 spaces between the values -- only commas. 388 You can use any number of values, separated by spaces. Values enclosed in 389 single (') or double quotes (") are treated as string literals, while values 390 without quotes are assumed to refer to context variables. 391 392 You can also separate values with commas:: 393 394 {% cycle row1,row2,row3 %} 395 396 In this syntax, each value will be interpreted as literal text. The 397 comma-based syntax exists for backwards-compatibility, and should not be 398 used for new projects. 388 399 389 400 debug django/trunk/tests/regressiontests/templates/tests.py
r5876 r6153 307 307 'cycle07': ('{% cycle a,b,c as foo %}{% cycle bar %}', {}, template.TemplateSyntaxError), 308 308 'cycle08': ('{% cycle a,b,c as foo %}{% cycle foo %}{{ foo }}{{ foo }}{% cycle foo %}{{ foo }}', {}, 'abbbcc'), 309 'cycle09': ("{% for i in test %}{% cycle a,b %}{{ i }},{% endfor %}", {'test': range(5)}, 'a0,b1,a2,b3,a4,'), 310 # New format: 311 'cycle10': ("{% cycle 'a' 'b' 'c' as abc %}{% cycle abc %}", {}, 'ab'), 312 'cycle11': ("{% cycle 'a' 'b' 'c' as abc %}{% cycle abc %}{% cycle abc %}", {}, 'abc'), 313 'cycle12': ("{% cycle 'a' 'b' 'c' as abc %}{% cycle abc %}{% cycle abc %}{% cycle abc %}", {}, 'abca'), 314 'cycle13': ("{% for i in test %}{% cycle 'a' 'b' %}{{ i }},{% endfor %}", {'test': range(5)}, 'a0,b1,a2,b3,a4,'), 315 'cycle14': ("{% cycle one two as foo %}{% cycle foo %}", {'one': '1','two': '2'}, '12'), 316 'cycle13': ("{% for i in test %}{% cycle aye bee %}{{ i }},{% endfor %}", {'test': range(5), 'aye': 'a', 'bee': 'b'}, 'a0,b1,a2,b3,a4,'), 309 317 310 318 ### EXCEPTIONS ############################################################
