示例#1
0
 def test_topic_page_viewed_handler(self):
     """
     topic_page_viewed_handler signal
     """
     req = RequestFactory().get('/')
     req.user = self.user
     topic_viewed.send(sender=self.topic.__class__, request=req, topic=self.topic)
     self.assertEqual(Topic.objects.get(pk=self.topic.pk).view_count, 1)
示例#2
0
 def test_comment_bookmark_topic_page_viewed_handler_invalid_page(self):
     """
     invalid page
     """
     page = 'im_a_string'
     req = RequestFactory().get('/', data={'page': str(page), })
     req.user = self.user
     topic_viewed.send(sender=self.topic.__class__, topic=self.topic, request=req)
     self.assertEqual(len(CommentBookmark.objects.all()), 0)
示例#3
0
 def test_topic_page_viewed_handler(self):
     """
     topic_page_viewed_handler signal
     """
     req = RequestFactory().get('/')
     req.user = self.user
     topic_viewed.send(sender=self.topic.__class__,
                       request=req,
                       topic=self.topic)
     self.assertEqual(Topic.objects.get(pk=self.topic.pk).view_count, 1)
示例#4
0
 def test_comment_bookmark_topic_page_viewed_handler(self):
     """
     topic_page_viewed_handler signal
     """
     page = 2
     req = RequestFactory().get('/', data={'page': str(page), })
     req.user = self.user
     topic_viewed.send(sender=self.topic.__class__, topic=self.topic, request=req)
     comment_bookmark = CommentBookmark.objects.get(user=self.user, topic=self.topic)
     self.assertEqual(comment_bookmark.comment_number, config.comments_per_page * (page - 1) + 1)
示例#5
0
文件: topic.py 项目: 0sw4l/devhunter
def topic_detail(request, pk, slug):
    topic = Topic.objects.get_public_or_404(pk, request.user)

    if topic.slug != slug:
        return HttpResponsePermanentRedirect(topic.get_absolute_url())

    topic_viewed.send(sender=topic.__class__, request=request, topic=topic)

    return render(request, 'spirit/topic/topic_detail.html', {'topic': topic,
                                                              'COMMENTS_PER_PAGE': settings.ST_COMMENTS_PER_PAGE})
示例#6
0
def private_detail(request, topic_id, slug):
    topic_private = get_object_or_404(TopicPrivate.objects.select_related('topic'),
                                      topic_id=topic_id, user=request.user)

    if topic_private.topic.slug != slug:
        return HttpResponsePermanentRedirect(topic_private.get_absolute_url())

    topic_viewed.send(sender=topic_private.topic.__class__, request=request, topic=topic_private.topic)

    return render(request, 'spirit/topic_private/private_detail.html', {'topic': topic_private.topic,
                                                                        'topic_private': topic_private,
                                                                        'COMMENTS_PER_PAGE': settings.ST_COMMENTS_PER_PAGE})
示例#7
0
文件: topic.py 项目: gone/Spirit
def topic_detail(request, pk, slug):
    topic = Topic.objects.get_public_or_404(pk, request.user)

    if topic.slug != slug:
        return HttpResponsePermanentRedirect(topic.get_absolute_url())

    topic_viewed.send(sender=topic.__class__, request=request, topic=topic)

    return render(request, 'spirit/topic/topic_detail.html', {
        'topic': topic,
        'COMMENTS_PER_PAGE': settings.ST_COMMENTS_PER_PAGE
    })
 def test_topic_viewed_handler(self):
     """
     mark notification as read when the user visits the topic
     """
     req = RequestFactory().get('/')
     req.user = self.user
     private = utils.create_private_topic()
     TopicNotification.objects.create(user=private.user, topic=private.topic, is_read=False)
     topic_viewed.send(sender=private.__class__,
                       topic=private.topic,
                       request=req)
     notification = TopicNotification.objects.get(user=private.user, topic=private.topic)
     self.assertFalse(notification.is_read)
示例#9
0
    def test_topic_unread_create_or_read_handler(self):
        """
        create or read when visiting topic
        """
        req = RequestFactory().get('/')
        req.user = self.user
        TopicUnread.objects.all().update(is_read=False)
        topic_viewed.send(sender=self.topic.__class__, request=req, topic=self.topic)
        self.assertTrue(TopicUnread.objects.get(user=self.user, topic=self.topic).is_read)

        req.user = self.user2
        topic_viewed.send(sender=self.topic.__class__, request=req, topic=self.topic)
        self.assertEqual(len(TopicUnread.objects.filter(user=self.user2, topic=self.topic)), 1)
        self.assertTrue(TopicUnread.objects.get(user=self.user2, topic=self.topic).is_read)
示例#10
0
 def test_topic_viewed_handler(self):
     """
     mark notification as read when the user visits the topic
     """
     req = RequestFactory().get('/')
     req.user = self.user
     private = utils.create_private_topic()
     TopicNotification.objects.create(user=private.user,
                                      topic=private.topic,
                                      is_read=False)
     topic_viewed.send(sender=private.__class__,
                       topic=private.topic,
                       request=req)
     notification = TopicNotification.objects.get(user=private.user,
                                                  topic=private.topic)
     self.assertFalse(notification.is_read)
示例#11
0
    def test_topic_unread_create_or_read_handler(self):
        """
        create or read when visiting topic
        """
        req = RequestFactory().get('/')
        req.user = self.user
        TopicUnread.objects.all().update(is_read=False)
        topic_viewed.send(sender=self.topic.__class__,
                          request=req,
                          topic=self.topic)
        self.assertTrue(
            TopicUnread.objects.get(user=self.user, topic=self.topic).is_read)

        req.user = self.user2
        topic_viewed.send(sender=self.topic.__class__,
                          request=req,
                          topic=self.topic)
        self.assertEqual(
            len(TopicUnread.objects.filter(user=self.user2, topic=self.topic)),
            1)
        self.assertTrue(
            TopicUnread.objects.get(user=self.user2, topic=self.topic).is_read)