当前位置: 首页>>代码示例>>Python>>正文


Python Topic.get_absolute_url方法代码示例

本文整理汇总了Python中pybb.models.Topic.get_absolute_url方法的典型用法代码示例。如果您正苦于以下问题:Python Topic.get_absolute_url方法的具体用法?Python Topic.get_absolute_url怎么用?Python Topic.get_absolute_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pybb.models.Topic的用法示例。


在下文中一共展示了Topic.get_absolute_url方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_hidden

# 需要导入模块: from pybb.models import Topic [as 别名]
# 或者: from pybb.models.Topic import get_absolute_url [as 别名]
    def test_hidden(self):
        client = Client()
        parent = Forum(name='hcat', hidden=True)
        parent.save()

        forum_in_hidden = Forum(name='in_hidden', forum=parent)
        forum_in_hidden.save()

        topic_in_hidden = Topic(forum=forum_in_hidden, name='in_hidden', user=self.user)
        topic_in_hidden.save()

        forum_hidden = Forum(name='hidden', forum=self.parent_forum, hidden=True)
        forum_hidden.save()

        topic_hidden = Topic(forum=forum_hidden, name='hidden', user=self.user)
        topic_hidden.save()

        post_hidden = Post(topic=topic_hidden, user=self.user, body='hidden')
        post_hidden.save()

        post_in_hidden = Post(topic=topic_in_hidden, user=self.user, body='hidden')
        post_in_hidden.save()

        self.assertFalse(parent.id in [c.id for c in client.get(reverse('pybb:index')).context['forums']])
        self.assertEqual(client.get(parent.get_absolute_url()).status_code, 302)
        self.assertEqual(client.get(forum_in_hidden.get_absolute_url()).status_code, 302)
        self.assertEqual(client.get(topic_in_hidden.get_absolute_url()).status_code, 302)

        self.assertNotContains(client.get(reverse('pybb:index')), forum_hidden.get_absolute_url())
        self.assertNotContains(client.get(reverse('pybb:feed_topics')), topic_hidden.get_absolute_url())
        self.assertNotContains(client.get(reverse('pybb:feed_topics')), topic_in_hidden.get_absolute_url())

        self.assertNotContains(client.get(reverse('pybb:feed_posts')), post_hidden.get_absolute_url())
        self.assertNotContains(client.get(reverse('pybb:feed_posts')), post_in_hidden.get_absolute_url())
        self.assertEqual(client.get(forum_hidden.get_absolute_url()).status_code, 302)
        self.assertEqual(client.get(topic_hidden.get_absolute_url()).status_code, 302)

        client.login(username='zeus', password='zeus')

        self.assertTrue(parent.id in [c.id for c in client.get(reverse('pybb:index')).context['forums']])

        self.assertContains(client.get(reverse('pybb:index')), forum_hidden.get_absolute_url())

        self.assertEqual(client.get(parent.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(forum_in_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(topic_in_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(forum_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(topic_hidden.get_absolute_url()).status_code, 200)
        self.user.is_staff = True
        self.user.save()
        self.assertTrue(parent.id in [c.id for c in client.get(reverse('pybb:index')).context['forums']])
        self.assertContains(client.get(reverse('pybb:index')), forum_hidden.get_absolute_url())

        self.assertEqual(client.get(parent.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(forum_in_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(topic_in_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(forum_hidden.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(topic_hidden.get_absolute_url()).status_code, 200)
开发者ID:thoas,项目名称:pybbm,代码行数:60,代码来源:test_features.py

示例2: test_read_tracking_multi_forum

# 需要导入模块: from pybb.models import Topic [as 别名]
# 或者: from pybb.models.Topic import get_absolute_url [as 别名]
    def test_read_tracking_multi_forum(self):
        self.post

        topic_1 = self.topic
        topic_2 = Topic(name='topic_2', forum=self.forum, user=self.user)
        topic_2.save()

        Post(topic=topic_2, user=self.user, body='one').save()

        forum_2 = Forum(name='forum_2', description='bar', forum=self.parent_forum)
        forum_2.save()

        Topic(name='garbage', forum=forum_2, user=self.user).save()

        self.login_as(self.user)

        #  everything starts unread
        self.assertEqual(ForumReadTracker.objects.count(), 0)
        self.assertEqual(TopicReadTracker.objects.count(), 0)

        #  user reads topic_1, they should get one topic read tracker, there should be no forum read trackers
        self.client.get(topic_1.get_absolute_url())
        self.assertEqual(TopicReadTracker.objects.count(), 1)
        self.assertEqual(TopicReadTracker.objects.filter(user=self.user).count(), 1)
        self.assertEqual(TopicReadTracker.objects.filter(user=self.user, topic=topic_1).count(), 1)

        #  user reads topic_2, they should get a forum read tracker,
        #  there should be no topic read trackers for the user
        self.client.get(topic_2.get_absolute_url())
        self.assertEqual(TopicReadTracker.objects.count(), 0)
        self.assertEqual(ForumReadTracker.objects.count(), 1)
        self.assertEqual(ForumReadTracker.objects.filter(user=self.user).count(), 1)
        self.assertEqual(ForumReadTracker.objects.filter(user=self.user, forum=self.forum).count(), 1)
开发者ID:thoas,项目名称:pybbm,代码行数:35,代码来源:test_trackers.py

示例3: test_topic_redirect_one_page

# 需要导入模块: from pybb.models import Topic [as 别名]
# 或者: from pybb.models.Topic import get_absolute_url [as 别名]
    def test_topic_redirect_one_page(self):
        topic = Topic(name='to-etopic', forum=self.forum, user=self.user)
        topic.save()

        response = self.client.get(reverse('pybb:topic_detail', kwargs={
            'forum_slug': self.forum.slug,
            'pk': topic.pk,
            'slug': topic.slug,
            'page': 1
        }))

        self.assertRedirects(response,
                             topic.get_absolute_url(),
                             301)
开发者ID:thoas,项目名称:pybbm,代码行数:16,代码来源:test_features.py

示例4: test_topic_redirect

# 需要导入模块: from pybb.models import Topic [as 别名]
# 或者: from pybb.models.Topic import get_absolute_url [as 别名]
    def test_topic_redirect(self):
        response = self.client.get(self.topic.get_absolute_url())
        self.assertEqual(response.status_code, 200)

        topic = Topic(name='to-etopic', forum=self.forum, user=self.user)
        topic.save()

        self.topic.redirect = True
        self.topic.save()

        redirection = TopicRedirection.objects.create(from_topic=self.topic, to_topic=topic)

        response = self.client.get(self.topic.get_absolute_url())

        self.assertRedirects(response, topic.get_absolute_url(), status_code=301)

        redirection.type = TopicRedirection.TYPE_NO_REDIRECT
        redirection.save()

        response = self.client.get(self.topic.get_absolute_url())

        self.assertEqual(response.status_code, 404)

        redirection.type = TopicRedirection.TYPE_EXPIRING_REDIRECT
        redirection.expired = date.today() + timedelta(days=1)
        redirection.save()

        response = self.client.get(self.topic.get_absolute_url())

        self.assertRedirects(response, topic.get_absolute_url())

        redirection.expired = date.today() - timedelta(days=1)
        redirection.save()

        response = self.client.get(self.topic.get_absolute_url())

        self.assertEqual(response.status_code, 404)
开发者ID:thoas,项目名称:pybbm,代码行数:39,代码来源:test_features.py

示例5: test_staff

# 需要导入模块: from pybb.models import Topic [as 别名]
# 或者: from pybb.models.Topic import get_absolute_url [as 别名]
    def test_staff(self):
        client = Client()
        parent = Forum(name='hcat', staff=True)
        parent.save()

        forum_in_staff = Forum(name='in_staff', forum=parent)
        forum_in_staff.save()

        topic_in_staff = Topic(forum=forum_in_staff, name='in_staff', user=self.user)
        topic_in_staff.save()

        forum_staff = Forum(name='staff', forum=self.parent_forum, staff=True)
        forum_staff.save()

        topic_staff = Topic(forum=forum_staff, name='staff', user=self.user)
        topic_staff.save()

        post_staff = Post(topic=topic_staff, user=self.user, body='staff')
        post_staff.save()

        post_in_staff = Post(topic=topic_in_staff, user=self.user, body='staff')
        post_in_staff.save()

        self.assertFalse(parent.id in [c.id for c in client.get(reverse('pybb:index')).context['forums']])
        self.assertEqual(client.get(parent.get_absolute_url()).status_code, 404)
        self.assertEqual(client.get(forum_in_staff.get_absolute_url()).status_code, 404)
        self.assertEqual(client.get(topic_in_staff.get_absolute_url()).status_code, 404)

        self.assertEqual(client.get(forum_staff.get_absolute_url()).status_code, 404)
        self.assertEqual(client.get(topic_staff.get_absolute_url()).status_code, 404)

        client.login(username='zeus', password='zeus')

        self.assertFalse(parent.id in [c.id for c in client.get(reverse('pybb:index')).context['forums']])

        self.assertNotContains(client.get(reverse('pybb:index')), forum_staff.get_absolute_url())

        self.assertEqual(client.get(parent.get_absolute_url()).status_code, 404)
        self.assertEqual(client.get(forum_in_staff.get_absolute_url()).status_code, 404)
        self.assertEqual(client.get(topic_in_staff.get_absolute_url()).status_code, 404)
        self.assertEqual(client.get(forum_staff.get_absolute_url()).status_code, 404)
        self.assertEqual(client.get(topic_staff.get_absolute_url()).status_code, 404)

        self.user.is_staff = True
        self.user.save()

        self.assertTrue(parent.id in [c.id for c in client.get(reverse('pybb:index')).context['forums']])

        self.assertEqual(client.get(parent.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(forum_in_staff.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(topic_in_staff.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(forum_staff.get_absolute_url()).status_code, 200)
        self.assertEqual(client.get(topic_staff.get_absolute_url()).status_code, 200)
开发者ID:thoas,项目名称:pybbm,代码行数:55,代码来源:test_features.py

示例6: test_read_tracking_multi_user

# 需要导入模块: from pybb.models import Topic [as 别名]
# 或者: from pybb.models.Topic import get_absolute_url [as 别名]
    def test_read_tracking_multi_user(self):
        self.post

        topic_1 = self.topic
        topic_2 = Topic(name='topic_2', forum=self.forum, user=self.user)
        topic_2.save()

        Post(topic=topic_2, user=self.user, body='one').save()

        user_ann = get_user_model().objects.create_user('ann', '[email protected]', 'ann')
        client_ann = Client()
        client_ann.login(username='ann', password='ann')

        user_bob = get_user_model().objects.create_user('bob', '[email protected]', 'bob')
        client_bob = Client()
        client_bob.login(username='bob', password='bob')

        #  Two topics, each with one post. everything is unread, so the db should reflect that:
        self.assertEqual(TopicReadTracker.objects.all().count(), 0)
        self.assertEqual(ForumReadTracker.objects.all().count(), 0)

        #  user_ann reads topic_1, she should get one topic read tracker, there should be no forum read trackers
        client_ann.get(topic_1.get_absolute_url())
        self.assertEqual(TopicReadTracker.objects.all().count(), 1)
        self.assertEqual(TopicReadTracker.objects.filter(user=user_ann).count(), 1)
        self.assertEqual(TopicReadTracker.objects.filter(user=user_ann, topic=topic_1).count(), 1)
        self.assertEqual(ForumReadTracker.objects.all().count(), 0)

        #  user_bob reads topic_1, he should get one topic read tracker, there should be no forum read trackers
        client_bob.get(topic_1.get_absolute_url())
        self.assertEqual(TopicReadTracker.objects.all().count(), 2)
        self.assertEqual(TopicReadTracker.objects.filter(user=user_bob).count(), 1)
        self.assertEqual(TopicReadTracker.objects.filter(user=user_bob, topic=topic_1).count(), 1)
        self.assertEqual(ForumReadTracker.objects.all().count(), 0)

        #  user_bob reads topic_2, he should get a forum read tracker,
        #  there should be no topic read trackers for user_bob
        client_bob.get(topic_2.get_absolute_url())
        self.assertEqual(TopicReadTracker.objects.all().count(), 1)
        self.assertEqual(ForumReadTracker.objects.all().count(), 1)
        self.assertEqual(ForumReadTracker.objects.filter(user=user_bob).count(), 1)
        self.assertEqual(ForumReadTracker.objects.filter(user=user_bob, forum=self.forum).count(), 1)

        #  user_ann creates topic_3, there should be a new topic read tracker in the db
        topic_create_url = reverse('pybb:topic_create', kwargs={'forum_id': self.forum.id})
        response = client_ann.get(topic_create_url)
        values = self.get_form_values(response)
        values['body'] = 'topic_3'
        values['name'] = 'topic_3'
        values['poll_type'] = 0
        response = client_ann.post(topic_create_url, data=values, follow=True)

        self.assertEqual(TopicReadTracker.objects.all().count(), 2)
        self.assertEqual(TopicReadTracker.objects.filter(user=user_ann).count(), 2)
        self.assertEqual(ForumReadTracker.objects.all().count(), 1)

        topic_3 = Topic.objects.order_by('-updated')[0]
        self.assertEqual(topic_3.name, 'topic_3')

        #  user_ann posts to topic_1, a topic they've already read, no new trackers should be created (existing one is updated)
        post_create_url = reverse('pybb:post_create', kwargs={'topic_id': topic_1.id})
        response = client_ann.get(post_create_url)
        values = self.get_form_values(response)
        values['body'] = 'test tracking'
        response = client_ann.post(post_create_url, values, follow=True)
        self.assertEqual(TopicReadTracker.objects.all().count(), 2)
        self.assertEqual(TopicReadTracker.objects.filter(user=user_ann).count(), 2)
        self.assertEqual(ForumReadTracker.objects.all().count(), 1)

        self.assertEqual(ForumReadTracker.objects.all().count(), 1)
        previous_time = ForumReadTracker.objects.all()[0].time_stamp

        # user bob reads topic 1 which he already read, topic tracker recreated, forum tracker untouched (topic 3 still unread)
        client_bob.get(topic_1.get_absolute_url())
        self.assertEqual(ForumReadTracker.objects.all().count(), 1)
        self.assertEqual(ForumReadTracker.objects.all()[0].time_stamp, previous_time)
        self.assertEqual(TopicReadTracker.objects.all().count(), 3)
        self.assertEqual(TopicReadTracker.objects.filter(user=user_bob).count(), 1)

        self.assertEqual(ForumReadTracker.objects.all().count(), 1)
        previous_time = ForumReadTracker.objects.all()[0].time_stamp

        # user bob reads topic 3, topic tracker purged, forum tracker updated
        client_bob.get(topic_3.get_absolute_url())
        self.assertEqual(ForumReadTracker.objects.all().count(), 1)
        self.assertGreater(ForumReadTracker.objects.all()[0].time_stamp, previous_time)
        self.assertEqual(TopicReadTracker.objects.all().count(), 2)
        self.assertEqual(TopicReadTracker.objects.filter(user=user_bob).count(), 0)
开发者ID:thoas,项目名称:pybbm,代码行数:90,代码来源:test_trackers.py


注:本文中的pybb.models.Topic.get_absolute_url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。