~widelands-dev/widelands-website/trunk

« back to all changes in this revision

Viewing changes to anti_spam/anti_spam_utils.py

  • Committer: franku
  • Date: 2017-11-23 16:12:01 UTC
  • mto: This revision was merged to the branch mainline in revision 477.
  • Revision ID: somal@arcor.de-20171123161201-bisjb21bnpx8i8nw
added a model for collecting spams; adjusted pybb

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from django.conf import settings
 
2
from anti_spam.models import FoundSpam
 
3
import re
 
4
 
 
5
 
 
6
def check_for_spam(*args, **kwargs):
 
7
 
 
8
    is_spam = check_text(kwargs['text_to_check'])
 
9
 
 
10
    if is_spam:
 
11
        fs = FoundSpam(content_object=kwargs['instance'],
 
12
                       user=kwargs['user'],
 
13
                       spam_text=kwargs['text_to_check'][:80])
 
14
        fs.save()
 
15
    return is_spam
 
16
 
 
17
 
 
18
def check_text(text):
 
19
    if any(x in text.lower() for x in settings.ANTI_SPAM_KWRDS):
 
20
        return True
 
21
    if re.search(settings.ANTI_SPAM_PHONE_NR, text):
 
22
        return True
 
23
    return False