本文整理汇总了Python中askbot.models.Post类的典型用法代码示例。如果您正苦于以下问题:Python Post类的具体用法?Python Post怎么用?Python Post使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Post类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_cached_get_absolute_url_2
def test_cached_get_absolute_url_2(self):
p = Post(id=3, post_type='question')
th = lambda:1
th.title = 'lala-x-lala'
self.assertEqual('/question/3/lala-x-lala/', p.get_absolute_url(thread=th))
self.assertTrue(p._thread_cache is th)
self.assertEqual('/question/3/lala-x-lala/', p.get_absolute_url(thread=th))
示例2: test_cached_get_absolute_url_2
def test_cached_get_absolute_url_2(self):
p = Post(id=3, post_type="question")
th = lambda: 1
th.title = "lala-x-lala"
expected_url = urlresolvers.reverse("question", kwargs={"id": 3}) + th.title + "/"
self.assertEqual(expected_url, p.get_absolute_url(thread=th))
self.assertTrue(p._thread_cache is th)
self.assertEqual(expected_url, p.get_absolute_url(thread=th))
示例3: test_cached_get_absolute_url_1
def test_cached_get_absolute_url_1(self):
th = lambda:1
th.title = 'lala-x-lala'
p = Post(id=3, post_type='question')
p._thread_cache = th # cannot assign non-Thread instance directly
self.assertEqual('/question/3/lala-x-lala/', p.get_absolute_url(thread=th))
self.assertTrue(p._thread_cache is th)
self.assertEqual('/question/3/lala-x-lala/', p.get_absolute_url(thread=th))
示例4: test_cached_get_absolute_url_1
def test_cached_get_absolute_url_1(self):
th = lambda: 1
th.title = "lala-x-lala"
p = Post(id=3, post_type="question")
p._thread_cache = th # cannot assign non-Thread instance directly
expected_url = urlresolvers.reverse("question", kwargs={"id": 3}) + th.title + "/"
self.assertEqual(expected_url, p.get_absolute_url(thread=th))
self.assertTrue(p._thread_cache is th)
self.assertEqual(expected_url, p.get_absolute_url(thread=th))
示例5: test_cached_get_absolute_url_1
def test_cached_get_absolute_url_1(self):
th = lambda:1
th.title = 'lala-x-lala'
p = Post(id=3, post_type='question')
p._thread_cache = th # cannot assign non-Thread instance directly
expected_url = urlresolvers.reverse('question', kwargs={'id': 3}) \
+ th.title + '/'
self.assertEqual(expected_url, p.get_absolute_url(thread=th))
self.assertTrue(p._thread_cache is th)
self.assertEqual(expected_url, p.get_absolute_url(thread=th))
示例6: import_posts
def import_posts(self, post_type, save_redirects=False):
"""imports osqa Nodes to askbot Post objects"""
if save_redirects:
redirects_file = self.open_unique_file('question_redirects')
models_map = {
'question': 'forum.question',
'answer': 'forum.answer',
'comment': 'forum.comment'
}
model_name = models_map[post_type]
for osqa_node in self.get_objects_for_model(model_name):
if osqa_node.node_type != post_type:
continue
post = Post()
#this line is a bit risky, but should work if we import things in correct order
if osqa_node.parent:
post.parent = self.get_imported_object_by_old_id(Post, osqa_node.parent)
post.thread = post.parent.thread
else:
post.thread = self.get_imported_object_by_old_id(Thread, osqa_node.id)
post.post_type = osqa_node.node_type
if save_redirects:
slug = django_urlquote(slugify(osqa_node.title))
#todo: add i18n to the old url
old_url = '/questions/%d/%s/' % (osqa_node.id, slug)
post.author = self.get_imported_object_by_old_id(User, osqa_node.author)
post.html = HTMLParser().unescape(osqa_node.body)
post.summary = post.get_snippet()
#these don't have direct equivalent in the OSQA Node object
#post.deleted_by
#post.locked_by
#post.last_edited_by
#these are to be set later with the real values
post.points = 0
post.vote_up_count = 0
post.vote_down_count = 0
post.offensive_flag_count = 0
post.save()
if save_redirects:
new_url = post.get_absolute_url()
self.write_redirect(old_url, new_url, redirects_file)
self.log_action_with_old_id(osqa_node.id, post)
if save_redirects:
redirects_file.close()
示例7: _askbot_ext_action
returns None anf an AttributeError has to be catched
(the method will then return False)
"""
rv = False
# Use parent.is_question is OK because we are sure that parent is not None
# (parent would be None if self.is_question())
if self.is_comment() and self.parent.is_question():
rv = True
return rv
@property
def _askbot_ext_action(self):
"""Encapsulation of action reference"""
return self.thread.action
Post.add_to_class('ext_noattr', PostExtension())
#--------------------------------------------------------------------------------
#TODO: place can be blank/null at creation time?
#TODO TOTHINK User.add_to_class("place", models.CharField(max_length=512))
#--------------------------------------------------------------------------------
class VoteExtension(AskbotModelExtender):
@property
def _askbot_ext_action(self):
"""Encapsulation of action reference"""
return self.voted_post.action
示例8: import_posts
def import_posts(self, post_type, save_redirects=False):
"""imports osqa Nodes to askbot Post objects"""
if save_redirects:
redirects_file = self.open_unique_file('question_redirects')
models_map = {
'question': 'forum.question',
'answer': 'forum.answer',
'comment': 'forum.comment'
}
model_name = models_map[post_type]
for osqa_node in self.get_objects_for_model(model_name):
#we iterate through all nodes, but pick only the ones we need
if osqa_node.node_type != post_type:
continue
#cheat: do not import deleted content
if '(deleted)' in osqa_node.state_string:
continue
post = Post()
#this line is a bit risky, but should work if we import things in correct order
if osqa_node.parent:
post.parent = self.get_imported_object_by_old_id(Post, osqa_node.parent)
if post.parent is None:
continue #deleted parent
post.thread = post.parent.thread
else:
post.thread = self.get_imported_object_by_old_id(Thread, osqa_node.id)
if post.thread is None:
continue #deleted thread
post.post_type = osqa_node.node_type
post.added_at = osqa_node.added_at
if save_redirects:
slug = django_urlquote(slugify(osqa_node.title))
#todo: add i18n to the old url
old_url = '/questions/%d/%s/' % (osqa_node.id, slug)
post.author = self.get_imported_object_by_old_id(User, osqa_node.author)
#html will de added with the revisions
#post.html = HTMLParser().unescape(osqa_node.body)
post.summary = post.get_snippet()
#these don't have direct equivalent in the OSQA Node object
#post.deleted_by - deleted nodes are not imported
#post.locked_by
#post.last_edited_by
#these are to be set later with the real values
post.points = 0
post.vote_up_count = 0
post.vote_down_count = 0
post.offensive_flag_count = 0
post.save()
#mark accepted answer
now = timezone.now()
if osqa_node.node_type == 'answer':
if '(accepted)' in osqa_node.state_string:
post.thread.accepted_answer = post
post.endorsed = True
post.endorsed_at = now
post.thread.save()
if save_redirects:
new_url = post.get_absolute_url()
self.write_redirect(old_url, new_url, redirects_file)
self.log_action_with_old_id(osqa_node.id, post)
if save_redirects:
redirects_file.close()
示例9: _askbot_ext_action
returns None anf an AttributeError has to be catched
(the method will then return False)
"""
rv = False
# Use parent.is_question is OK because we are sure that parent is not None
# (parent would be None if self.is_question())
if self.is_comment() and self.parent.is_question():
rv = True
return rv
@property
def _askbot_ext_action(self):
"""Encapsulation of action reference"""
return self.thread.action
Post.add_to_class('ext_noattr', PostExtension())
Post.add_to_class('title', models.CharField(default='',max_length=256)
)
#--------------------------------------------------------------------------------
#TODO: place can be blank/null at creation time?
#TODO TOTHINK User.add_to_class("place", models.CharField(max_length=512))
#--------------------------------------------------------------------------------
class VoteExtension(AskbotModelExtender):
@property
def _askbot_ext_action(self):