Mercurial > public > sg101
comparison gpp/antispam/utils.py @ 214:28988cce138b
Implement #83: a string filter facility like NukeSeSentinel. It currently isn't hooked up to anything. Will do that in #84.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Fri, 14 May 2010 02:19:48 +0000 |
parents | |
children | 8c1832b9d815 |
comparison
equal
deleted
inserted
replaced
213:65016249bf35 | 214:28988cce138b |
---|---|
1 """Antispam utility functions other apps can use.""" | |
2 from django.core.cache import cache | |
3 | |
4 from antispam import SPAM_PHRASE_KEY | |
5 from antispam.models import SpamPhrase | |
6 | |
7 | |
8 def contains_spam(s): | |
9 """This function returns True if the supplied string s contains any spam | |
10 phrases and False otherwise. | |
11 """ | |
12 phrases = _get_spam_phrases() | |
13 for spam in phrases: | |
14 if spam in s: | |
15 return True | |
16 | |
17 return False | |
18 | |
19 | |
20 def _get_spam_phrases(): | |
21 """This function returns the current list of spam phrase strings. | |
22 The strings are cached to avoid hitting the database. | |
23 """ | |
24 phrases = cache.get(SPAM_PHRASE_KEY) | |
25 if phrases: | |
26 return phrases | |
27 | |
28 phrases = SpamPhrase.objects.values_list('phrase', flat=True) | |
29 cache.set(SPAM_PHRASE_KEY, phrases) | |
30 return phrases | |
31 |