Snippet List
Use this if you want to check if commenting is allowed for a certain object/model/... in a template. Like this;
`{% if not object.comments_allowed %}
<p>Comments are now closed.</p>
{% else %}
{% render_comment_form for object %}
{% endif %}`
You can replace the CommentModerator class with your own custom moderation class ofcourse.
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/
- akismet
- comments
- moderation
**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.
- akismet
- comments
- moderation
4 snippets posted so far.