1
from django.db.models import signals
2
from threadedcomments.models import ThreadedComment, FreeThreadedComment, 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)
36
class Moderator(moderation.Moderator):
38
for model in (ThreadedComment, FreeThreadedComment):
39
signals.pre_save.connect(self.pre_save_moderation, sender=model)
40
signals.post_save.connect(self.post_save_moderation, sender=model)
42
## THE FOLLOWING ARE HACKS UNTIL django-comment-utils GETS UPDATED SIGNALS ####
43
def pre_save_moderation(self, sender=None, instance=None, **kwargs):
44
return super(Moderator, self).pre_save_moderation(sender, instance)
46
def post_save_moderation(self, sender=None, instance=None, **kwargs):
47
return super(Moderator, self).post_save_moderation(sender, instance)
50
# Instantiate the ``Moderator`` so that other modules can import and
51
# begin to register with it.
53
moderator = Moderator()
b'\\ No newline at end of file'