开发者

How to automatically accept comments from authenticated users in django.contrib.comments

Is there a way to make Django automatically set the is_public field of the 开发者_Go百科comment as True.

I only allow comments for registered users and would like to skip manual review of comments posted.


The built in comments form should already set every comment to have is_public=True. See CommentDetailsForm.get_comment_create_data in http://code.djangoproject.com/browser/django/trunk/django/contrib/comments/forms.py

If you want to change this for logged in vs not logged in users, take a look at the built in comment moderation docs: http://docs.djangoproject.com/en/1.1/ref/contrib/comments/moderation/#ref-contrib-comments-moderation

You can write your own moderator which checks the comment to see if the comment.user is set and if it is do not moderate (is_public=True) otherwise set is_public=False.


overwrite the comments-form save-method, and set is_public to True


OK if anyone is looking for the answer for this, this is how I solved it:

# in models.py:
import datetime
def moderate_comment(sender, instance, **kwargs):
    if not instance.id:
        instance.is_public = True
from django.contrib.comments.models import Comment
from django.db.models import signals

signals.pre_save.connect(moderate_comment, sender=Comment)


Overriding the moderate of CommentModerator works for me:

from django.contrib.comments.moderation import CommentModerator

class EntryModerator(CommentModerator):
    # [...]

    def moderate(self, comment, content_object, request):
        # If the user who commented is a staff member, don't moderate
        if comment.user and comment.user.is_staff:
            return False
        else:
            return True
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜