Beispiel #1
0
def title(value):
    """
    A slightly better title template filter.

    Same as Django's builtin ``title`` filter, but operates on individual words
    and leaves words unchanged if they already have a capital letter.
    """
    title_word = lambda w: w if RE_UPPERCASE.search(w) else old_title(w)
    return re.sub('(\S+)', lambda m: title_word(m.group(0)), value)
Beispiel #2
0
def title(value):
    """
    A slightly better title template filter.

    Same as Django's builtin ``title`` filter, but operates on individual words
    and leaves words unchanged if they already have a capital letter.
    """
    title_word = lambda w: w if RE_UPPERCASE.search(w) else old_title(w)
    return re.sub('(\S+)', lambda m: title_word(m.group(0)), value)
Beispiel #3
0
def title(value):
    '''
    A slightly better title template filter.

    Same as Django's builtin `~django.template.defaultfilters.title` filter,
    but operates on individual words and leaves words unchanged if they already
    have a capital letter or a digit. Actually Django's filter also skips
    words with digits but only for latin letters (or at least not for
    cyrillic ones).
    '''
    return ' '.join([
        any([c.isupper() or c.isdigit() for c in w]) and w or old_title(w)
        for w in value.split()
    ])
Beispiel #4
0
 def title_word(w):
     return w if RE_UPPERCASE.search(w) else old_title(w)
Beispiel #5
0
 def title_word(w):
     return w if RE_UPPERCASE.search(w) else old_title(w)