本文整理汇总了Python中pages.models.Content.creation_date方法的典型用法代码示例。如果您正苦于以下问题:Python Content.creation_date方法的具体用法?Python Content.creation_date怎么用?Python Content.creation_date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pages.models.Content
的用法示例。
在下文中一共展示了Content.creation_date方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_automatic_slug_renaming
# 需要导入模块: from pages.models import Content [as 别名]
# 或者: from pages.models.Content import creation_date [as 别名]
def test_automatic_slug_renaming(self):
"""Test a slug renaming."""
self.set_setting("PAGE_AUTOMATIC_SLUG_RENAMING", True)
c = self.get_admin_client()
page_data = self.get_new_page_data()
page_data['slug'] = "slug"
response = c.post('/admin/pages/page/add/', page_data)
self.assertRedirects(response, '/admin/pages/page/')
response = c.post('/admin/pages/page/add/', page_data)
self.assertRedirects(response, '/admin/pages/page/')
response = c.post('/admin/pages/page/add/', page_data)
self.assertRedirects(response, '/admin/pages/page/')
slug = page_data['slug']
page1 = Content.objects.get_content_slug_by_slug(slug).page
page2 = Content.objects.get_content_slug_by_slug(slug+'-2').page
page3 = Content.objects.get_content_slug_by_slug(slug+'-3').page
self.assertNotEqual(page1.id, page2.id)
self.assertNotEqual(page2.id, page3.id)
self.assertEqual(Content.objects.filter(type="slug").count(), 3)
# post again on page 3 doesn't change the slug
page_3_slug = page3.slug()
page_data['slug'] = page_3_slug
response = c.post('/admin/pages/page/%d/' % page3.id, page_data)
self.assertRedirects(response, '/admin/pages/page/')
self.assertEqual(Content.objects.filter(type="slug").count(), 3)
content = Content.objects.get_content_slug_by_slug(page_3_slug)
self.assertEqual(page3.id, content.page.id)
# change an old slug of another page and see that it doesn't
# influence the current slug of this page
old_slug = Content.objects.filter(page=page1).latest("creation_date")
new_slug = Content(page=page1, body=page_3_slug, type="slug")
new_slug.creation_date = old_slug.creation_date - datetime.timedelta(seconds=5)
new_slug.save()
self.assertEqual(Content.objects.filter(type="slug").count(), 4)
# check than the old slug doesn't trigger a new slug for page 3
response = c.post('/admin/pages/page/%d/' % page3.id, page_data)
content = Content.objects.get_content_slug_by_slug(page_3_slug)
self.assertEqual(page3.id, content.page.id)
self.assertEqual(Content.objects.filter(type="slug").count(), 4)
new_slug.creation_date = old_slug.creation_date + datetime.timedelta(seconds=5)
new_slug.save()
# check than the new slug does trigger a new slug for page 3
response = c.post('/admin/pages/page/%d/' % page3.id, page_data)
content = Content.objects.get_content_slug_by_slug(page_3_slug)
self.assertEqual(page1.id, content.page.id)
content = Content.objects.get_content_slug_by_slug(page_3_slug+'-2')
self.assertEqual(page3.id, content.page.id)