Пример #1
0
    def test_topic_detail_view_signals(self):
        """
        send topic view signal
        """
        def topic_viewed_handler(sender, request, topic, **kwargs):
            self._viewed = [
                request,
                repr(topic),
            ]

        topic_viewed.connect(topic_viewed_handler)

        utils.login(self)

        category = utils.create_category()
        topic = utils.create_topic(category=category, user=self.user)
        response = self.client.get(
            reverse('spirit:topic-detail',
                    kwargs={
                        'pk': topic.pk,
                        'slug': topic.slug
                    }))
        self.assertEqual(response.status_code, 200)
        self.assertSequenceEqual(self._viewed,
                                 [response.context['request'],
                                  repr(topic)])
Пример #2
0
    def test_topic_detail_view_signals(self):
        """
        send topic view signal
        """
        def topic_viewed_handler(sender, request, topic, **kwargs):
            self._viewed = [request, repr(topic), ]
        topic_viewed.connect(topic_viewed_handler)

        utils.login(self)

        category = utils.create_category()
        topic = utils.create_topic(category=category, user=self.user)
        response = self.client.get(reverse('spirit:topic-detail', kwargs={'pk': topic.pk, 'slug': topic.slug}))
        self.assertEqual(response.status_code, 200)
        self.assertSequenceEqual(self._viewed, [response.context['request'], repr(topic)])
Пример #3
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__)
Пример #4
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__)