本文整理汇总了Python中wikipendium.wiki.models.Article.get_newest_content方法的典型用法代码示例。如果您正苦于以下问题:Python Article.get_newest_content方法的具体用法?Python Article.get_newest_content怎么用?Python Article.get_newest_content使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wikipendium.wiki.models.Article
的用法示例。
在下文中一共展示了Article.get_newest_content方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ArticleTest
# 需要导入模块: from wikipendium.wiki.models import Article [as 别名]
# 或者: from wikipendium.wiki.models.Article import get_newest_content [as 别名]
class ArticleTest(TestCase):
def setUp(self):
self.u1 = User(username='u1')
self.u2 = User(username='u2')
self.u1.save()
self.u2.save()
self.article = Article(slug="TDT4100")
self.article.save()
self.ac1 = ArticleContent(article=self.article,
updated=datetime.datetime(2012, 1, 1))
self.ac2 = ArticleContent(article=self.article,
updated=datetime.datetime(2013, 1, 1),
title='per')
self.ac1.edited_by = self.u1
self.ac2.edited_by = self.u2
self.ac1.save()
self.ac2.save()
def test_slug_should_uppercase_when_saved(self):
article = Article()
article.slug = "lowercase"
article.save()
self.assertEqual(article.slug, "LOWERCASE")
def test_slug_should_strip_whitespace_when_saved(self):
article = Article()
article.slug = " PADDED\v\t \n"
article.save()
self.assertEqual(article.slug, "PADDED")
def test_slug_cannot_contain_slashes(self):
article = Article()
article.slug = "TDT/4100"
try:
article.save()
self.assertEqual(1, 2) # this should not be reached
except ValidationError:
self.assertEqual(1, 1) # correct error was raised
def test_get_contributors(self):
self.assertEquals(self.article.get_contributors(),
set([self.u1, self.u2]))
def test_get_newest_content(self):
self.assertEquals(self.article.get_newest_content(), self.ac2)
def test_get_available_languages(self):
self.assertEquals(self.article.get_available_languages(),
[('English', self.ac2)])
def test_get_absolute_url(self):
self.assertEquals(self.article.get_absolute_url(), "/TDT4100_per")
示例2: merge_contents_if_needed
# 需要导入模块: from wikipendium.wiki.models import Article [as 别名]
# 或者: from wikipendium.wiki.models.Article import get_newest_content [as 别名]
def merge_contents_if_needed(self):
parent_id = self.cleaned_data['parent_id']
article = None
articleContent = None
slug = self.cleaned_data['slug']
lang = self.cleaned_data['lang']
try:
article = Article.objects.get(slug=slug)
except:
article = Article(slug=slug)
articleContent = article.get_newest_content(lang)
if articleContent is None:
articleContent = ArticleContent(article=article, lang=lang)
if parent_id and parent_id != articleContent.pk:
parent = ArticleContent.objects.get(id=parent_id)
a = parent
b = articleContent
ancestors = set()
commonAncestor = None
while True:
if a and a.pk in ancestors:
commonAncestor = a
break
if b and b.pk in ancestors:
commonAncestor = b
break
ancestors.add(a.pk)
ancestors.add(b.pk)
a = a.parent
b = b.parent
if a and a.parent is None and b and b.parent is None:
break
try:
merged = merge(self.cleaned_data['content'],
commonAncestor.content, articleContent.content)
self.cleaned_data['content'] = merged
except MergeError as e:
raise ValidationError('Merge conflict.',
params={'diff': e.diff})
return True
示例3: ArticleTest
# 需要导入模块: from wikipendium.wiki.models import Article [as 别名]
# 或者: from wikipendium.wiki.models.Article import get_newest_content [as 别名]
class ArticleTest(TestCase):
def setUp(self):
self.u1 = User(username='u1')
self.u2 = User(username='u2')
self.u1.save()
self.u2.save()
self.article1 = Article(slug=u'TDT4100')
self.article1.save()
self.article2 = Article(slug=u'TIØ4258')
self.article2.save()
self.ac1 = ArticleContent(article=self.article1,
updated=datetime.datetime(2012, 1, 1))
self.ac2 = ArticleContent(article=self.article1,
updated=datetime.datetime(2013, 1, 1),
title='per')
self.ac3 = ArticleContent(article=self.article2,
updated=datetime.datetime(2001, 3, 7))
self.ac4 = ArticleContent(article=self.article2,
updated=datetime.datetime(2001, 3, 8),
lang='nb')
self.ac1.edited_by = self.u1
self.ac2.edited_by = self.u2
self.ac3.edited_by = self.u1
self.ac4.edited_by = self.u2
self.ac1.save()
self.ac2.save()
self.ac3.save()
self.ac4.save()
def test_slug_should_uppercase_when_saved(self):
article = Article()
article.slug = u'lowercase'
article.save()
self.assertEqual(article.slug, u'LOWERCASE')
def test_slug_should_strip_whitespace_when_saved(self):
article = Article()
article.slug = u' PADDED\v\t \n'
article.save()
self.assertEqual(article.slug, u'PADDED')
def test_slug_cannot_contain_slashes(self):
article = Article()
article.slug = u'TDT/4100'
try:
article.save()
self.assertEqual(1, 2) # this should not be reached
except ValidationError:
self.assertEqual(1, 1) # correct error was raised
def test_get_contributors(self):
self.assertEquals(self.article1.get_contributors(),
set([self.u1, self.u2]))
def test_get_newest_content(self):
self.assertEquals(self.article1.get_newest_content(), self.ac2)
def test_get_available_languages(self):
self.assertEquals(self.article1.get_available_languages(),
[('English', self.ac2)])
result = self.article2.get_available_languages()
expected_result = [('English', self.ac3),
('Norwegian', self.ac4)]
self.assertEquals(expected_result, result)
def test_get_absolute_url(self):
self.assertEquals(self.article1.get_absolute_url(), '/TDT4100_per')
def test_get_all_article_content(self):
result = Article.get_all_article_content()
expected_result = [[self.ac2], [self.ac3, self.ac4]]
self.assertEquals(expected_result, result)
def test_get_all_newest_contents(self):
result = Article.get_all_newest_contents()
expected_result = [self.ac2, self.ac4]
self.assertEquals(expected_result, result)
def test_get_all_newest_contents_all_languages(self):
result = Article.get_all_newest_contents_all_languages()
expected_result = [self.ac4, self.ac3, self.ac2]
self.assertEquals(expected_result, result)
def test___unicode__(self):
self.assertEquals(u'TIØ4258', unicode(self.article2))
self.assertEquals(unicode, type(unicode(self.article2)))
def test_get_sorted_contents(self):
result = list(self.article1.get_sorted_contents())
expected_result = [self.ac2, self.ac1]
self.assertEquals(expected_result, result)
result = list(self.article2.get_sorted_contents())
expected_result = [self.ac3]
self.assertEquals(expected_result, result)
result = list(self.article2.get_sorted_contents(lang='nb'))
expected_result = [self.ac4]
self.assertEquals(expected_result, result)
#.........这里部分代码省略.........