本文整理匯總了Python中wagtail.wagtailcore.models.Site方法的典型用法代碼示例。如果您正苦於以下問題:Python models.Site方法的具體用法?Python models.Site怎麽用?Python models.Site使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類wagtail.wagtailcore.models
的用法示例。
在下文中一共展示了models.Site方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: get_sharing_url
# 需要導入模塊: from wagtail.wagtailcore import models [as 別名]
# 或者: from wagtail.wagtailcore.models import Site [as 別名]
def get_sharing_url(page):
"""Get a sharing URL for the latest revision of a page, if available."""
url_parts = page.get_url_parts()
if url_parts is None:
# Page is not routable.
return None
site_id, root_url, page_path = url_parts
site = Site.objects.get(id=site_id)
try:
sharing_site = site.sharing_site
except SharingSite.DoesNotExist:
# Site is not shared.
return None
return sharing_site.root_url + page_path
示例2: ready
# 需要導入模塊: from wagtail.wagtailcore import models [as 別名]
# 或者: from wagtail.wagtailcore.models import Site [as 別名]
def ready(self):
# patch Site and Page models here
from wagtail.wagtailcore.models import AbstractPage, Page, Site
from wagtail.wagtailcore.query import PageQuerySet
from .manager import MultilingualPageManager
# fix PageManager to inherit from MultilingualManager
# since automatic manager patching no longer works (Django 1.10 and newer)
AbstractPage.objects = MultilingualPageManager()
AbstractPage.objects.contribute_to_class(AbstractPage, 'objects')
Page.objects = MultilingualPageManager()
Page.objects.contribute_to_class(Page, 'objects')
page_patch = import_module('wagtail_translation.page_patch')
site_patch = import_module('wagtail_translation.site_patch')
query_patch = import_module('wagtail_translation.query_patch')
for name in page_patch.__all__:
setattr(Page, name, getattr(page_patch, name))
for name in site_patch.__all__:
setattr(Site, name, getattr(site_patch, name))
for name in query_patch.__all__:
setattr(PageQuerySet, name, getattr(query_patch, name))
示例3: get_site_root_paths
# 需要導入模塊: from wagtail.wagtailcore import models [as 別名]
# 或者: from wagtail.wagtailcore.models import Site [as 別名]
def get_site_root_paths():
lang = get_language()
cache_key = ROOT_PATHS_CACHE_KEY_FMT.format(lang)
result = cache.get(cache_key)
if result is None:
result = [
(site.id, site.root_page.url_path, site.root_url)
for site in Site.objects.select_related('root_page').order_by('-root_page__url_path')
]
cache.set(cache_key, result, 3600)
return result
示例4: handle
# 需要導入模塊: from wagtail.wagtailcore import models [as 別名]
# 或者: from wagtail.wagtailcore.models import Site [as 別名]
def handle(self, **options):
fixtures_dir = os.path.join(settings.BASE_DIR, 'base', 'fixtures')
fixture_file = os.path.join(fixtures_dir, 'bakerydemo.json')
# Wagtail creates default Site and Page instances during install, but we already have
# them in the data load. Remove the auto-generated ones.
if Site.objects.filter(hostname='localhost').exists():
Site.objects.get(hostname='localhost').delete()
if Page.objects.filter(title='Welcome to your new Wagtail site!').exists():
Page.objects.get(title='Welcome to your new Wagtail site!').delete()
call_command('loaddata', fixture_file, verbosity=0)
print("Awesome. Your data is loaded! The bakery's doors are almost ready to open...")
示例5: create_if_necessary
# 需要導入模塊: from wagtail.wagtailcore import models [as 別名]
# 或者: from wagtail.wagtailcore.models import Site [as 別名]
def create_if_necessary(cls, *args, **kwargs):
root = super().create_if_necessary(*args, **kwargs)
# create default Site if it doesn't exist
Site.objects.get_or_create(
hostname='localhost',
defaults={
'root_page': root,
'is_default_site': True
}
)
return root
示例6: site
# 需要導入模塊: from wagtail.wagtailcore import models [as 別名]
# 或者: from wagtail.wagtailcore.models import Site [as 別名]
def site():
"""
Returns the Wagtail test Site, as provided in the
Django configuration settings
"""
from django.conf import settings
from wagtail.wagtailcore.models import Site
return Site.objects.get(id=settings.SITE_ID)