本文整理汇总了Python中mezzanine.pages.models.RichTextPage类的典型用法代码示例。如果您正苦于以下问题:Python RichTextPage类的具体用法?Python RichTextPage怎么用?Python RichTextPage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RichTextPage类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_copy_default_minimal
def test_copy_default_minimal(self):
"""Copy all CMS models from the default site (minimal example)."""
# This will be created with the default site
# TODO: .create fails somehow related to django-concurrency
page = RichTextPage(title='Learn', content='<h1>Title</h1>')
page.save()
site = Site.objects.create(name='zh-cn', domain='example.com')
utils.build_site_content(site)
self.assertCopied(page, site)
示例2: test_copy_multiple_models
def test_copy_multiple_models(self):
"""CMS Pages, RichTextPage, Links should all be copied."""
# TODO: .create fails somehow related to django-concurrency
page = RichTextPage(title='Learn', content='<h1>Title</h1>')
page.save()
link = Link.objects.create(title='External Link')
site = Site.objects.create(name='zh-cn', domain='example.com')
utils.build_site_content(site)
self.assertCopied(page, site)
self.assertCopied(link, site)
示例3: test_set_parent
def test_set_parent(self):
old_parent, _ = RichTextPage.objects.get_or_create(title="Old parent")
new_parent, _ = RichTextPage.objects.get_or_create(title="New parent")
child, _ = RichTextPage.objects.get_or_create(
title="Child", slug="kid")
self.assertTrue(child.parent is None)
self.assertTrue(child.slug == "kid")
child.set_parent(old_parent)
child.save()
self.assertEqual(child.parent_id, old_parent.id)
self.assertTrue(child.slug == "old-parent/kid")
child = RichTextPage.objects.get(id=child.id)
self.assertEqual(child.parent_id, old_parent.id)
self.assertTrue(child.slug == "old-parent/kid")
child.set_parent(new_parent)
child.save()
self.assertEqual(child.parent_id, new_parent.id)
self.assertTrue(child.slug == "new-parent/kid")
child = RichTextPage.objects.get(id=child.id)
self.assertEqual(child.parent_id, new_parent.id)
self.assertTrue(child.slug == "new-parent/kid")
child.set_parent(None)
child.save()
self.assertTrue(child.parent is None)
self.assertTrue(child.slug == "kid")
child = RichTextPage.objects.get(id=child.id)
self.assertTrue(child.parent is None)
self.assertTrue(child.slug == "kid")
child = RichTextPage(title="child2")
child.set_parent(new_parent)
self.assertEqual(child.slug, "new-parent/child2")
# Assert that cycles are detected.
p1, _ = RichTextPage.objects.get_or_create(title="p1")
p2, _ = RichTextPage.objects.get_or_create(title="p2")
p2.set_parent(p1)
with self.assertRaises(AttributeError):
p1.set_parent(p1)
with self.assertRaises(AttributeError):
p1.set_parent(p2)
p2c = RichTextPage.objects.get(title="p2")
with self.assertRaises(AttributeError):
p1.set_parent(p2c)
示例4: update_cms_page
def update_cms_page(self, title=None, content='', parent_title=None, draft=False):
if not title:
title = 'Untitled'
from mezzanine.pages.models import Page, RichTextPage
page = get_cms_page_from_title(title)
in_menus = [2,3]
# create the page
from mezzanine.core.models import CONTENT_STATUS_PUBLISHED, CONTENT_STATUS_DRAFT
if not page:
parent_page = get_cms_page_from_title(parent_title)
page = RichTextPage(title=title, content_model='richtextpage', parent=parent_page, content=content, status=CONTENT_STATUS_PUBLISHED)
page.save()
page.status = CONTENT_STATUS_DRAFT if draft else CONTENT_STATUS_PUBLISHED
page.in_menus = in_menus
else:
# Can't find an easy way to edit page.richtextpage.content, so let's write directly to the DB!
from django.db import connection
cursor = connection.cursor()
cursor.execute('''update pages_richtextpage set content = %s where page_ptr_id = %s''', [content, page.id])
page.save()
return page
示例5: test_nested_forms_links
def test_nested_forms_links(self):
"""Page hierarchy for forms and links should be preserved on copy."""
# TODO: .create fails somehow related to django-concurrency
page = RichTextPage(title='Learn', content='<h1>Title</h1>')
page.save()
form = Form(title='Contact Us', parent=page)
form.save()
link = Link(title='Foo', parent=page)
link.save()
site = Site.objects.create(name='zh-cn', domain='example.com')
utils.build_site_content(site)
self.assertCopied(page, site)
self.assertCopied(form, site)
self.assertCopied(link, site)
copy = QuerySet(RichTextPage).get(slug=page.slug, site=site)
formcopy = QuerySet(Form).get(slug=form.slug, site=site)
linkcopy = QuerySet(Link).get(slug=link.slug, site=site)
self.assertEqual(formcopy.parent_id, copy.pk)
self.assertEqual(linkcopy.parent_id, copy.pk)
示例6: test_nested_pages
def test_nested_pages(self):
"""Page hierarchy should be preserved on copy."""
# TODO: .create fails somehow related to django-concurrency
page = RichTextPage(title='Learn', content='<h1>Title</h1>')
page.save()
subpage = RichTextPage(title='Sub Learn', content='<h1>Title</h1>', parent=page)
subpage.save()
site = Site.objects.create(name='zh-cn', domain='example.com')
utils.build_site_content(site)
self.assertCopied(page, site)
self.assertCopied(subpage, site)
copy = QuerySet(RichTextPage).get(slug=page.slug, site=site)
subcopy = QuerySet(RichTextPage).get(slug=subpage.slug, site=site)
self.assertEqual(subcopy.parent_id, copy.pk)
示例7: test_update_site
def test_update_site(self):
from django.conf import settings
from mezzanine.utils.sites import current_site_id
# setup
try:
old_site_id = settings.SITE_ID
except:
old_site_id = None
site1 = Site.objects.create(domain="site1.com")
site2 = Site.objects.create(domain="site2.com")
# default behaviour, page gets assigned current site
settings.SITE_ID = site2.pk
self.assertEqual(settings.SITE_ID, current_site_id())
page = RichTextPage()
page.save()
self.assertEqual(page.site_id, site2.pk)
# Subsequent saves do not update site to current site
page.site = site1
page.save()
self.assertEqual(page.site_id, site1.pk)
# resave w/ update_site=True, page gets assigned current site
settings.SITE_ID = site1.pk
page.site = site2
page.save(update_site=True)
self.assertEqual(page.site_id, site1.pk)
# resave w/ update_site=False, page does not update site
settings.SITE_ID = site2.pk
page.save(update_site=False)
self.assertEqual(page.site_id, site1.pk)
# When update_site=True, new page gets assigned current site
settings.SITE_ID = site2.pk
page = RichTextPage()
page.site = site1
page.save(update_site=True)
self.assertEqual(page.site_id, site2.pk)
# When update_site=False, new page keeps current site
settings.SITE_ID = site2.pk
page = RichTextPage()
page.site = site1
page.save(update_site=False)
self.assertEqual(page.site_id, site1.pk)
# When site explicitly assigned, new page keeps assigned site
settings.SITE_ID = site2.pk
page = RichTextPage()
page.site = site1
page.save()
self.assertEqual(page.site_id, site1.pk)
# tear down
if old_site_id:
settings.SITE_ID = old_site_id
else:
del settings.SITE_ID
site1.delete()
site2.delete()