示例#1
0
    def test_comment_move_signal(self):
        """
        move comments, emit signal
        """
        self._comments = []

        def comment_posted_handler(sender, comment, **kwargs):
            self._comments.append(comment)
        comment_posted.connect(comment_posted_handler)

        def comment_moved_handler(sender, comments, topic_from, **kwargs):
            self._comment_count = len(comments)
            self._topic_from = topic_from
        comment_moved.connect(comment_moved_handler)

        utils.login(self)
        self.user.is_moderator = True
        self.user.save()

        comment = utils.create_comment(user=self.user, topic=self.topic)
        comment2 = utils.create_comment(user=self.user, topic=self.topic)
        to_topic = utils.create_topic(self.category)

        form_data = {'topic': to_topic.pk,
                     'comments': [comment.pk, comment2.pk], }
        response = self.client.post(reverse('spirit:comment-move', kwargs={'topic_id': self.topic.pk, }),
                                    form_data)
        self.assertEqual(response.status_code, 302)
        self.assertListEqual(self._comments, [comment2, comment])
        self.assertEqual(self._comment_count, 2)
        self.assertEqual(repr(self._topic_from), repr(self.topic))
示例#2
0
    def test_comment_publish_signal(self):
        """
        create comment signal
        """
        def comment_posted_handler(sender, comment, **kwargs):
            self._comment = comment
        comment_posted.connect(comment_posted_handler)

        utils.login(self)
        form_data = {'comment': 'foobar', }
        self.client.post(reverse('spirit:comment-publish', kwargs={'topic_id': self.topic.pk, }), form_data)
        self.assertEqual(self._comment.comment, 'foobar')
示例#3
0
    def test_comment_publish_signal(self):
        """
        create comment signal
        """
        def comment_posted_handler(sender, comment, **kwargs):
            self._comment = comment
        comment_posted.connect(comment_posted_handler)

        utils.login(self)
        form_data = {'comment': 'foobar', }
        response = self.client.post(reverse('spirit:comment-publish', kwargs={'topic_id': self.topic.pk, }),
                                    form_data)
        self.assertEqual(self._comment.comment, 'foobar')
示例#4
0
    def test_topic_publish_comment_posted_signals(self):
        """
        send publish_comment_posted signal
        """
        def comment_posted_handler(sender, comment, **kwargs):
            self._comment = repr(comment)
        comment_posted.connect(comment_posted_handler)

        utils.login(self)

        category = utils.create_category()
        form_data = {'title': 'foobar', 'category': category.pk, 'comment': 'foo',
                     'choices-TOTAL_FORMS': 2, 'choices-INITIAL_FORMS': 0, 'choice_limit': 1}
        response = self.client.post(reverse('spirit:topic-publish'),
                                    form_data)
        self.assertEqual(response.status_code, 302)
        comment = Comment.objects.last()
        self.assertEqual(self._comment, repr(comment))
示例#5
0
    def test_comment_move_signal(self):
        """
        move comments, emit signal
        """
        self._comments = []

        def comment_posted_handler(sender, comment, **kwargs):
            self._comments.append(comment)

        comment_posted.connect(comment_posted_handler)

        def comment_moved_handler(sender, comments, topic_from, **kwargs):
            self._comment_count = len(comments)
            self._topic_from = topic_from

        comment_moved.connect(comment_moved_handler)

        utils.login(self)
        self.user.is_moderator = True
        self.user.save()

        comment = utils.create_comment(user=self.user, topic=self.topic)
        comment2 = utils.create_comment(user=self.user, topic=self.topic)
        to_topic = utils.create_topic(self.category)

        form_data = {
            'topic': to_topic.pk,
            'comments': [comment.pk, comment2.pk],
        }
        response = self.client.post(
            reverse('spirit:comment-move',
                    kwargs={
                        'topic_id': self.topic.pk,
                    }), form_data)
        self.assertEqual(response.status_code, 302)
        self.assertListEqual(self._comments, [comment2, comment])
        self.assertEqual(self._comment_count, 2)
        self.assertEqual(repr(self._topic_from), repr(self.topic))
示例#6
0
    def test_topic_publish_comment_posted_signals(self):
        """
        send publish_comment_posted signal
        """
        def comment_posted_handler(sender, comment, **kwargs):
            self._comment = repr(comment)

        comment_posted.connect(comment_posted_handler)

        utils.login(self)

        category = utils.create_category()
        form_data = {
            'title': 'foobar',
            'category': category.pk,
            'comment': 'foo',
            'choices-TOTAL_FORMS': 2,
            'choices-INITIAL_FORMS': 0,
            'choice_limit': 1
        }
        response = self.client.post(reverse('spirit:topic-publish'), form_data)
        self.assertEqual(response.status_code, 302)
        comment = Comment.objects.last()
        self.assertEqual(self._comment, repr(comment))
示例#7
0
        verbose_name = _("topic unread")
        verbose_name_plural = _("topics unread")

    def get_absolute_url(self):
        return self.topic.get_absolute_url()

    def __unicode__(self):
        return "%s read %s" % (self.user, self.topic)


def topic_page_viewed_handler(sender, request, topic, **kwargs):
    if not request.user.is_authenticated():
        return

    # TODO: use update_or_create on django 1.7
    try:
        TopicUnread.objects.create(user=request.user, topic=topic)
    except IntegrityError:
        TopicUnread.objects.filter(user=request.user, topic=topic)\
            .update(is_read=True)


def comment_posted_handler(sender, comment, **kwargs):
    TopicUnread.objects.filter(topic=comment.topic)\
        .exclude(user=comment.user)\
        .update(is_read=False, date=timezone.now())


topic_viewed.connect(topic_page_viewed_handler, dispatch_uid=__name__)
comment_posted.connect(comment_posted_handler, dispatch_uid=__name__)
示例#8
0
        [
            TopicNotification(user=tp.user, topic=tp.topic, comment=comment, action=COMMENT, is_active=True)
            for tp in topics_private
            if tp.user != tp.topic.user
        ]
    )


def topic_private_access_pre_create_handler(sender, topic, user, **kwargs):
    # TODO: use update_or_create on django 1.7
    # change to post create
    try:
        TopicNotification.objects.create(
            user=user, topic=topic, comment=topic.comment_set.last(), action=COMMENT, is_active=True
        )
    except IntegrityError:
        pass


def topic_viewed_handler(sender, request, topic, **kwargs):
    if not request.user.is_authenticated():
        return

    TopicNotification.objects.filter(user=request.user, topic=topic).update(is_read=True)


comment_posted.connect(comment_posted_handler, dispatch_uid=__name__)
topic_private_post_create.connect(topic_private_post_create_handler, dispatch_uid=__name__)
topic_private_access_pre_create.connect(topic_private_access_pre_create_handler, dispatch_uid=__name__)
topic_viewed.connect(topic_viewed_handler, dispatch_uid=__name__)
示例#9
0
        .exclude(user=comment.user)
    quote_url = reverse('spirit:comment-publish', kwargs={'topic_id': topic.id,
                                                          'pk': comment.id})

    body_context = {
        'comment': comment,
        'quote_url': quote_url,
        'domain': settings.DOMAIN
    }
    done_emails = set()
    body = render_to_string('spirit_email_notification/new_comment.html', body_context)
    for notif in notifications:
        send_mail('EoC Comment. {}'.format(topic.title),
                  body, settings.DEFAULT_FROM_EMAIL,
                  [notif.user.email])
        done_emails.add(notif.user.email)

    body_ment = render_to_string('spirit_email_notification/mention.html', body_context)
    for user in mentions.values():
        if comment.user == user:
            continue
        if user.email in done_emails:
            continue
        send_mail('EoC Mention. {}'.format(topic.title),
                  body_ment, settings.DEFAULT_FROM_EMAIL,
                  [user.email])
        done_emails.add(user.email)


comment_posted.connect(send_notification, dispatch_uid=__name__)