Reputation: 6865
im trying moderation comment form the book of James Bennett, i think that all is fine, but the moderation comment is just for SPAM and the comments are public.. so , how ill put the comments always not public, i need that just the administrator can do public the comments.
Thanks
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)
Upvotes: 1
Views: 1240
Reputation: 7103
If you want to make all comments not public, except those sent by an administrator, then why not simply do just that in your moderate
function, e. g. something like:
def moderate(self, comment, content_object, request):
if comment.user and comment.user.is_staff: #or maybe is_superuser
return False
return True
If the user who sent the comment is a staff member (or whatever other requirements), return False
means the comment will not be moderated (e. g. is_public
will be set to True
), otherwise return True
means it will be moderated (e. g. is_public
set to False
until somebody set it to True
in the admin interface).
Upvotes: 0
Reputation: 10311
probably, altering the is_public field in the moderation function should do the trick
comment.is_public = False
Upvotes: 1