當前位置: 首頁>>代碼示例>>Python>>正文


Python models.RichTextPage類代碼示例

本文整理匯總了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)
開發者ID:Osmose,項目名稱:fxoss,代碼行數:9,代碼來源:test_utils.py

示例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)
開發者ID:Osmose,項目名稱:fxoss,代碼行數:10,代碼來源:test_utils.py

示例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)
開發者ID:Kenhaha,項目名稱:mezzanine,代碼行數:50,代碼來源:tests.py

示例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
開發者ID:MCadeStewart,項目名稱:digipal,代碼行數:28,代碼來源:dpdoc.py

示例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)
開發者ID:Osmose,項目名稱:fxoss,代碼行數:19,代碼來源:test_utils.py

示例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)
開發者ID:Osmose,項目名稱:fxoss,代碼行數:14,代碼來源:test_utils.py

示例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()
開發者ID:tiktuk,項目名稱:mezzanine,代碼行數:65,代碼來源:tests.py


注:本文中的mezzanine.pages.models.RichTextPage類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。