Задать вопрос

Тел: +7 965 3737 888





Unobtrusive comment moderation

<p><strong>Before using this snippet</strong>, please note that it's largely been superseded by <a href="http://code.google.com/p/django-comment-utils/">comment_utils</a>, 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.</p>
<p>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.</p>
<p>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:</p>
<ol><li>Grab the <a href="http://www.voidspace.org.uk/python/modules.shtml#akismet">Python Akismet module</a> and install it somewhere on your server.</li>
<li>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 <a href="http://wordpress.com/api-keys/">get one at wordpress.com</a>.</li>
<li>Put this code -- both the function and the dispatcher calls -- somewhere in your project that's <em>guaranteed</em> to be imported early (until this code is executed, the moderation function won't be set up to listen for comments posting).</li>
</ol><p>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.</p>

Вопрос полезен? Да0/Нет0

Ответы (4):

Ответ полезен? Да0/Нет0

The best place is in a models file or the __init__.py of an application.

Ответ полезен? Да0/Нет0

When you say

Put this code -- both the function and the dispatcher calls -- somewhere in your project that's guaranteed to be imported early

do you mean like somewhere (up high) in views.py?

Ответ полезен? Да0/Нет0


Just wanted to say that this is very useful. I love innovative applications of Django's signals!


Ответ полезен? Да0/Нет0

This is wonderful. I just learned about Django’s use of Signals today, and this is one of the first things to come to mind (after threading with the API calls I made earlier, of course).

I really like this function; it definitely seems like the cleanest way to do this.

I think it's also very similar to how the Askimet plugin for WordPress works.