Login

Audit word filter

Author:
shinyzhu
Posted:
February 10, 2010
Language:
Python
Version:
1.1
Tags:
filter
Score:
0 (after 0 ratings)

a simple bad word filter. usage:

{{ post.content|audit }}

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
from django import template
from post.models import AuditWord
from datetime import datetime

register = template.Library()

_bad_words = [aw.word for aw in AuditWord.objects.filter(is_published=True)]

@register.filter
def audit(value):
    for word in _bad_words:
        if word in value:
            value = value.replace(word,'*')

    return value

More like this

  1. Truncate words by characters by trodrigues 6 years, 10 months ago
  2. wordbreak filter by soniiic 5 years, 11 months ago
  3. Truncate string after a given number of chars keeping whole words by rix 6 years, 3 months ago
  4. truncatehtml_at_word by zakj 6 years, 4 months ago
  5. Word-boundary-aware string truncation template filter by josho 5 years, 10 months ago

Comments

Please login first before commenting.