Ticket #393: filter-object.diff

File filter-object.diff, 7.4 KB (added by Boffbowsh, 19 years ago)
  • usr/local/django_src/django/core/template.py

     
    412412   except VariableDoesNotExist:
    413413       obj = ''
    414414   for name, arg in filters:
     415       if registered_filters[name][2]:
     416               # Check type so that we don't run str() on a Unicode object
     417               if not isinstance(obj, basestring):
     418                   obj = str(obj)
     419               elif isinstance(obj, unicode):
     420                   obj = obj.encode('utf-8')
    415421       obj = registered_filters[name][0](obj, arg)
    416422   return obj
    417423
     
    481487def unregister_tag(token_command):
    482488   del registered_tags[token_command]
    483489
    484 def register_filter(filter_name, callback_function, has_arg):
    485     registered_filters[filter_name] = (callback_function, has_arg)
     490def register_filter(filter_name, callback_function, has_arg, string_only=False):
     491    registered_filters[filter_name] = (callback_function, has_arg, string_only)
    486492
    487493def unregister_filter(filter_name):
    488494   del registered_filters[filter_name]
  • usr/local/django_src/django/core/defaultfilters.py

     
    1313
    1414def capfirst(value, _):
    1515   "Capitalizes the first character of the value"
    16     value = str(value)
    17     return value and value[0].upper() + value[1:]
     16    return value[0].upper() + value[1:]
    1817
    1918def fix_ampersands(value, _):
    2019   "Replaces ampersands with ``&`` entities"
     
    418417   from pprint import pformat
    419418   return pformat(value)
    420419
    421 # Syntax: template.register_filter(name of filter, callback, has_argument)
    422 template.register_filter('add', add, True)
    423 template.register_filter('addslashes', addslashes, False)
    424 template.register_filter('capfirst', capfirst, False)
    425 template.register_filter('center', center, True)
    426 template.register_filter('cut', cut, True)
    427 template.register_filter('date', date, True)
    428 template.register_filter('default', default, True)
    429 template.register_filter('dictsort', dictsort, True)
    430 template.register_filter('dictsortreversed', dictsortreversed, True)
    431 template.register_filter('divisibleby', divisibleby, True)
    432 template.register_filter('escape', escape, False)
    433 template.register_filter('filesizeformat', filesizeformat, False)
    434 template.register_filter('first', first, False)
    435 template.register_filter('fix_ampersands', fix_ampersands, False)
    436 template.register_filter('floatformat', floatformat, False)
    437 template.register_filter('get_digit', get_digit, True)
    438 template.register_filter('join', join, True)
    439 template.register_filter('length', length, False)
    440 template.register_filter('length_is', length_is, True)
    441 template.register_filter('linebreaks', linebreaks, False)
    442 template.register_filter('linebreaksbr', linebreaksbr, False)
    443 template.register_filter('linenumbers', linenumbers, False)
    444 template.register_filter('ljust', ljust, True)
    445 template.register_filter('lower', lower, False)
    446 template.register_filter('make_list', make_list, False)
    447 template.register_filter('phone2numeric', phone2numeric, False)
    448 template.register_filter('pluralize', pluralize, False)
    449 template.register_filter('pprint', pprint, False)
    450 template.register_filter('removetags', removetags, True)
    451 template.register_filter('random', random, False)
    452 template.register_filter('rjust', rjust, True)
    453 template.register_filter('slice', slice_, True)
    454 template.register_filter('slugify', slugify, False)
    455 template.register_filter('stringformat', stringformat, True)
    456 template.register_filter('striptags', striptags, False)
    457 template.register_filter('time', time, True)
    458 template.register_filter('timesince', timesince, False)
    459 template.register_filter('title', title, False)
    460 template.register_filter('truncatewords', truncatewords, True)
    461 template.register_filter('unordered_list', unordered_list, False)
    462 template.register_filter('upper', upper, False)
    463 template.register_filter('urlencode', urlencode, False)
    464 template.register_filter('urlize', urlize, False)
    465 template.register_filter('urlizetrunc', urlizetrunc, True)
    466 template.register_filter('wordcount', wordcount, False)
    467 template.register_filter('wordwrap', wordwrap, True)
    468 template.register_filter('yesno', yesno, True)
     420# Syntax: template.register_filter(name of filter, callback, has_argument, string_only)
     421template.register_filter('add', add, True, False)
     422template.register_filter('addslashes', addslashes, False, True)
     423template.register_filter('capfirst', capfirst, False, True)
     424template.register_filter('center', center, True, True)
     425template.register_filter('cut', cut, True, True)
     426template.register_filter('date', date, True, False)
     427template.register_filter('default', default, True, False)
     428template.register_filter('dictsort', dictsort, True, False)
     429template.register_filter('dictsortreversed', dictsortreversed, True, False)
     430template.register_filter('divisibleby', divisibleby, True, False)
     431template.register_filter('escape', escape, False, True)
     432template.register_filter('filesizeformat', filesizeformat, False, False)
     433template.register_filter('first', first, False, False)
     434template.register_filter('fix_ampersands', fix_ampersands, False, True)
     435template.register_filter('floatformat', floatformat, False, False)
     436template.register_filter('get_digit', get_digit, True, False)
     437template.register_filter('join', join, True, False)
     438template.register_filter('length', length, False, False)
     439template.register_filter('length_is', length_is, True, False)
     440template.register_filter('linebreaks', linebreaks, False, True)
     441template.register_filter('linebreaksbr', linebreaksbr, False, True)
     442template.register_filter('linenumbers', linenumbers, False, True)
     443template.register_filter('ljust', ljust, True, True)
     444template.register_filter('lower', lower, False, True)
     445template.register_filter('make_list', make_list, False, True)
     446template.register_filter('phone2numeric', phone2numeric, True, True)
     447template.register_filter('pluralize', pluralize, False, False)
     448template.register_filter('pprint', pprint, False, False)
     449template.register_filter('removetags', removetags, True, True)
     450template.register_filter('random', random, False, False)
     451template.register_filter('rjust', rjust, True, True)
     452template.register_filter('slice', slice_, True, False)
     453template.register_filter('slugify', slugify, False, True)
     454template.register_filter('stringformat', stringformat, True, True)
     455template.register_filter('striptags', striptags, False, True)
     456template.register_filter('time', time, True, False)
     457template.register_filter('timesince', timesince, False, False)
     458template.register_filter('title', title, False, True)
     459template.register_filter('truncatewords', truncatewords, True, True)
     460template.register_filter('unordered_list', unordered_list, False, False)
     461template.register_filter('upper', upper, False, True)
     462template.register_filter('urlencode', urlencode, False, True)
     463template.register_filter('urlize', urlize, False, True)
     464template.register_filter('urlizetrunc', urlizetrunc, True, True)
     465template.register_filter('wordcount', wordcount, False, True)
     466template.register_filter('wordwrap', wordwrap, True, True)
     467template.register_filter('yesno', yesno, True, False)
Back to Top