# HG changeset patch # User Steve Losh # Date 1232772667 18000 # Node ID bfa2c0882ce64fbfa3e4dadf30a050d946ba300d # Parent 9a43a0ef26024cce016049e1a62860a06ff98b37 Added Akismet spam filtering for comments. diff -r 9a43a0ef2602 -r bfa2c0882ce6 blog/views.py --- a/blog/views.py Fri Jan 23 23:02:53 2009 -0500 +++ b/blog/views.py Fri Jan 23 23:51:07 2009 -0500 @@ -3,8 +3,10 @@ from django.shortcuts import get_object_or_404, render_to_response from django.http import HttpResponseRedirect, HttpResponsePermanentRedirect from django.core.urlresolvers import reverse +from akismet import Akismet +import deploy - +ak = Akismet(deploy.AKISMET_API_KEY, blog_url='http://stevelosh.com/') ENTRIES_PER_PAGE = 10 def entry(request, year, month, day, slug): @@ -34,11 +36,25 @@ fields = request.POST entry = Entry.objects.get(pk=fields['entry-id']) - if ( fields.has_key('name') and (not fields['name'].strip() == '') and - fields.has_key('body') and not fields['body'].strip() == ''): + if ( fields.has_key('name') and + not fields['name'].strip() == '' and + not len(fields['name']) < 3 and + fields.has_key('body') and + not fields['body'].strip() == '' and + not len(fields['body']) < 3 and + not len(fields['body']) > 15000): + + akismet_data = {} + akismet_data['user_ip'] = request.META['REMOTE_ADDR'] + akismet_data['user_agent'] = request.META['HTTP_USER_AGENT'] + akismet_data['comment_author'] = fields['name'] + akismet_data['comment_type'] ='comment' + spam = ak.comment_check(fields['body'], akismet_data) + new_comment = Comment(name=fields['name'], body=fields['body'], - entry=entry) + entry=entry, + spam=spam) new_comment.save() return HttpResponseRedirect(reverse('stevelosh.blog.views.entry', diff -r 9a43a0ef2602 -r bfa2c0882ce6 deploy-template.py --- a/deploy-template.py Fri Jan 23 23:02:53 2009 -0500 +++ b/deploy-template.py Fri Jan 23 23:51:07 2009 -0500 @@ -18,3 +18,5 @@ # This is used for the Mint (http://haveamint.com/) Bird Feeder plugin hack. FEEDER_PASSWORD = '' + +AKISMET_API_KEY = '' diff -r 9a43a0ef2602 -r bfa2c0882ce6 projects/views.py --- a/projects/views.py Fri Jan 23 23:02:53 2009 -0500 +++ b/projects/views.py Fri Jan 23 23:51:07 2009 -0500 @@ -3,8 +3,12 @@ from django.shortcuts import render_to_response, get_object_or_404 from django.http import HttpResponseRedirect from django.core.urlresolvers import reverse +from akismet import Akismet +import deploy +ak = Akismet(deploy.AKISMET_API_KEY, blog_url='http://stevelosh.com/') + def project(request, slug): project = get_object_or_404(Project, slug=slug) comments = project.comment_set.filter(spam=False).order_by('submitted') @@ -27,9 +31,18 @@ not fields['body'].strip() == '' and not len(fields['body']) < 3 and not len(fields['body']) > 15000): + + akismet_data = {} + akismet_data['user_ip'] = request.META['REMOTE_ADDR'] + akismet_data['user_agent'] = request.META['HTTP_USER_AGENT'] + akismet_data['comment_author'] = fields['name'] + akismet_data['comment_type'] ='comment' + spam = ak.comment_check(fields['body'], akismet_data) + new_comment = Comment(name=fields['name'], body=fields['body'], - project=project) + project=project, + spam=spam) new_comment.save() return HttpResponseRedirect(reverse('stevelosh.projects.views.project',