本文整理汇总了Python中pybb.models.Post.mark_as_deleted方法的典型用法代码示例。如果您正苦于以下问题:Python Post.mark_as_deleted方法的具体用法?Python Post.mark_as_deleted怎么用?Python Post.mark_as_deleted使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pybb.models.Post
的用法示例。
在下文中一共展示了Post.mark_as_deleted方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_compute_active_members
# 需要导入模块: from pybb.models import Post [as 别名]
# 或者: from pybb.models.Post import mark_as_deleted [as 别名]
def test_compute_active_members(self):
# Initials
self.assertEquals(self.parent_forum.member_count, 0)
self.assertEquals(self.forum.member_count, 0)
self.assertEquals(self.topic.member_count, 0)
# Add first post by self.user (count += 1)
user_post_1 = self.post
self.assertEquals(self.parent_forum.member_count, 1)
self.assertEquals(self.forum.member_count, 1)
self.assertEquals(self.topic.member_count, 1)
# Add first post by self.staff (count += 1)
staff_post_1 = Post(topic=self.topic, user=self.staff, body='my new post')
staff_post_1.save()
self.assertEquals(self.parent_forum.member_count, 2)
self.assertEquals(self.forum.member_count, 2)
self.assertEquals(self.topic.member_count, 2)
# Add second post by self.user (count += 0)
user_post_2 = Post(topic=self.topic, user=self.user, body='my new post')
user_post_2.save()
self.assertEquals(self.parent_forum.member_count, 2)
self.assertEquals(self.forum.member_count, 2)
self.assertEquals(self.topic.member_count, 2)
# Delete staff_post_1 (count -= 1)
staff_post_1.mark_as_deleted(commit=True)
self.assertEquals(self.parent_forum.member_count, 1)
self.assertEquals(self.forum.member_count, 1)
self.assertEquals(self.topic.member_count, 1)
# Restore staff_post_1 (count += 1)
staff_post_1.mark_as_undeleted(commit=True)
self.assertEquals(self.parent_forum.member_count, 2)
self.assertEquals(self.forum.member_count, 2)
self.assertEquals(self.topic.member_count, 2)
# Delete user_post_2 (count -= 0)
user_post_2.mark_as_deleted(commit=True)
self.assertEquals(self.parent_forum.member_count, 2)
self.assertEquals(self.forum.member_count, 2)
self.assertEquals(self.topic.member_count, 2)
# Add third post by self.user in parent_forum (count += 0)
new_topic = Topic(name='foo2', forum=self.parent_forum, user=self.user)
new_topic.save()
user_post_3 = Post(topic=new_topic, user=self.user, body='my new post')
user_post_3.save()
self.assertEquals(self.parent_forum.member_count, 2)
self.assertEquals(new_topic.member_count, 1)
self.assertEquals(self.forum.member_count, 2)
self.assertEquals(self.topic.member_count, 2)
示例2: test_compute
# 需要导入模块: from pybb.models import Post [as 别名]
# 或者: from pybb.models.Post 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)
示例3: test_undelete_post_topic_view
# 需要导入模块: from pybb.models import Post [as 别名]
# 或者: from pybb.models.Post import mark_as_deleted [as 别名]
def test_undelete_post_topic_view(self):
post = Post(topic=self.topic, user=self.user, body='test to delete', deleted=True)
post.save()
post.mark_as_deleted(user=self.user)
self.login()
self.post.mark_as_deleted(user=self.user)
response = self.client.post(reverse('pybb:post_delete', args=[self.post.id]))
self.assertEqual(response.status_code, 302)
self.post = Post.objects.get(pk=self.post.pk)
self.assertRaises(PostDeletion.DoesNotExist, lambda: self.post.deletion)
self.assertFalse(self.post.deleted)
self.assertTrue(Post.objects.get(pk=post.pk).deleted)
示例4: test_compute
# 需要导入模块: from pybb.models import Post [as 别名]
# 或者: from pybb.models.Post 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)