Django

Code

Changeset 6571

Show
Ignore:
Timestamp:
10/20/07 10:01:31 (1 year ago)
Author:
mtredinnick
Message:

Fixed #4123 -- Changed the firstof template tag to correctly handle a literal
string as its last argument. Thanks, Wesley Fok and Matt Boersma.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/template/defaulttags.py

    r6539 r6571  
    518518 
    519519    but obviously much cleaner! 
    520     """ 
    521     bits = token.contents.split()[1:] 
     520 
     521    You can also use a literal string as a fallback value in case all 
     522    passed variables are False:: 
     523 
     524        {% firstof var1 var2 var3 "fallback value" %} 
     525 
     526    """ 
     527    bits = token.split_contents()[1:] 
    522528    if len(bits) < 1: 
    523529        raise TemplateSyntaxError, "'firstof' statement requires at least one argument" 
  • django/trunk/docs/templates.txt

    r6562 r6571  
    476476        {{ var3 }} 
    477477    {% endif %}{% endif %}{% endif %} 
     478 
     479You can also use a literal string as a fallback value in case all 
     480passed variables are False:: 
     481 
     482    {% firstof var1 var2 var3 "fallback value" %} 
    478483 
    479484for 
  • django/trunk/tests/regressiontests/templates/tests.py

    r6366 r6571  
    342342            'firstof04': ('{% firstof a b c %}', {'a':0,'b':0,'c':3}, '3'), 
    343343            'firstof05': ('{% firstof a b c %}', {'a':1,'b':2,'c':3}, '1'), 
    344             'firstof06': ('{% firstof %}', {}, template.TemplateSyntaxError), 
     344            'firstof06': ('{% firstof a b c %}', {'b':0,'c':3}, '3'), 
     345            'firstof07': ('{% firstof a b "c" %}', {'a':0}, 'c'), 
     346            'firstof08': ('{% firstof a b "c and d" %}', {'a':0,'b':0}, 'c and d'), 
     347            'firstof09': ('{% firstof %}', {}, template.TemplateSyntaxError), 
    345348 
    346349            ### FOR TAG ###############################################################