Mercurial > public > sg101
comparison gpp/forums/views.py @ 215:8c1832b9d815
Implement #84; additional checks on spammers; implement stranger status.
author | Brian Neal <bgneal@gmail.com> |
---|---|
date | Sat, 29 May 2010 04:51:28 +0000 |
parents | db202792d9f5 |
children | fe900598f81c |
comparison
equal
deleted
inserted
replaced
214:28988cce138b | 215:8c1832b9d815 |
---|---|
29 SplitTopicForm | 29 SplitTopicForm |
30 from forums.unread import get_forum_unread_status, get_topic_unread_status, \ | 30 from forums.unread import get_forum_unread_status, get_topic_unread_status, \ |
31 get_post_unread_status, get_unread_topics | 31 get_post_unread_status, get_unread_topics |
32 | 32 |
33 from bio.models import UserProfile | 33 from bio.models import UserProfile |
34 import antispam | |
35 import antispam.utils | |
36 | |
34 ####################################################################### | 37 ####################################################################### |
35 | 38 |
36 TOPICS_PER_PAGE = 50 | 39 TOPICS_PER_PAGE = 50 |
37 POSTS_PER_PAGE = 20 | 40 POSTS_PER_PAGE = 20 |
38 | 41 |
223 return HttpResponseForbidden() | 226 return HttpResponseForbidden() |
224 | 227 |
225 if request.method == 'POST': | 228 if request.method == 'POST': |
226 form = NewTopicForm(request.user, forum, request.POST) | 229 form = NewTopicForm(request.user, forum, request.POST) |
227 if form.is_valid(): | 230 if form.is_valid(): |
231 if antispam.utils.spam_check(request, form.cleaned_data['body']): | |
232 return HttpResponseRedirect(reverse('antispam-suspended')) | |
233 | |
228 topic = form.save(request.META.get("REMOTE_ADDR")) | 234 topic = form.save(request.META.get("REMOTE_ADDR")) |
229 _bump_post_count(request.user) | 235 _bump_post_count(request.user) |
230 return HttpResponseRedirect(reverse('forums-new_topic_thanks', | 236 return HttpResponseRedirect(reverse('forums-new_topic_thanks', |
231 kwargs={'tid': topic.pk})) | 237 kwargs={'tid': topic.pk})) |
232 else: | 238 else: |
265 | 271 |
266 form = NewPostForm(request.POST) | 272 form = NewPostForm(request.POST) |
267 if form.is_valid(): | 273 if form.is_valid(): |
268 if not _can_post_in_topic(form.topic, request.user): | 274 if not _can_post_in_topic(form.topic, request.user): |
269 return HttpResponseForbidden("You don't have permission to post in this topic.") | 275 return HttpResponseForbidden("You don't have permission to post in this topic.") |
276 if antispam.utils.spam_check(request, form.cleaned_data['body']): | |
277 return HttpResponseForbidden(antispam.BUSTED_MESSAGE) | |
270 | 278 |
271 post = form.save(request.user, request.META.get("REMOTE_ADDR", "")) | 279 post = form.save(request.user, request.META.get("REMOTE_ADDR", "")) |
272 post.unread = True | 280 post.unread = True |
273 post.user_profile = request.user.get_profile() | 281 post.user_profile = request.user.get_profile() |
274 _bump_post_count(request.user) | 282 _bump_post_count(request.user) |
340 return HttpResponseForbidden("You don't have permission to edit that post.") | 348 return HttpResponseForbidden("You don't have permission to edit that post.") |
341 | 349 |
342 if request.method == "POST": | 350 if request.method == "POST": |
343 form = PostForm(request.POST, instance=post) | 351 form = PostForm(request.POST, instance=post) |
344 if form.is_valid(): | 352 if form.is_valid(): |
353 if antispam.utils.spam_check(request, form.cleaned_data['body']): | |
354 return HttpResponseRedirect(reverse('antispam-suspended')) | |
345 post = form.save(commit=False) | 355 post = form.save(commit=False) |
346 post.touch() | 356 post.touch() |
347 post.save() | 357 post.save() |
348 return HttpResponseRedirect(post.get_absolute_url()) | 358 return HttpResponseRedirect(post.get_absolute_url()) |
349 else: | 359 else: |
460 | 470 |
461 if can_post: | 471 if can_post: |
462 if request.method == 'POST': | 472 if request.method == 'POST': |
463 form = PostForm(request.POST) | 473 form = PostForm(request.POST) |
464 if form.is_valid(): | 474 if form.is_valid(): |
475 if antispam.utils.spam_check(request, form.cleaned_data['body']): | |
476 return HttpResponseRedirect(reverse('antispam-suspended')) | |
465 post = form.save(commit=False) | 477 post = form.save(commit=False) |
466 post.topic = topic | 478 post.topic = topic |
467 post.user = request.user | 479 post.user = request.user |
468 post.user_ip = request.META.get("REMOTE_ADDR", "") | 480 post.user_ip = request.META.get("REMOTE_ADDR", "") |
469 post.save() | 481 post.save() |