Django

Code

Changeset 859

Show
Ignore:
Timestamp:
10/13/05 22:48:27 (3 years ago)
Author:
adrian
Message:

Fixed #622 -- Added default_if_none filter. Thanks, Eric

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/defaultfilters.py

    r666 r859  
    333333    "If value is unavailable, use given default" 
    334334    return value or arg 
     335 
     336def default_if_none(value, arg): 
     337    "If value is None, use given default" 
     338    if value is None: 
     339        return arg 
     340    return value 
    335341 
    336342def divisibleby(value, arg): 
  • django/trunk/docs/templates.txt

    r736 r859  
    377377        ``forloop.counter``         The current iteration of the loop (1-indexed) 
    378378        ``forloop.counter0``        The current iteration of the loop (0-indexed) 
    379         ``forloop.revcounter``      The number of iterations from the end of the  
     379        ``forloop.revcounter``      The number of iterations from the end of the 
    380380                                    loop (1-indexed) 
    381         ``forloop.revcounter0``     The number of iterations from the end of the  
     381        ``forloop.revcounter0``     The number of iterations from the end of the 
    382382                                    loop (0-indexed) 
    383383        ``forloop.first``           True if this is the first time through the loop 
     
    570570 
    571571``add`` 
    572     Adds the arg to the value 
     572    Adds the arg to the value. 
    573573 
    574574``addslashes`` 
    575     Adds slashes - useful for passing strings to JavaScript, for example. 
     575    Adds slashes. Useful for passing strings to JavaScript, for example. 
    576576 
    577577``capfirst`` 
    578     Capitalizes the first character of the value 
     578    Capitalizes the first character of the value. 
    579579 
    580580``center`` 
    581     Centers the value in a field of a given width 
     581    Centers the value in a field of a given width. 
    582582 
    583583``cut`` 
    584     Removes all values of arg from the given string 
     584    Removes all values of arg from the given string. 
    585585 
    586586``date`` 
    587     Formats a date according to the given format (same as the ``now`` tag) 
     587    Formats a date according to the given format (same as the ``now`` tag). 
    588588 
    589589``default`` 
    590     If value is unavailable, use given default 
     590    If value is unavailable, use given default. 
     591 
     592``default_if_none`` 
     593    If value is ``None``, use given default. 
    591594 
    592595``dictsort`` 
     
    599602 
    600603``divisibleby`` 
    601     Returns true if the value is divisible by the argument 
     604    Returns true if the value is divisible by the argument. 
    602605 
    603606``escape`` 
    604     Escapes a string's HTML 
     607    Escapes a string's HTML. 
    605608 
    606609``filesizeformat`` 
     
    609612 
    610613``first`` 
    611     Returns the first item in a list 
     614    Returns the first item in a list. 
    612615 
    613616``fix_ampersands`` 
    614     Replaces ampersands with ``&`` entities 
     617    Replaces ampersands with ``&`` entities. 
    615618 
    616619``floatformat`` 
    617620    Displays a floating point number as 34.2 (with one decimal places) - but 
    618     only if there's a point to be displayed 
     621    only if there's a point to be displayed. 
    619622 
    620623``get_digit`` 
     
    625628 
    626629``join`` 
    627     Joins a list with a string, like Python's ``str.join(list)`` 
     630    Joins a list with a string, like Python's ``str.join(list)``. 
    628631 
    629632``length`` 
    630     Returns the length of the value - useful for lists 
     633    Returns the length of the value. Useful for lists. 
    631634 
    632635``length_is`` 
    633     Returns a boolean of whether the value's length is the argument 
     636    Returns a boolean of whether the value's length is the argument. 
    634637 
    635638``linebreaks`` 
    636     Converts newlines into <p> and <br />s 
     639    Converts newlines into ``<p>`` and ``<br />``s. 
    637640 
    638641``linebreaksbr`` 
    639     Converts newlines into <br />s 
     642    Converts newlines into ``<br />``s. 
    640643 
    641644``linenumbers`` 
    642     Displays text with line numbers 
     645    Displays text with line numbers. 
    643646 
    644647``ljust`` 
    645     Left-aligns the value in a field of a given width 
     648    Left-aligns the value in a field of a given width. 
    646649 
    647650    **Argument:** field size 
    648651 
    649652``lower`` 
    650     Converts a string into all lowercase 
     653    Converts a string into all lowercase. 
    651654 
    652655``make_list`` 
     
    655658 
    656659``phone2numeric`` 
    657     Takes a phone number and converts it in to its numerical equivalent 
     660    Takes a phone number and converts it in to its numerical equivalent. 
    658661 
    659662``pluralize`` 
    660     Returns 's' if the value is not 1, for '1 vote' vs. '2 votes' 
     663    Returns 's' if the value is not 1, for '1 vote' vs. '2 votes'. 
    661664 
    662665``pprint`` 
    663     A wrapper around pprint.pprint -- for debugging, really 
     666    A wrapper around pprint.pprint -- for debugging, really. 
    664667 
    665668``random`` 
    666     Returns a random item from the list 
     669    Returns a random item from the list. 
    667670 
    668671``removetags`` 
    669     Removes a space separated list of [X]HTML tags from the output 
     672    Removes a space separated list of [X]HTML tags from the output. 
    670673 
    671674``rjust`` 
    672     Right-aligns the value in a field of a given width 
     675    Right-aligns the value in a field of a given width. 
    673676 
    674677    **Argument:** field size 
     
    697700 
    698701``striptags`` 
    699     Strips all [X]HTML tags 
     702    Strips all [X]HTML tags. 
    700703 
    701704``time`` 
     
    703706 
    704707``timesince`` 
    705     Formats a date as the time since that date (i.e. "4 days, 6 hours") 
     708    Formats a date as the time since that date (i.e. "4 days, 6 hours"). 
    706709 
    707710``title`` 
    708     Converts a string into titlecase 
     711    Converts a string into titlecase. 
    709712 
    710713``truncatewords`` 
    711     Truncates a string after a certain number of words 
     714    Truncates a string after a certain number of words. 
    712715 
    713716    **Argument:** Number of words to truncate after 
     
    734737 
    735738``upper`` 
    736     Converts a string into all uppercase 
     739    Converts a string into all uppercase. 
    737740 
    738741``urlencode`` 
    739     Escapes a value for use in a URL 
     742    Escapes a value for use in a URL. 
    740743 
    741744``urlize`` 
    742     Converts URLs in plain text into clickable links 
     745    Converts URLs in plain text into clickable links. 
    743746 
    744747``urlizetrunc`` 
    745     Converts URLs into clickable links, truncating URLs to the given character limit 
    746  
    747     **Argument:** Length to truncate URLs to. 
     748    Converts URLs into clickable links, truncating URLs to the given character 
     749    limit. 
     750 
     751    **Argument:** Length to truncate URLs to 
    748752 
    749753``wordcount`` 
    750     Returns the number of words 
     754    Returns the number of words. 
    751755 
    752756``wordwrap`` 
    753     Wraps words at specified line length 
    754  
    755     **Argument:** number of words to wrap the text at. 
     757    Wraps words at specified line length. 
     758 
     759    **Argument:** number of words at which to wrap the text 
    756760 
    757761``yesno``