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