1
from django.db.models import signals
2
from threadedcomments.models import ThreadedComment, MARKUP_CHOICES
3
from threadedcomments.models import DEFAULT_MAX_COMMENT_LENGTH, DEFAULT_MAX_COMMENT_DEPTH
4
from comment_utils import moderation
6
MARKUP_CHOICES_IDS = [c[0] for c in MARKUP_CHOICES]
9
class CommentModerator(moderation.CommentModerator):
10
max_comment_length = DEFAULT_MAX_COMMENT_LENGTH
11
allowed_markup = MARKUP_CHOICES_IDS
12
max_depth = DEFAULT_MAX_COMMENT_DEPTH
14
def _is_past_max_depth(self, comment):
20
if i > self.max_depth:
24
def allow(self, comment, content_object):
25
if self._is_past_max_depth(comment):
27
if comment.markup not in self.allowed_markup:
29
return super(CommentModerator, self).allow(comment, content_object)
31
def moderate(self, comment, content_object):
32
if len(comment.comment) > self.max_comment_length:
34
return super(CommentModerator, self).moderate(comment, content_object)
37
class Moderator(moderation.Moderator):
40
signals.pre_save.connect(self.pre_save_moderation, sender=ThreadedComment)
41
signals.post_save.connect(self.post_save_moderation, sender=ThreadedComment)
43
# THE FOLLOWING ARE HACKS UNTIL django-comment-utils GETS UPDATED SIGNALS
45
def pre_save_moderation(self, sender=None, instance=None, **kwargs):
46
return super(Moderator, self).pre_save_moderation(sender, instance)
48
def post_save_moderation(self, sender=None, instance=None, **kwargs):
49
return super(Moderator, self).post_save_moderation(sender, instance)
52
# Instantiate the ``Moderator`` so that other modules can import and
53
# begin to register with it.
55
moderator = Moderator()