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


Python Post.save方法代码示例

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


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

示例1: test_topic_delete_formset

# 需要导入模块: from pybb.models import Post [as 别名]
# 或者: from pybb.models.Post import save [as 别名]
    def test_topic_delete_formset(self):
        topic2 = Topic.objects.create(name='Topic 2', forum=self.forum, user=self.superuser)

        post2 = Post(topic=topic2, user=self.superuser, body='post on topic2')
        post2.save()

        topics = Topic.objects.filter(pk__in=[self.topic.pk, topic2.pk])

        FormSet = get_topic_delete_formset(topics=topics)

        formset = FormSet(data={
            'form-TOTAL_FORMS': 2,
            'form-INITIAL_FORMS': 0,
            'form-0-topic': self.topic.pk,
            'form-0-confirm': True,
            'form-1-topic': topic2.pk,
            'form-1-confirm': True,
        })

        self.assertTrue(formset.is_valid())

        for form in formset:
            topic = form.save()

            self.assertTrue(topic.deleted)
开发者ID:magatz,项目名称:pybbm-1,代码行数:27,代码来源:tests.py

示例2: test_topic_tracker_redirect_view

# 需要导入模块: from pybb.models import Post [as 别名]
# 或者: from pybb.models.Post import save [as 别名]
    def test_topic_tracker_redirect_view(self):
        self.login_as(self.staff)

        self.post

        response = self.client.get(reverse('pybb:topic_tracker_redirect', kwargs={
            'topic_id': self.topic.pk
        }))

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

        TopicReadTracker.objects.create(topic=self.topic,
                                        user=self.staff)

        response = self.client.get(reverse('pybb:topic_tracker_redirect', kwargs={
            'topic_id': self.topic.pk
        }))

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

        post = Post(topic=self.topic, user=self.user, body='test')
        post.save()

        response = self.client.get(reverse('pybb:topic_tracker_redirect', kwargs={
            'topic_id': self.topic.pk
        }))

        self.assertRedirects(response, post.get_absolute_url(), status_code=301)
开发者ID:thoas,项目名称:pybbm,代码行数:30,代码来源:test_trackers.py

示例3: save

# 需要导入模块: from pybb.models import Post [as 别名]
# 或者: from pybb.models.Post import save [as 别名]
 def save(self, commit=True):
     if self.instance.pk:
         post = super(PostForm, self).save(commit=False)
         if self.user:
             post.user = self.user
         if post.topic.head == post:
             post.topic.name = self.cleaned_data['name']
             post.topic.updated = datetime.now()
             post.topic.save()
         post.save()
         return post
     allow_post = True
     if defaults.PYBB_PREMODERATION:
             allow_post = defaults.PYBB_PREMODERATION(self.user, self.cleaned_data['body'])
     if self.forum:
         topic = Topic(forum=self.forum,
                       user=self.user,
                       name=self.cleaned_data['name'])
         if not allow_post:
             topic.on_moderation = True
         topic.save()
     else:
         topic = self.topic
     post = Post(topic=topic, user=self.user, user_ip=self.ip,
                 body=self.cleaned_data['body'])
     if not allow_post:
         post.on_moderation = True
     post.save()
     return post
开发者ID:makinacorpus,项目名称:pybbm,代码行数:31,代码来源:forms.py

示例4: test_topics_delete_complete

# 需要导入模块: from pybb.models import Post [as 别名]
# 或者: from pybb.models.Post import save [as 别名]
    def test_topics_delete_complete(self):
        topic2 = Topic.objects.create(name='Topic 2', forum=self.forum, user=self.superuser)

        post2 = Post(topic=topic2, user=self.superuser, body='post on topic2')
        post2.save()

        topics_delete_url = reverse('pybb:topics_delete')

        self.login_as(self.staff)

        response = self.client.post(topics_delete_url, data={
            'topic_ids': [self.topic.pk, topic2.pk],
            'form-TOTAL_FORMS': 2,
            'form-INITIAL_FORMS': 0,
            'form-0-topic': self.topic.pk,
            'form-0-confirm': True,
            'form-1-topic': topic2.pk,
            'form-1-confirm': True,
            'submit': 1
        })

        topic2 = Topic.objects.get(pk=topic2.pk)

        self.assertTrue(self.topic.delete)
        self.assertTrue(topic2.delete)

        self.assertRedirects(response, reverse('pybb:index'))
开发者ID:thoas,项目名称:pybbm,代码行数:29,代码来源:test_features.py

示例5: create_other_threads

# 需要导入模块: from pybb.models import Post [as 别名]
# 或者: from pybb.models.Post import save [as 别名]
	def create_other_threads(self):
		for page in LessonPage.objects.all():
			if not page.has_own_topic:
				new_topic, topic_created = Topic.objects.get_or_create(
					forum=Forum.objects.get(name='Lessons Forum'),
					name='Урок-' + str(page.lesson_number),
					user=User.objects.get(username='admin'),
					slug='lecon' + str(page.lesson_number),
				)
				if topic_created:
					page.topic_id = new_topic.id
					self.stdout.write(str(page.lesson_number) + ' thread created')
					body = 'Не стесняйтесь задавать вопросы и комментировать.'
					new_post = Post(
						body=body,
						topic_id=new_topic.id,
						user_id=new_topic.user_id,
						user_ip='1.1.1.1',
						created=datetime.now(),
					)
					new_post.save()
					self.stdout.write(str(lesson_number) + ' post created')
				else:
					self.stdout.write(str(lesson_number) + ' thread not created')
				page.save()
开发者ID:5CORNERS,项目名称:www.le-francais.ru,代码行数:27,代码来源:create_lessons_threads.py

示例6: test_topic_move_form_with_new_forum

# 需要导入模块: from pybb.models import Post [as 别名]
# 或者: from pybb.models.Post import save [as 别名]
    def test_topic_move_form_with_new_forum(self):
        forum = Forum.objects.create(name='temporary forum')

        topic = Topic.objects.create(name='move_topic', forum=forum, user=self.superuser)

        post = Post(topic=topic, user=self.superuser, body='move post')
        post.save()

        name = 'new name for temporary topic'

        form = TopicMoveForm(topic=topic, data={
            'name': name,
            'forum': self.forum.pk,
            'redirection_type': TopicRedirection.TYPE_PERMANENT_REDIRECT
        })

        self.assertTrue(form.is_valid())

        new_topic = form.save()

        topic = Topic.objects.get(pk=topic.pk)

        self.assertTrue(topic.redirect)

        self.failUnless(new_topic.slug is not None)
        self.assertEqual(new_topic.redirections.count(), 1)
        self.assertEqual(Post.objects.get(pk=post.pk).topic, new_topic)
        self.assertEqual(topic.posts.count(), 0)
开发者ID:magatz,项目名称:pybbm-1,代码行数:30,代码来源:tests.py

示例7: test_topic_move_complete

# 需要导入模块: from pybb.models import Post [as 别名]
# 或者: from pybb.models.Post import save [as 别名]
    def test_topic_move_complete(self):
        topic = Topic(name='xtopic', forum=self.forum, user=self.user)
        topic.save()
        post = Post(topic=topic, user=self.user, body='one')
        post.save()

        topic_merge_url = reverse('pybb:topic_move')

        self.login_as(self.staff)

        name = 'new name for a topic'

        response = self.client.post(topic_merge_url, data={
            'topic_ids': [topic.pk],
            'form-TOTAL_FORMS': 1,
            'form-INITIAL_FORMS': 0,
            'form-0-name': name,
            'form-0-forum': self.forum.pk,
            'form-0-redirection_type': TopicRedirection.TYPE_PERMANENT_REDIRECT,
            'submit': 1
        })

        self.assertRedirects(response, reverse('pybb:index'))

        topic = Topic.objects.get(pk=topic.pk)

        self.assertTrue(topic.redirect)
        self.failUnless(topic.redirection is not None)

        redirection = topic.redirection

        new_topic = redirection.to_topic

        self.assertEqual(new_topic.name, name)
        self.assertEqual(new_topic.post_count, 1)
开发者ID:thoas,项目名称:pybbm,代码行数:37,代码来源:test_features.py

示例8: test_topic_move_form_errors

# 需要导入模块: from pybb.models import Post [as 别名]
# 或者: from pybb.models.Post import save [as 别名]
    def test_topic_move_form_errors(self):
        forum = Forum.objects.create(name='temporary forum')

        topic = Topic.objects.create(name='move_topic', forum=forum, user=self.superuser)

        post = Post(topic=topic, user=self.superuser, body='move post')
        post.save()

        form = TopicMoveForm(topic=topic, data={
            'name': topic.name,
            'forum': forum.pk,
            'redirection_type': TopicRedirection.TYPE_PERMANENT_REDIRECT
        })

        self.assertFalse(form.is_valid())
        self.assertIn('name', form.errors)

        Topic.objects.create(name='move_topic', forum=self.forum, user=self.superuser)

        form = TopicMoveForm(topic=topic, data={
            'forum': self.forum.pk,
            'redirection_type': TopicRedirection.TYPE_PERMANENT_REDIRECT
        })

        self.assertFalse(form.is_valid())
        self.assertIn('name', form.errors)

        form = TopicMoveForm(topic=topic, data={
            'forum': self.forum.pk,
            'redirection_type': TopicRedirection.TYPE_EXPIRING_REDIRECT
        })

        self.assertFalse(form.is_valid())
        self.assertIn('expired', form.errors)
开发者ID:magatz,项目名称:pybbm-1,代码行数:36,代码来源:tests.py

示例9: test_topic_merge_formset

# 需要导入模块: from pybb.models import Post [as 别名]
# 或者: from pybb.models.Post import save [as 别名]
    def test_topic_merge_formset(self):
        topic = Topic.objects.create(name='merged_topic', forum=self.forum, user=self.superuser)

        post = Post(topic=topic, user=self.superuser, body='merged post')
        post.save()

        topics = [topic]

        FormSet = get_topic_merge_formset(topics=topics)

        formset = FormSet()

        for i in range(len(topics)):
            self.assertEqual(formset.forms[i].topic, topics[i])

        formset = FormSet(data={
            'form-TOTAL_FORMS': 1,
            'form-INITIAL_FORMS': 0,
            'form-0-topic': self.topic.pk
        })

        self.assertTrue(formset.is_valid())

        for form in formset:
            new_topic = form.save()

        topic = Topic.objects.get(pk=topic.pk)

        self.assertTrue(topic.redirect)

        self.assertEqual(new_topic.redirections.count(), 1)
        self.assertEqual(Post.objects.get(pk=post.pk).topic, self.topic)
        self.assertEqual(topic.posts.count(), 0)
开发者ID:magatz,项目名称:pybbm-1,代码行数:35,代码来源:tests.py

示例10: test_topic_merge_form

# 需要导入模块: from pybb.models import Post [as 别名]
# 或者: from pybb.models.Post import save [as 别名]
    def test_topic_merge_form(self):
        topic = Topic.objects.create(name='merged_topic', forum=self.forum, user=self.superuser)

        post = Post(topic=topic, user=self.superuser, body='merged post')
        post.save()

        form = TopicMergeForm(topic=topic, data={
            'topic': topic.pk
        })

        self.assertFalse(form.is_valid())
        self.assertIn('topic', form.errors)

        form = TopicMergeForm(topic=topic, data={
            'topic': self.topic.pk
        })

        self.assertTrue(form.is_valid())

        new_topic = form.save()

        topic = Topic.objects.get(pk=topic.pk)

        self.assertTrue(topic.redirect)

        self.assertEqual(new_topic.redirections.count(), 1)
        self.assertEqual(Post.objects.get(pk=post.pk).topic, self.topic)
        self.assertEqual(topic.posts.count(), 0)
开发者ID:magatz,项目名称:pybbm-1,代码行数:30,代码来源:tests.py

示例11: test_multiple_quote_add

# 需要导入模块: from pybb.models import Post [as 别名]
# 或者: from pybb.models.Post import save [as 别名]
    def test_multiple_quote_add(self):
        self.user
        self.login_as(self.staff)

        self.post

        post = Post(topic=self.topic, user=self.superuser, body='[b]do you want my pere nowel?[/b]')
        post.save()

        response = self.client.post(reverse('quote'), data={
            'topic_id': self.topic.pk,
            'post_id': post.pk
        })

        self.assertEqual(response.status_code, 302)

        response = self.client.get(reverse('pybb:post_create',
                                           kwargs={'topic_id': self.topic.id}) + '?quote_id=%d' % self.post.id)

        self.assertEqual(response.context['form'].initial['body'], u'[quote="zeus;{}"]bbcode [b]test[/b][/quote]\n\n[quote="oleiade;{}"][b]do you want my pere nowel?[/b][/quote]\n\n'.format(self.post.pk, post.pk))

        self.assertEqual(response.status_code, 200)

        response = self.client.post(reverse('quote'), data={
            'topic_id': self.topic.pk,
            'post_id': post.pk
        })

        self.assertEqual(response.status_code, 302)

        response = self.client.get(reverse('pybb:post_create',
                                           kwargs={'topic_id': self.topic.id}))
        self.assertTrue('body' not in response.context['form'].initial)
        self.assertEqual(response.status_code, 200)
开发者ID:thoas,项目名称:pybbm,代码行数:36,代码来源:test_quotes.py

示例12: test_simple_quote

# 需要导入模块: from pybb.models import Post [as 别名]
# 或者: from pybb.models.Post import save [as 别名]
    def test_simple_quote(self):
        post = Post(user=self.staff, body='[quote="zeus;%d"]Super quote[/quote]' % self.post.pk, topic=self.topic)
        post.save()

        self.assertHTMLEqual(minify_html(post.body_html), u'<blockquote><div class="quote-author">        Posted by <a class="quote-author-name" href="/users/zeus/">zeus</a><a rel="nofollow" class="quote-message-link" href="/xfoo/{}-etopic#post{}"></a></div><div class="quote-message">        Super quote    </div></blockquote>'.format(self.post.topic_id, self.post.id))

        self.assertEqual(Quote.objects.filter(from_post=post).count(), 1)
开发者ID:thoas,项目名称:pybbm,代码行数:9,代码来源:test_quotes.py

示例13: test_forum_updated

# 需要导入模块: from pybb.models import Post [as 别名]
# 或者: from pybb.models.Post import save [as 别名]
 def test_forum_updated(self):
     time.sleep(1)
     topic = Topic(name='xtopic', forum=self.forum, user=self.user)
     topic.save()
     post = Post(topic=topic, user=self.user, body='one')
     post.save()
     post = Post.objects.get(id=post.id)
     self.assertTrue(self.forum.updated == post.created)
开发者ID:thoas,项目名称:pybbm,代码行数:10,代码来源:test_features.py

示例14: test_hidden

# 需要导入模块: from pybb.models import Post [as 别名]
# 或者: from pybb.models.Post import save [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

示例15: test_delete_post_view_own_user

# 需要导入模块: from pybb.models import Post [as 别名]
# 或者: from pybb.models.Post import save [as 别名]
    def test_delete_post_view_own_user(self):
        post = Post(topic=self.topic, user=self.user, body='test to delete')
        post.save()

        self.login()

        response = self.client.post(reverse('pybb:post_delete', args=[post.id]))
        self.assertEqual(response.status_code, 302)

        self.assertRaises(Post.DoesNotExist, lambda: Post.objects.get(pk=post.pk, deleted=False))

        self.assertNotEqual(post.deletion, None)
开发者ID:thoas,项目名称:pybbm,代码行数:14,代码来源:test_features.py


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