本文整理汇总了Python中pybb.models.Topic.mark_as_deleted方法的典型用法代码示例。如果您正苦于以下问题:Python Topic.mark_as_deleted方法的具体用法?Python Topic.mark_as_deleted怎么用?Python Topic.mark_as_deleted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybb.models.Topic
的用法示例。
在下文中一共展示了Topic.mark_as_deleted方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_compute
# 需要导入模块: from pybb.models import Topic [as 别名]
# 或者: from pybb.models.Topic import mark_as_deleted [as 别名]
def test_compute(self):
# initials
self.assertEqual(self.forum.forum_count, 0)
self.assertEqual(self.parent_forum.forum_count, 1)
self.topic
self.post
parent_forum = Forum.objects.get(pk=self.parent_forum.pk)
self.assertEqual(parent_forum.topic_count, 1)
self.assertEqual(parent_forum.post_count, 1)
self.assertEqual(self.forum.topic_count, 1)
self.assertEqual(self.forum.post_count, 1)
forum = Forum.objects.create(name='bar', description='bar', forum=self.forum)
topic = Topic(name='bar', forum=forum, user=self.user)
topic.save()
post = Post(topic=topic, user=self.user, body='my new post')
post.save()
self.assertEqual(topic.post_count, 1)
self.assertEqual(forum.topic_count, 1)
self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 2)
self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 2)
new_topic = Topic(name='foo', forum=self.forum, user=self.user)
new_topic.save()
new_post = Post(topic=topic, user=self.user, body='my new post')
new_post.save()
self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 3)
self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 3)
post.mark_as_deleted(commit=True)
self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 2)
self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 2)
self.assertTrue(Topic.objects.get(pk=topic.pk).deleted)
self.assertEqual(Forum.objects.get(pk=forum.pk).topic_count, 0)
self.assertEqual(Forum.objects.get(pk=forum.pk).post_count, 0)
new_topic.mark_as_deleted()
self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 1)
self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 1)
示例2: test_compute
# 需要导入模块: from pybb.models import Topic [as 别名]
# 或者: from pybb.models.Topic import mark_as_deleted [as 别名]
def test_compute(self):
# initials
self.assertEqual(self.forum.forum_count, 0)
self.assertEqual(self.parent_forum.forum_count, 1)
self.topic
self.post
parent_forum = Forum.objects.get(pk=self.parent_forum.pk)
self.assertEqual(parent_forum.topic_count, 1)
self.assertEqual(parent_forum.post_count, 1)
self.assertEqual(self.forum.topic_count, 1)
self.assertEqual(self.forum.post_count, 1)
# Add (forum --> topic --> post) in self.forum
forum = Forum.objects.create(name='bar', description='bar', forum=self.forum)
topic = Topic(name='bar', forum=forum, user=self.user)
topic.save()
post = Post(topic=topic, user=self.user, body='my new post')
post.save()
self.assertEquals(Topic.objects.get(pk=topic.pk).first_post, post)
self.assertEqual(topic.post_count, 1)
self.assertEqual(forum.topic_count, 1)
self.assertEqual(Forum.objects.get(pk=self.forum.pk).post_count, 2)
self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 2)
self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).post_count, 2)
self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 2)
# Add (topic --> post) in self.forum
new_topic = Topic(name='foo', forum=self.forum, user=self.user)
new_topic.save()
new_post = Post(topic=new_topic, user=self.user, body='my new post')
new_post.save()
self.assertEquals(Topic.objects.get(pk=new_topic.pk).first_post, new_post)
self.assertEqual(Forum.objects.get(pk=self.forum.pk).post_count, 3)
self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 3)
self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).post_count, 3)
self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 3)
# delete post in (self.parent_forum --> self.forum --> forum --> topic)
post.mark_as_deleted(commit=True)
self.assertTrue(Topic.objects.get(pk=topic.pk).deleted)
self.assertEquals(Topic.objects.get(pk=topic.pk).first_post, post)
self.assertTrue(Topic.objects.get(pk=topic.pk).first_post.deleted)
self.assertEqual(Forum.objects.get(pk=forum.pk).topic_count, 0)
self.assertEqual(Forum.objects.get(pk=forum.pk).post_count, 0)
self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 2)
self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 2)
# delete new_topic in (self.parent_forum --> self.forum)
new_topic.mark_as_deleted()
self.assertTrue(Topic.objects.get(pk=new_topic.pk).deleted)
self.assertEquals(Topic.objects.get(pk=new_topic.pk).first_post, new_post)
self.assertTrue(Topic.objects.get(pk=new_topic.pk).first_post.deleted)
self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 1)
self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 1)
# undelete new_topic in (self.parent_forum --> self.forum)
new_topic.mark_as_undeleted()
self.assertFalse(Topic.objects.get(pk=new_topic.pk).deleted)
self.assertEquals(Topic.objects.get(pk=new_topic.pk).first_post, new_post)
self.assertFalse(Topic.objects.get(pk=new_topic.pk).first_post.deleted)
self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 2)
self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 2)
# undelete post in (self.parent_forum --> self.forum --> forum --> topic)
post.mark_as_undeleted(commit=True)
self.assertFalse(Topic.objects.get(pk=topic.pk).deleted)
self.assertEquals(Topic.objects.get(pk=topic.pk).first_post, post)
self.assertFalse(Topic.objects.get(pk=topic.pk).first_post.deleted)
self.assertEqual(Forum.objects.get(pk=forum.pk).post_count, 1)
self.assertEqual(Forum.objects.get(pk=forum.pk).topic_count, 1)
self.assertEqual(Forum.objects.get(pk=self.forum.pk).post_count, 3)
self.assertEqual(Forum.objects.get(pk=self.forum.pk).topic_count, 3)
self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).post_count, 3)
self.assertEqual(Forum.objects.get(pk=self.parent_forum.pk).topic_count, 3)