谢谢
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)
答案 0 :(得分:1)
可能,改变审核功能中的is_public字段应该做的伎俩
comment.is_public = False
答案 1 :(得分:0)
如果您想要公开所有评论(管理员发送的评论除外),那么为什么不在您的moderate
功能中执行此操作,例如: G。类似的东西:
def moderate(self, comment, content_object, request):
if comment.user and comment.user.is_staff: #or maybe is_superuser
return False
return True
如果发送评论的用户是工作人员(或其他任何要求),return False
表示评论不会被审核(例如is_public
将设置为True
) ,否则return True
表示它将被审核(例如is_public
设置为False
,直到有人在管理界面中将其设置为True
。