Ticket #6290: profanepatch.diff

File profanepatch.diff, 1.9 KB (added by Jeff Anderson, 16 years ago)

Initial patch

  • django/contrib/humanize/templatetags/humanize.py

    from django import template  
    44from django.template import defaultfilters
    55from django.conf import settings
    66from datetime import date, timedelta
    7 from random import randint
    87import re
    98
    109register = template.Library()
    def naturalday(value, arg=None):  
    9998        return _(u'yesterday')
    10099    return defaultfilters.date(value, arg)
    101100register.filter(naturalday)
    102 
    103 def profanity(value, arg='star'):
    104         """Removes profane words and replaces them with ***"""
    105         BADWORDS = settings.PROFANITIES_LIST
    106         for word in BADWORDS:
    107                 rePattern = r"\b(" + word + r")\b"
    108                 reg = re.compile(rePattern)
    109                 if (arg == 'symbol'):
    110                         symbols = ('@','!','*','#','^','*','@','!','#','@','!')
    111                         clean = ''
    112                         while len( clean) < len( word ):
    113                                 clean = clean + symbols[randint(0,len(symbols)-1)]
    114                 else:
    115                         clean = '*'
    116                         while len( clean ) < len( word ):
    117                                 clean = clean + clean
    118                 value = reg.sub(clean, value)
    119         return value
    120 register.filter(profanity)
  • docs/add_ons.txt

    diff --git a/docs/add_ons.txt b/docs/add_ons.txt
    index 1494bb7..c6fdb4a 100644
    a b Examples (when 'today' is 17 Feb 2007):  
    173173
    174174.. _DATE_FORMAT: ../settings/#date_format
    175175
    176 profanity
    177 ---------
    178 
    179 **New in Django development version**
    180 
    181 Remove profanity, replacing it with stars or symbols. This uses the
    182 ``PROFANE_WORDS`` setting either from your settings.py or
    183 global_settings.py.
    184 
    185 The optional argument can be ``'symbol'`` or ``'star'``. Anything else is
    186 ignored and the default behaviour is assumed. ``'symbol'`` will make the
    187 profane words be replaced from a random string of symbols: #^@!@* while the
    188 default mode just replaces them with asterisks: ******
    189 
    190176localflavor
    191177===========
    192178
Back to Top