• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python models.RichTextPage类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python cache.add_cache_bypass函数代码示例发布时间:2022-05-27
下一篇:
Python models.Page类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap