| commit 73: | d3fe3f5eb724 |
| parent 72: | f3fc7756344c |
| branch: | default |
Killing spammers, round two
18 months ago
Changed (Δ1.1 KB):
raw changeset »
discussion/__init__.py (17 lines added, 0 lines removed)
Up to file-list discussion/__init__.py:
1 |
# -*- coding: utf-8 -*- |
|
2 |
from django.conf import settings |
|
3 |
from django.core.mail import send_mail |
|
4 |
from django.core.urlresolvers import reverse |
|
1 |
5 |
from django.db.models.signals import post_save, post_delete |
2 |
6 |
from django.contrib.comments import get_model, get_form_target |
3 |
7 |
from django.contrib.comments.models import Comment |
8 |
from django.contrib.comments.signals import comment_was_posted |
|
4 |
9 |
|
5 |
10 |
def get_form(): |
6 |
11 |
from discussion.forms import CommentForm |
| … | … | @@ -10,5 +15,17 @@ def denormalize_comments_count(sender, i |
10 |
15 |
"""This recalculates the comment total for the object being commented on""" |
11 |
16 |
instance.content_object.compute_nb_comments() |
12 |
17 |
|
18 |
def inactivate_comments_with_too_many_http(sender, **kwargs): |
|
19 |
comment = kwargs["comment"] |
|
20 |
if 'http://' in comment.comment and not ('biologeek.com' in comment.comment or 'David, biologeek' in comment.user_name): |
|
21 |
comment.is_public = False |
|
22 |
comment.save() |
|
23 |
subject = u'Modération du commentaire de %s au sujet de %s' % (comment.user_name, comment.content_object.title) |
|
24 |
message = u'De : %s (%s)\n %s\n\nCommentaire :\n%s\n\n' % (comment.user_name, comment.user_email,comment.user_url, comment.comment) |
|
25 |
message += u'URL de modération : http://www.biologeek.com%s' % (reverse('admin_%s_%s_change' % (comment._meta.app_label, comment._meta.module_name), args=[comment.id])) |
|
26 |
send_mail(subject, message, settings.SERVER_EMAIL, [email for (name, email) in settings.ADMINS], fail_silently=True) |
|
27 |
||
28 |
||
13 |
29 |
post_save.connect(denormalize_comments_count, sender=Comment) |
14 |
30 |
post_delete.connect(denormalize_comments_count, sender=Comment) |
31 |
comment_was_posted.connect(inactivate_comments_with_too_many_http, sender=Comment) |
