Ticket #6290: profanepatch.diff
File profanepatch.diff, 1.9 KB (added by , 17 years ago) |
---|
-
django/contrib/humanize/templatetags/humanize.py
from django import template 4 4 from django.template import defaultfilters 5 5 from django.conf import settings 6 6 from datetime import date, timedelta 7 from random import randint8 7 import re 9 8 10 9 register = template.Library() … … def naturalday(value, arg=None): 99 98 return _(u'yesterday') 100 99 return defaultfilters.date(value, arg) 101 100 register.filter(naturalday) 102 103 def profanity(value, arg='star'):104 """Removes profane words and replaces them with ***"""105 BADWORDS = settings.PROFANITIES_LIST106 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 + clean118 value = reg.sub(clean, value)119 return value120 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): 173 173 174 174 .. _DATE_FORMAT: ../settings/#date_format 175 175 176 profanity177 ---------178 179 **New in Django development version**180 181 Remove profanity, replacing it with stars or symbols. This uses the182 ``PROFANE_WORDS`` setting either from your settings.py or183 global_settings.py.184 185 The optional argument can be ``'symbol'`` or ``'star'``. Anything else is186 ignored and the default behaviour is assumed. ``'symbol'`` will make the187 profane words be replaced from a random string of symbols: #^@!@* while the188 default mode just replaces them with asterisks: ******189 190 176 localflavor 191 177 =========== 192 178