本文整理汇总了Python中pybb.models.Post类的典型用法代码示例。如果您正苦于以下问题:Python Post类的具体用法?Python Post怎么用?Python Post使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Post类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: save
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,代码行数:29,代码来源:forms.py
示例2: test_topic_tracker_redirect_view
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,代码行数:28,代码来源:test_trackers.py
示例3: test_simple_quote
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,代码行数:7,代码来源:test_quotes.py
示例4: test_topics_delete_complete
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,代码行数:27,代码来源:test_features.py
示例5: test_topic_merge_form
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,代码行数:28,代码来源:tests.py
示例6: test_topic_move_complete
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,代码行数:35,代码来源:test_features.py
示例7: test_topic_delete_formset
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,代码行数:25,代码来源:tests.py
示例8: test_topic_move_form_with_new_forum
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,代码行数:28,代码来源:tests.py
示例9: test_topic_move_form_errors
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,代码行数:34,代码来源:tests.py
示例10: test_topic_merge_formset
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,代码行数:33,代码来源:tests.py
示例11: create_other_threads
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,代码行数:25,代码来源:create_lessons_threads.py
示例12: test_multiple_quote_add
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,代码行数:34,代码来源:test_quotes.py
示例13: test_forum_updated
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,代码行数:8,代码来源:test_features.py
示例14: test_delete_post_view_own_user
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,代码行数:12,代码来源:test_features.py
示例15: test_hidden
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,代码行数:58,代码来源:test_features.py
示例16: test_undelete_post_view_own_user
def test_undelete_post_view_own_user(self):
post = Post(topic=self.topic, user=self.user, body='test to delete', deleted=True)
post.save()
PostDeletion.objects.create(post=post, user=self.user)
self.login()
response = self.client.post(reverse('pybb:post_delete', args=[post.id]))
self.assertEqual(response.status_code, 302)
post = Post.objects.get(pk=post.pk)
self.assertRaises(PostDeletion.DoesNotExist, lambda: post.deletion)
self.assertFalse(post.deleted)
开发者ID:thoas,项目名称:pybbm,代码行数:16,代码来源:test_features.py
示例17: test_topic_merge_view
def test_topic_merge_view(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_merge')
self.login_as(self.staff)
response = self.client.post(topic_merge_url, data={
'topic_ids': [topic.pk]
})
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.context['form'].forms), 1)
self.assertTemplateUsed(response, 'pybb/topic/merge.html')
开发者ID:thoas,项目名称:pybbm,代码行数:17,代码来源:test_features.py
示例18: test_multiple_mentions
def test_multiple_mentions(self):
self.user
self.staff
self.superuser
multiple_mentions = Post(topic=self.topic, user=self.user, body='@thoas is right and @oleiade or @zeus!')
processor = MentionProcessor(multiple_mentions.body, obj=multiple_mentions)
self.assertEqual(processor.render(), u'[mention=%d]thoas[/mention] is right and [mention=%d]oleiade[/mention] or [mention=%d]zeus[/mention]!' % (
self.staff.pk,
self.superuser.pk,
self.user.pk
))
multiple_mentions.save()
self.assertEqual(Mention.objects.filter(post=multiple_mentions).count(), 3)
开发者ID:magatz,项目名称:pybbm-1,代码行数:17,代码来源:tests.py
示例19: handle
def handle(self, *args, **options):
_parser = Markdown(
extensions=[
'forum.mdownx.nofollowlinks',
'markdown.extensions.nl2br',
'pymdownx.extra',
'pymdownx.emoji',
'pymdownx.tasklist',
'pymdownx.details',
'pymdownx.superfences',
'pymdownx.details',
],
safe_mode='escape',
)
table = self.import_from_csv('narodny_konspekt.csv')
for lesson_number in table:
table[lesson_number] = self.rewrite(table[lesson_number])
if isinstance(table[lesson_number], float):
pass
else:
try:
page = LessonPage.objects.get(lesson_number=lesson_number)
except:
self.stdout.write("Lesson page doesn't exist")
break
page.has_own_topic = True
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='ILYA'),
slug='lecon' + str(page.lesson_number),
)
page.topic_id = new_topic.id
self.stdout.write(str(lesson_number) + ' thread created')
body = table[lesson_number]
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(tz=pytz.timezone(settings.TIME_ZONE)),
)
new_post.save()
self.stdout.write(str(lesson_number) + ' post created')
page.save()
开发者ID:5CORNERS,项目名称:www.le-francais.ru,代码行数:45,代码来源:create_lessons_threads.py
示例20: test_delete_post_view_superuser
def test_delete_post_view_superuser(self):
post = Post(topic=self.topic, user=self.user, body='test to delete')
post.save()
self.user.is_superuser = True
self.user.save()
self.login()
response = self.client.post(reverse('pybb:post_delete', args=[post.id]), follow=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(Topic.objects.filter(id=self.topic.id).count(), 1)
self.assertEqual(Forum.objects.filter(id=self.forum.id).count(), 1)
response = self.client.post(reverse('pybb:post_delete', args=[self.post.id]), follow=True)
self.assertEqual(response.status_code, 200)
self.assertEqual(Post.objects.filter(id=self.post.id,
deleted=False).count(), 0)
self.assertEqual(Topic.objects.filter(id=self.topic.id,
deleted=False).count(), 0)
self.assertEqual(Forum.objects.filter(id=self.forum.id).count(), 1)
开发者ID:thoas,项目名称:pybbm,代码行数:19,代码来源:test_features.py
注:本文中的pybb.models.Post类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论