本文整理汇总了Python中cms.models.Page方法的典型用法代码示例。如果您正苦于以下问题:Python models.Page方法的具体用法?Python models.Page怎么用?Python models.Page使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cms.models
的用法示例。
在下文中一共展示了models.Page方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: record_plugin_history
# 需要导入模块: from cms import models [as 别名]
# 或者: from cms.models import Page [as 别名]
def record_plugin_history(self, sender, instance, **kwargs):
"""When a plugin is created or edited"""
from cms.models import CMSPlugin, Page
from .models import EditHistory
if not isinstance(instance, CMSPlugin):
return
user_id = cache.get('cms-user-id')
comment = cache.get('cms-comment')
content = generate_content(instance)
if content is None:
return
# Don't record a history of change if nothing changed.
history = EditHistory.objects.filter(plugin_id=instance.id)
if history.count() > 0:
# Temporary history object for uuid
this = EditHistory(content=content)
latest = history.latest()
if latest.content == content or this.uuid == latest.uuid:
return
EditHistory.objects.record(instance, user_id, comment, content)
示例2: test_publish_page_extension
# 需要导入模块: from cms import models [as 别名]
# 或者: from cms.models import Page [as 别名]
def test_publish_page_extension(self):
page = create_page('Test Page Extension', "nav_playground.html", "en")
page_extension = MyPageExtension(extended_object=page, extra='page extension 1')
page_extension.save()
page.mypageextension = page_extension
# publish first time
page.publish('en')
self.assertEqual(page_extension.extra, page.publisher_public.mypageextension.extra)
self.assertEqual(page.get_publisher_state('en'), 0)
# change and publish again
page = Page.objects.get(pk=page.pk)
page_extension = page.mypageextension
page_extension.extra = 'page extension 1 - changed'
page_extension.save()
self.assertEqual(page.get_publisher_state('en', True), PUBLISHER_STATE_DIRTY)
page.publish('en')
self.assertEqual(page.get_publisher_state('en', True), 0)
# delete
page_extension.delete()
self.assertFalse(MyPageExtension.objects.filter(pk=page_extension.pk).exists())
self.assertEqual(page.get_publisher_state('en', True), PUBLISHER_STATE_DIRTY)
示例3: test_duplicate_extensions
# 需要导入模块: from cms import models [as 别名]
# 或者: from cms.models import Page [as 别名]
def test_duplicate_extensions(self):
with self.login_user_context(self.admin):
# create page copy
page_data = {
'title': 'type1', 'slug': 'type1', '_save': 1, 'template': 'nav_playground.html',
'site': 1, 'language': 'en'
}
self.assertEqual(Page.objects.all().count(), 2)
self.assertEqual(MyPageExtension.objects.all().count(), 1)
self.assertEqual(MyTitleExtension.objects.all().count(), 1)
self.client.post(
"%s?position=first-child©_target=%s&language=en" % (
URL_CMS_PAGE_ADD, self.page.pk
),
data=page_data)
# Check that page and its extensions have been copied
self.assertEqual(Page.objects.all().count(), 3)
self.assertEqual(MyPageExtension.objects.all().count(), 2)
self.assertEqual(MyTitleExtension.objects.all().count(), 2)
示例4: test_get_success_url
# 需要导入模块: from cms import models [as 别名]
# 或者: from cms.models import Page [as 别名]
def test_get_success_url(self):
user = self.get_superuser()
page = create_page(
title="Sample Page",
template=TEMPLATE_INHERITANCE_MAGIC,
language="en",
created_by=smart_text(user),
parent=None,
in_navigation=True,
published=False
)
url = "{0}?edit".format(page.get_absolute_url(language="en"))
self.assertEqual(self.page_wizard.get_success_url(
page, language="en"), url)
# Now again without a language code
url = "{0}?edit".format(page.get_absolute_url())
self.assertEqual(self.page_wizard.get_success_url(page), url)
示例5: test_page_create_redirect
# 需要导入模块: from cms import models [as 别名]
# 或者: from cms.models import Page [as 别名]
def test_page_create_redirect(self):
superuser = self.get_superuser()
page = create_page("home", "nav_playground.html", "en",
published=True)
resolve_url_on = '%s?%s' % (admin_reverse('cms_page_resolve'),
get_cms_setting('CMS_TOOLBAR_URL__EDIT_ON'))
resolve_url_off = '%s?%s' % (admin_reverse('cms_page_resolve'),
get_cms_setting('CMS_TOOLBAR_URL__EDIT_OFF'))
with self.login_user_context(superuser):
response = self.client.post(resolve_url_on, {'pk': '', 'model': 'cms.page'})
self.assertEqual(response.content.decode('utf-8'), '')
page_data = self.get_new_page_data(parent_id=page.pk)
self.client.post(URL_CMS_PAGE_ADD, page_data)
# test redirection when toolbar is in edit mode
response = self.client.post(resolve_url_on, {'pk': Page.objects.all()[2].pk,
'model': 'cms.page'})
self.assertEqual(response.content.decode('utf-8'), '/en/test-page-1/')
self.client.post(URL_CMS_PAGE_ADD, page_data)
# test redirection when toolbar is not in edit mode
response = self.client.post(resolve_url_off, {'pk': Page.objects.all()[2].pk,
'model': 'cms.page'})
self.assertEqual(response.content.decode('utf-8'), '/en/')
示例6: set_dirty
# 需要导入模块: from cms import models [as 别名]
# 或者: from cms.models import Page [as 别名]
def set_dirty(plugin, delete_cache=True):
placeholder = get_placeholder(plugin)
if placeholder:
language = plugin.language
if delete_cache:
clear_placeholder_cache(placeholder, language)
attached_model = placeholder._get_attached_model()
if attached_model is Page:
Title.objects.filter(page=placeholder.page, language=language).update(publisher_state=PUBLISHER_STATE_DIRTY)
elif attached_model is StaticPlaceholder:
StaticPlaceholder.objects.filter(draft=placeholder).update(dirty=True)
示例7: update_permission_fieldsets
# 需要导入模块: from cms import models [as 别名]
# 或者: from cms.models import Page [as 别名]
def update_permission_fieldsets(self, request, obj=None):
"""
Nobody can grant more than he haves, so check for user permissions
to Page and User model and render fieldset depending on them.
"""
fieldsets = deepcopy(self.fieldsets)
perm_models = (
(Page, ugettext('Page permissions')),
(PageUser, ugettext('User & Group permissions')),
(PagePermission, ugettext('Page permissions management')),
)
for i, perm_model in enumerate(perm_models):
model, title = perm_model
opts, fields = model._meta, []
name = model.__name__.lower()
for key in ('add', 'change', 'delete'):
perm_code = '%s.%s' % (opts.app_label, get_permission_codename(key, opts))
if request.user.has_perm(perm_code):
fields.append('can_%s_%s' % (key, name))
if fields:
fieldsets.insert(2 + i, (title, {'fields': (fields,)}))
return fieldsets
示例8: get_queryset
# 需要导入模块: from cms import models [as 别名]
# 或者: from cms.models import Page [as 别名]
def get_queryset(self, request):
if COPY_VAR in self.params:
del self.params[COPY_VAR]
if 'language' in self.params:
del self.params['language']
if 'page_id' in self.params:
del self.params['page_id']
qs = super(CMSChangeList, self).get_queryset(request).drafts()
site = self.current_site()
permissions = Page.permissions.get_change_id_list(request.user, site)
if permissions != Page.permissions.GRANT_ALL:
qs = qs.filter(pk__in=permissions)
self.root_queryset = self.root_queryset.filter(pk__in=permissions)
self.real_queryset = True
qs = qs.filter(site=self._current_site)
return qs
示例9: get_copy_dialog
# 需要导入模块: from cms import models [as 别名]
# 或者: from cms.models import Page [as 别名]
def get_copy_dialog(request, page_id):
if not get_cms_setting('PERMISSION'):
return HttpResponse('')
target_id = request.GET.get('target', False) or request.POST.get('target', False)
callback = request.GET.get('callback', False) or request.POST.get('callback', False)
page = get_object_or_404(Page, pk=page_id)
if target_id:
target = get_object_or_404(Page, pk=target_id)
if not page.has_change_permission(request) or (
target_id and not target.has_add_permission(request)):
raise Http404
context = {
'dialog_id': 'dialog-copy',
'form': PermissionForm(), # class needs to be instantiated
'callback': callback,
}
return render(request, "admin/cms/page/tree/copy_premissions.html", context)
示例10: ready
# 需要导入模块: from cms import models [as 别名]
# 或者: from cms.models import Page [as 别名]
def ready(self):
from cms.models import CMSPlugin, Page
from cms.signals import post_publish
from .cms_toolbar import DiffToolbar
signals.pre_save.connect(self.ensure_initial)
signals.post_save.connect(self.record_plugin_history)
post_publish.connect(self.record_history, sender=Page)
示例11: page
# 需要导入模块: from cms import models [as 别名]
# 或者: from cms.models import Page [as 别名]
def page(self):
obj = self.get_queryset()._hints.get('instance', None)
if isinstance(obj, Page):
return obj
示例12: decompress
# 需要导入模块: from cms import models [as 别名]
# 或者: from cms.models import Page [as 别名]
def decompress(self, value):
"""
receives a page_id in value and returns the site_id and page_id
of that page or the current site_id and None if no page_id is given.
"""
if value:
page = Page.objects.get(pk=value)
site = page.site
return [site.pk, page.pk, page.pk]
site = Site.objects.get_current()
return [site.pk,None,None]
示例13: public
# 需要导入模块: from cms import models [as 别名]
# 或者: from cms.models import Page [as 别名]
def public(self):
return super(PageManager, self).public()
# !IMPORTANT: following methods always return access to draft instances,
# take care on what you do one them. use Page.objects.public() for accessing
# the published page versions
# Just some of the queryset methods are implemented here, access queryset
# for more getting more supporting methods.
# TODO: check which from following methods are really required to be on
# manager, maybe some of them can be just accessible over queryset...?
示例14: get_restricted_id_list
# 需要导入模块: from cms import models [as 别名]
# 或者: from cms.models import Page [as 别名]
def get_restricted_id_list(self, site):
from cms.models import (GlobalPagePermission, PagePermission,
MASK_CHILDREN, MASK_DESCENDANTS, MASK_PAGE)
global_permissions = GlobalPagePermission.objects.all()
if global_permissions.filter(Q(sites__in=[site]) | Q(sites__isnull=True)
).filter(can_view=True).exists():
# user or his group are allowed to do `attr` action
# !IMPORTANT: page permissions must not override global permissions
from cms.models import Page
return Page.objects.filter(site=site).values_list('id', flat=True)
# for standard users without global permissions, get all pages for him or
# his group/s
qs = PagePermission.objects.filter(page__site=site, can_view=True).select_related('page')
qs.order_by('page__path')
# default is denny...
page_id_allow_list = []
for permission in qs:
if permission.grant_on & MASK_PAGE:
page_id_allow_list.append(permission.page_id)
if permission.grant_on & MASK_CHILDREN:
page_id_allow_list.extend(permission.page.get_children().values_list('id', flat=True))
elif permission.grant_on & MASK_DESCENDANTS:
page_id_allow_list.extend(permission.page.get_descendants().values_list('id', flat=True))
# store value in cache
return page_id_allow_list
示例15: get_on_delete_redirect_url
# 需要导入模块: from cms import models [as 别名]
# 或者: from cms.models import Page [as 别名]
def get_on_delete_redirect_url(self):
parent, language = self.page.parent, self.current_lang
# if the current page has a parent in the request's current language redirect to it
if parent and language in parent.get_languages():
with force_language(language):
return parent.get_absolute_url(language=language)
# else redirect to root, do not redirect to Page.objects.get_home() because user could have deleted the last
# page, if DEBUG == False this could cause a 404
return reverse('pages-root')
# Populate