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
16
15
class AddPostForm(forms.ModelForm):
62
61
topic_is_new = False
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
71
text = self.cleaned_data['body']
72
if any(x in text.lower() for x in settings.ANTI_SPAM_BODY):
75
if re.search(settings.ANTI_SPAM_PHONE_NR, text):
79
text = self.cleaned_data['name']
80
if any(x in text.lower() for x in settings.ANTI_SPAM_TOPIC):
82
if re.search(settings.ANTI_SPAM_PHONE_NR, text):
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)
90
69
if pybb_settings.ATTACHMENT_ENABLE:
91
70
self.save_attachment(post, self.cleaned_data['attachment'])
95
send(get_observers_for('forum_new_topic'), 'forum_new_topic',
96
{'topic': topic, 'post': post, 'user': topic.user}, queue = True)
98
send(self.topic.subscribers.all(), 'forum_new_post',
99
{'post': post, 'topic': topic, 'user': post.user}, queue = True)
103
74
def save_attachment(self, post, memfile):