Audit word filter

 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. wordbreak filter by soniiic 4 years, 2 months ago
  2. custom template tag sample by shinyzhu 3 years, 4 months ago
  3. Avoid widows using a template filter by jcroft 6 years, 3 months ago
  4. Truncate string after a given number of chars keeping whole words by rix 4 years, 5 months ago
  5. Table of Contents by dogada 5 years, 6 months ago

Comments

(Forgotten your password?)