~widelands-dev/widelands-website/django_staticfiles

« back to all changes in this revision

Viewing changes to pybb/forms.py

  • Committer: franku
  • Date: 2017-11-30 15:53:56 UTC
  • mfrom: (476.1.12 spam_fight)
  • Revision ID: somal@arcor.de-20171130155356-gcx9f8krnkvf6v0y
mergedĀ theĀ anti_spam_app

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
from pybb.models import Topic, Post, PrivateMessage, Attachment
11
11
from pybb import settings as pybb_settings
12
12
from django.conf import settings
13
 
from notification.models import send, get_observers_for
14
13
 
15
14
 
16
15
class AddPostForm(forms.ModelForm):
62
61
            topic_is_new = False
63
62
            topic = self.topic
64
63
 
65
 
        # Check for spam and hide the post
66
 
        # TODO(Franku): This is currently a simple keyword search. Maybe add akismet check here
67
 
        # could be improved...
68
 
        # The admins get informed of hidden post(s) over
69
 
        # a Django command. See pybb/management/commands
70
 
        hidden = False
71
 
        text = self.cleaned_data['body']
72
 
        if any(x in text.lower() for x in settings.ANTI_SPAM_BODY):
73
 
            hidden = True
74
 
 
75
 
        if re.search(settings.ANTI_SPAM_PHONE_NR, text):
76
 
            hidden = True
77
 
 
78
 
        if topic_is_new:
79
 
            text = self.cleaned_data['name']
80
 
            if any(x in text.lower() for x in settings.ANTI_SPAM_TOPIC):
81
 
                hidden = True
82
 
            if re.search(settings.ANTI_SPAM_PHONE_NR, text):
83
 
                hidden = True
84
 
 
85
64
        post = Post(topic=topic, user=self.user, user_ip=self.ip,
86
65
                    markup=self.cleaned_data['markup'],
87
 
                    body=self.cleaned_data['body'], hidden=hidden)
 
66
                    body=self.cleaned_data['body'])
88
67
        post.save(*args, **kwargs)
89
68
 
90
69
        if pybb_settings.ATTACHMENT_ENABLE:
91
70
            self.save_attachment(post, self.cleaned_data['attachment'])
92
71
 
93
 
        if not hidden:
94
 
            if topic_is_new:
95
 
                send(get_observers_for('forum_new_topic'), 'forum_new_topic',
96
 
                     {'topic': topic, 'post': post, 'user': topic.user}, queue = True)
97
 
            else:
98
 
                send(self.topic.subscribers.all(), 'forum_new_post',
99
 
                     {'post': post, 'topic': topic, 'user': post.user}, queue = True)
100
 
 
101
72
        return post
102
73
 
103
74
    def save_attachment(self, post, memfile):