我正在尝试从 James Bennett 的书中进行审核评论,我认为一切都很好,但是审核评论仅适用于垃圾邮件,并且评论是公开的。所以,如何将评论始终不公开,我只需要管理员可以公开评论。
谢谢
import datetime
from Paso_a_Paso.akismet import Akismet
from django.conf import settings
from django.contrib.comments.models import Comment
from django.contrib.comments.signals import comment_will_be_posted
from django.contrib.sites.models import Site
from django.utils.encoding import smart_str
from django.contrib.comments.moderation import CommentModerator, moderator
class NoticiaModerator(CommentModerator):
auto_moderate_field= 'pub_date'
moderate_after = 30
email_notification = True
def moderate(self, comment, content_object, request):
already_moderated = super(NoticiaModerator,self).moderate(comment, content_object, request)
if already_moderated:
return True
akismet_api = Akismet(key=settings.AKISMET_API_KEY,blog_url="http:/%s/" %Site.objects.get_current().domain)
if akismet_api.verify_key():
akismet_data = {'comment_type': 'comment',
'referrer': request.META['HTTP_USER_AGENT'],
'user_ip': comment.ip_address,
'user_agent': request.META['HTTP_USER_AGENT']}
return akismet_api.comment_check(smart_str(comment.comment),
akismet_data,
build_data=True)
return False
moderator.register(Noticia, NoticiaModerator)