即時審判詹姆斯貝內特的書評論形式,我認爲一切都很好,但適度評論僅適用於垃圾郵件和評論是公開的。所以,多麼噁心總是把評論不公開,我需要的只是管理員可以公開評論。Django評論審查,不公開
感謝
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)
謝謝zalew,我現在這部分,問題是,這是不工作... – Asinox
*知道,但讓我試試somthing – Asinox