本文整理汇总了Python中wagtail.wagtailcore.models.Page方法的典型用法代码示例。如果您正苦于以下问题:Python models.Page方法的具体用法?Python models.Page怎么用?Python models.Page使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wagtail.wagtailcore.models
的用法示例。
在下文中一共展示了models.Page方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from wagtail.wagtailcore import models [as 别名]
# 或者: from wagtail.wagtailcore.models import Page [as 别名]
def __init__(self, *args, **kwargs):
"""
Create fields dicts without any translation fields.
"""
# Extend local fields, this ensures that Wagtail Page models are always
# extend on the local application, not on Wagtail itself (which would
# cause us to need migrations on wagtailcore!)
self.fields = list(self.fields)
self.fields += [
'search_description',
'seo_title',
'title',
]
super(TranslationOptions, self).__init__(*args, **kwargs)
示例2: delete_submission
# 需要导入模块: from wagtail.wagtailcore import models [as 别名]
# 或者: from wagtail.wagtailcore.models import Page [as 别名]
def delete_submission(request, page_id, submission_id):
if not get_surveys_for_user(request.user).filter(id=page_id).exists():
raise PermissionDenied
page = get_object_or_404(Page, id=page_id).specific
submission = get_object_or_404(page.get_submission_class(), id=submission_id)
if request.method == 'POST':
submission.delete()
messages.success(request, _("Submission deleted."))
return redirect('wagtailsurveys:list_submissions', page_id)
return render(request, 'wagtailsurveys/confirm_delete.html', {
'page': page,
'submission': submission
})
示例3: setUp
# 需要导入模块: from wagtail.wagtailcore import models [as 别名]
# 或者: from wagtail.wagtailcore.models import Page [as 别名]
def setUp(self):
home_page = Page.objects.get(slug='home')
blog_index_page = BlogIndexPage(
title='Blog',
slug='blog',
show_in_menus=True
)
home_page.add_child(instance=blog_index_page)
blog_posts = [
BlogPost(title='First Blog Post',
slug='first-blog-post',
date=datetime.date.today(),
byline='Author'),
BlogPost(title='Second Blog Post',
slug='second-blog-post',
date=datetime.date.today(),
byline='Author')
]
for blog_post in blog_posts:
blog_index_page.add_child(instance=blog_post)
示例4: full_clean
# 需要导入模块: from wagtail.wagtailcore import models [as 别名]
# 或者: from wagtail.wagtailcore.models import Page [as 别名]
def full_clean(self, *args, **kwargs):
# autogenerate slugs for non-empty title translation
for lang_code in mt_settings.AVAILABLE_LANGUAGES:
title_field = build_localized_fieldname('title', lang_code)
slug_field = build_localized_fieldname('slug', lang_code)
title = getattr(self, title_field)
slug = getattr(self, slug_field)
if title and not slug:
if DJANGO_VERSION >= (1, 9):
base_slug = slugify(title, allow_unicode=True)
else:
base_slug = slugify(title)
if base_slug:
setattr(self, slug_field, self._get_autogenerated_lang_slug(base_slug, lang_code))
super(Page, self).full_clean(*args, **kwargs)
示例5: move
# 需要导入模块: from wagtail.wagtailcore import models [as 别名]
# 或者: from wagtail.wagtailcore.models import Page [as 别名]
def move(self, target, pos=None):
old_self = Page.objects.get(id=self.id)
super(Page, self).move(target, pos=pos)
new_self = Page.objects.get(id=self.id)
# go through slugs to make sure they're available in new parent
# and auto-update if necessary
for lang_code in mt_settings.AVAILABLE_LANGUAGES:
slug_attr = build_localized_fieldname('slug', lang_code)
slug = getattr(new_self, slug_attr)
if slug:
slug = new_self._get_autogenerated_lang_slug(slug, lang_code)
setattr(new_self, slug_attr, slug)
new_self.set_url_path(new_self.get_parent())
new_self.save()
new_self._update_descendant_lang_url_paths(old_self)
logger.info("Page moved: \"%s\" id=%d path=%s", self.title, self.id, self.url_path)
示例6: requests_admin
# 需要导入模块: from wagtail.wagtailcore import models [as 别名]
# 或者: from wagtail.wagtailcore.models import Page [as 别名]
def requests_admin(request, pk):
"""Table display of each request for a given product.
Allows the given Page pk to refer to a direct parent of
the ProductVariant model or be the ProductVariant model itself.
This allows for the standard longclaw product modelling philosophy where
ProductVariant refers to the actual product (in the case where there is
only 1 variant) or to be variants of the product page.
"""
page = Page.objects.get(pk=pk).specific
if hasattr(page, 'variants'):
requests = ProductRequest.objects.filter(
variant__in=page.variants.all()
)
else:
requests = ProductRequest.objects.filter(variant=page)
return render(
request,
"productrequests/requests_admin.html",
{'page': page, 'requests': requests}
)
示例7: revisions_view
# 需要导入模块: from wagtail.wagtailcore import models [as 别名]
# 或者: from wagtail.wagtailcore.models import Page [as 别名]
def revisions_view(request, page_id, revision_id):
"""
Redirects to a frontend preview page of type:
`<frontend-preview-url>/<signature>/<page-id>/<revision-id>`
Where:
- frontend-preview-url: settings.FRONTEND_PREVIEW_URL
- signature: see the generate_preview_signature method
- page-id: id of the page
- revision-id: id of the revision
"""
if not settings.FRONTEND_PREVIEW_URL:
return HttpResponse(_('Please set FRONTEND_PREVIEW_URL in your settings.py'))
page = get_object_or_404(Page, id=page_id).specific
revision = get_object_or_404(page.revisions, id=revision_id)
signature = generate_preview_signature(page.id, revision.id)
return redirect(
settings.FRONTEND_PREVIEW_URL.format(
signature=signature.decode(),
page_id=page.id,
revision_id=revision.id
)
)
示例8: get_site_root
# 需要导入模块: from wagtail.wagtailcore import models [as 别名]
# 或者: from wagtail.wagtailcore.models import Page [as 别名]
def get_site_root(context):
"""Returns the site root Page, not the implementation-specific model used.
:rtype: `wagtail.wagtailcore.models.Page`
"""
return context['request'].site.root_page
示例9: slugurl
# 需要导入模块: from wagtail.wagtailcore import models [as 别名]
# 或者: from wagtail.wagtailcore.models import Page [as 别名]
def slugurl(context, slug):
"""Returns the URL for the page that has the given slug."""
page = Page.objects.filter(slug=slug).first()
if page:
return pageurl(context, page)
else:
return None
示例10: select_winner
# 需要导入模块: from wagtail.wagtailcore import models [as 别名]
# 或者: from wagtail.wagtailcore.models import Page [as 别名]
def select_winner(request, experiment_id, variation_id):
if not request.user.has_perm('experiments.change_experiment'):
raise PermissionDenied
experiment = get_object_or_404(Experiment, pk=experiment_id)
variation = get_object_or_404(Page, pk=variation_id)
if request.method == 'POST':
experiment.select_winner(variation)
messages.success(
request,
_("Page '{0}' has been selected as the winning variation.").format(variation.title),
)
return redirect('experiments:report', experiment.pk)
示例11: preview_for_report
# 需要导入模块: from wagtail.wagtailcore import models [as 别名]
# 或者: from wagtail.wagtailcore.models import Page [as 别名]
def preview_for_report(request, experiment_id, page_id):
experiment = get_object_or_404(Experiment, pk=experiment_id)
page = get_object_or_404(Page, id=page_id).specific
if not page.permissions_for_user(request.user).can_publish():
raise PermissionDenied
# hack the title and page-tree-related fields to match the control page
impersonate_other_page(page, experiment.control_page)
# pass in the real user request rather than page.dummy_request(), so that request.user
# and request.revision_id will be picked up by the wagtail user bar
return page.serve_preview(request, page.default_preview_mode)
示例12: test_frontend_cache_invalidation
# 需要导入模块: from wagtail.wagtailcore import models [as 别名]
# 或者: from wagtail.wagtailcore.models import Page [as 别名]
def test_frontend_cache_invalidation(self, mock_purge_page_from_cache):
"""When a BlogPost is published or unpublished, we should invalidate
the frontend cache for the corresponding BlogIndexPage."""
blog_index_page = BlogIndexPage.objects.first()
new_blog_post = BlogPost(
title='New Blog Post',
slug='new-blog-post',
date=datetime.date.today(),
byline='Author'
)
blog_index_page.add_child(instance=new_blog_post)
# Publishing a BlogPost should trigger frontend cache invalidation for
# the corresponding BlogIndexPage.
#
# XXX: For some reason, Wagtail uses the generic Page object as the
# instance for the page_published signal, but uses the specific object
# (e.g. BlogIndexPage) as the instance for the page_unpublished signal.
# You can get the generic Page object from a specific object with
# .page_ptr, or go the other way with .specific. For more, see:
# http://docs.wagtail.io/en/v1.8/topics/pages.html#working-with-pages
new_blog_post.save_revision().publish()
mock_purge_page_from_cache.assert_called_once_with(
blog_index_page.page_ptr)
# Unpublishing the BlogPost should also trigger frontend cache
# invalidation for the corresponding BlogIndexPage.
mock_purge_page_from_cache.reset_mock()
new_blog_post.unpublish()
mock_purge_page_from_cache.assert_called_once_with(blog_index_page)
示例13: test_page_str
# 需要导入模块: from wagtail.wagtailcore import models [as 别名]
# 或者: from wagtail.wagtailcore.models import Page [as 别名]
def test_page_str(self):
page_block = PageBlock(
page=Page(title='Title', slug='title'),
block='path.to.block'
)
self.assertEqual(str(page_block), '<Title, path.to.block>')
示例14: get_url_for_object
# 需要导入模块: from wagtail.wagtailcore import models [as 别名]
# 或者: from wagtail.wagtailcore.models import Page [as 别名]
def get_url_for_object(object):
"""
"""
if isinstance(object, Page):
return object.url
else:
return object.get_absolute_uri()
示例15: test_inheritance
# 需要导入模块: from wagtail.wagtailcore import models [as 别名]
# 或者: from wagtail.wagtailcore.models import Page [as 别名]
def test_inheritance(self):
self.assertTrue(issubclass(PageRedirection, Page))