After one or two months of online service i started getting few spams from the freecomments. Following b-list post i will make a step by step summary to add spam protection to free comment with Akismet.
API key
You need an akismet API key, for comments to be checked again the akismet database. Get it here, you will receive an email from wordpress with the key in it.
Akismet python
Get akismet python implementation, A zip file by Michael Foord of Voidspace. Download the zip file and only extract akismet.py.
Install Akismet
To install akismet.py move the file to your site-packages directory (/usr/lib/python2.4/) folder for linux. If you are using dreamhost and fcgi, go to your website folder (not the django one) and edit django.fcgi to add
sys.path += ['/home/yourlogin/afolder_where_akismet.py_is']
Edit your project settings.py and add the api key as follow.
AKISMET_API_KEY = "4weatc7b37b3"
Template
Check you comments.html template which diplay the comments, it has to check ispublic attribute since we will set ispublic to false if akismet detect the comment as spam.
{% for comment in comment_list %}
{% if comment.is_public %}
[...]
{% endif %}
{% endfor %}
comments.py
Edit django_src/django/contrib/comments/views/comments.py,
# add needed imports
from akismet import Akismet
from django.contrib.sites.models import Site
In the free_comment class section atound line 300, after errors = manipulator.get_validation_errors(new_data) add
# akismet check
ak_api = Akismet(key=settings.AKISMET_API_KEY, blog_url='http://%s/' % Site.objects.get(pk=settings.SITE_ID).domain)
if ak_api.verify_key():
ak_data = {
'user_ip': request.META.get('REMOTE_ADDR', '127.0.0.1'),
'user_agent': request.META.get('HTTP_USER_AGENT', ''),
'referrer': request.META.get('HTTP_REFERER', ''),
'comment_type': 'comment',
'comment_author': new_data.get('person_name', ''),
}
if ak_api.comment_check(new_data.get('comment', ''), data=ak_data, build_data=True):
new_data['is_public'] = False
else:
new_data['is_public'] = IS_PUBLIC in option_list
Feeds
If you also use comments feed, edit your feed.py and change this line:
#return FreeComment.objects.order_by('-submit_date',)[:5] to
return FreeComment.objects.filter(is_public = True).order_by('-submit_date',)[:5]
return FreeComment.objects.filter(is_public = True).order_by('-submit_date',)[:5]
Other changes you may need
Everywhere you were using FreeComment.objects, you need to add the filter(is_public = True). In my case it was in blog.py templatetags.
def render(self, context):
ctype = ContentType.objects.get(name='entry')
context['blog_comments'] = FreeComment.objects.filter(content_type=ctype.id, is_public = True).order_by('-submit_date')[:5]
return '
and blog models, with get_comment_count method.
def get_comment_count(self):
from django.contrib.contenttypes.models import ContentType
from django.contrib.comments.models import FreeComment
ctype = ContentType.objects.get(name__exact='entry')
num_comments = FreeComment.objects.filter(content_type=ctype.id, is_public = True, object_id=self.id).count()
return num_comments


6:11 p.m.
n1!
8:23 a.m.
Do you do any cleanup of spam comments, or do they remain in the database?
4:34 a.m.
Bob
8:29 p.m.
obviously my askimet use is broken, i stop comments for now.
2:48 a.m.
Jonny was here tight preteens hopmoh
4:26 p.m.
this is be cool 8) Suzanne Shaw Porn Video :(( Sopcast Adult Video Links >:P Toutube Porn 01247 Toutube Porn 8] Sex With Animal Free Videos 8894
4:48 p.m.
Gloomy tales Young Model Bbs 403 Pornhub Video petkp Young Loli Bbs 1653 Pornoamateurs Be wqtt Pornhost Tv 59653
1:02 a.m.
It's funny goodluck Pornic Seka %-]]] Porno Wiki iuls Pornhub Video =DDD Pornfree =-PPP Pornfree 8PPP
4:37 a.m.
I love this site X Tube >:) Tubeporn 99270 Tubeporn 134 Tv Porno Gratis >:-((( Watch Free Pokemon Episodes dfvx
1:14 p.m.
This site is crazy :) X Hampster Porn 9742 X Tube 409 X Tube =]] Watch Porn On Ipod Touch flp Tube8 Videos 959100 Xtube fwenh
11:04 p.m.
test spam
1:14 a.m.
Freextube 7463 Vogue Cover =-[
8:17 a.m.
It's serious Free Tube1 milnxj Freenudetube jdi
8:40 a.m.
magic story very thanks Free Eskimotube :D Zootube nnl
1:12 p.m.
Very funny pictures Tubetv vnla Free Redtube 2973
1:39 p.m.
Punk not dead Tube 8 Video >:-]]] Xtube vnim
5:38 p.m.
It's funny goodluck Tube8 Videos :-DDD Tube 8 Videos vgpf
8:13 p.m.
this is be cool 8) Freenudetube =D Mytube euq
8:28 a.m.
Good crew it's cool :)