Ticket #2250: munge_email.diff

File munge_email.diff, 1.4 KB (added by anonymous, 18 years ago)

Patch implementing a template filter munge_email

  • django/template/defaultfilters.py

     
    6363    """
    6464    return list(str(value))
    6565
     66def munge_email(value):
     67    """Tries to hide email address from spambots.
     68
     69    Not handling unicode strings.
     70    """
     71    if isinstance(value, str):
     72        return ''.join('&#%d;' % ord(char) for char in value)
     73    else:
     74        return value
     75
    6676def slugify(value):
    6777    "Converts to lowercase, removes non-alpha chars and converts spaces to hyphens"
    6878    value = re.sub('[^\w\s-]', '', value).strip().lower()
     
    485495register.filter(ljust)
    486496register.filter(lower)
    487497register.filter(make_list)
     498register.filter(munge_email)
    488499register.filter(phone2numeric)
    489500register.filter(pluralize)
    490501register.filter(pprint)
  • docs/templates.txt

     
    938938Returns the value turned into a list. For an integer, it's a list of
    939939digits. For a string, it's a list of characters.
    940940
     941munge_email
     942~~~~~~~~~~
     943
     944Returns an encoded version of a string. Can be used to make it harder for
     945spambots to harvest e-mail addresses. For example, ``'a@b.com'`` gets
     946converted to ``'a@b.com'``.
     947
    941948phone2numeric
    942949~~~~~~~~~~~~~
    943950
Back to Top