Clean spam from comments by running management command and akismet
..
- akismet
- spam
- comments
- command
..
This is a rewrite of [snippet #1006](http://www.djangosnippets.org/snippets/1006/) to use the moderation features available in Django's comments framework. This is more customizable than the signals approach and works well if other moderation features are being used. If you want to make comments that are flagged as spam become hidden instead of deleted, change the allow() method to moderate(). [See the blog post here](http://sciyoshi.com/blog/2009/jul/17/prevent-django-newcomments-spam-akismet-reloaded/)
This is the "unobtrusive comments moderation" code from http://www.djangosnippets.org/snippets/112/ , but updated so it works properly with Django 1.0. There are only a few small changes reflecting changes in the comments, contenttypes, and signals APIs. For full background, see the original snippet: http://www.djangosnippets.org/snippets/112/
http://sciyoshi.com/blog/2008/aug/27/using-akismet-djangos-new-comments-framework/
See the description in the blog entry at [http://sciyoshi.com/blog/2008/aug/27/using-akismet-djangos-new-comments-framework/](http://sciyoshi.com/blog/2008/aug/27/using-akismet-djangos-new-comments-framework/)
This is an extension to ubernostrum's [comment-utils](http://code.google.com/p/django-comment-utils/) that performs comment moderation based on LinkSleeve check result. It requires original comment-utils package.
**Before using this snippet**, please note that it's largely been superseded by [comment_utils](http://code.google.com/p/django-comment-utils/), which includes a more featureful and extensible version of this system, particularly with respect to additional moderation options and useful things like email notifications of comments. Once upon a time I hacked the copy of `django.contrib.comments` I'm using on my blog, so that I could have comments get set to `is_public=False` if posted more than 30 days after the entry's publication, and to add Akismet spam filtering. I've regretted it ever since, because it's made upgrading my copy of Django a pain. So here's an improved version which doesn't require hacking directly on Django. To use it, you'll need to do a few things: 1. Grab the [Python Akismet module](http://www.voidspace.org.uk/python/modules.shtml#akismet) and install it somewhere on your server. 2. In your settings file, add `AKISMET_API_KEY`, and make sure its value is a valid Akismet key. If you don't have an Akismet key, you can [get one at wordpress.com](http://wordpress.com/api-keys/). 3. Put this code -- both the function and the dispatcher calls -- somewhere in your project that's _guaranteed_ to be imported early (until this code is executed, the moderation function won't be set up to listen for comments posting). To have comments on a certain type of object (say, weblog entries) automatically go into moderation when the object reaches a certain age, define a method on that object's model called `comments_open`, and have it return `False` when comments should be auto-moderated.
A short little bit of code to test for comment spam against Akimet. Use: a = Akismet('<AkismetKey>', 'http://sneeu.com/blog/') a.verify_key() print a.comment_check( comment_author='...', comment_author_email='[email protected]', user_ip='10.0.0.1', comment_content="""Comment content!""" )
8 snippets posted so far.