本文整理匯總了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)