本文整理汇总了Python中mezzanine.pages.models.RichTextPage.site方法的典型用法代码示例。如果您正苦于以下问题:Python RichTextPage.site方法的具体用法?Python RichTextPage.site怎么用?Python RichTextPage.site使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mezzanine.pages.models.RichTextPage
的用法示例。
在下文中一共展示了RichTextPage.site方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_update_site
# 需要导入模块: from mezzanine.pages.models import RichTextPage [as 别名]
# 或者: from mezzanine.pages.models.RichTextPage import site [as 别名]
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()