本文整理汇总了Python中pages.permissions.PagePermission类的典型用法代码示例。如果您正苦于以下问题:Python PagePermission类的具体用法?Python PagePermission怎么用?Python PagePermission使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PagePermission类的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_permissions
def test_permissions(self):
"""Test the permissions lightly."""
from pages.permissions import PagePermission
admin = User.objects.get(username='admin')
page = self.new_page()
pp = PagePermission(user=page.author)
self.assertTrue(pp.check('change', page=page, method='GET'))
self.assertTrue(pp.check('change', page=page, method='POST'))
staff = User.objects.get(username='staff')
pp = PagePermission(user=staff)
# weird because nonstaff?
self.assertTrue(pp.check('change', page=page, method='GET',
lang='en-us'))
self.assertFalse(pp.check('change', page=page, method='POST',
lang='en-us'))
self.assertFalse(pp.check('delete', page=page, method='POST',
lang='en-us'))
self.assertFalse(pp.check('add', page=page, method='POST',
lang='en-us'))
self.assertFalse(pp.check('freeze', page=page, method='POST',
lang='en-us'))
self.assertFalse(pp.check('doesnotexist', page=page, method='POST',
lang='en-us'))
示例2: list_pages
def list_pages(self, request, template_name=None, extra_context=None):
"""List root pages"""
if not admin.site.has_permission(request):
return admin.site.login(request)
language = get_language_from_request(request)
query = request.POST.get('q', '').strip()
if query:
page_ids = list(set([c.page.pk for c in
Content.objects.filter(body__icontains=query)]))
pages = Page.objects.filter(pk__in=page_ids)
else:
pages = Page.objects.root()
if settings.PAGE_HIDE_SITES:
pages = pages.filter(sites=settings.SITE_ID)
perms = PagePermission(request.user)
context = {
'can_publish': perms.check('publish'),
'language': language,
'name': _("page"),
'pages': pages,
'opts': self.model._meta,
'q': query
}
context.update(extra_context or {})
change_list = self.changelist_view(request, context)
return change_list
示例3: get_fieldsets
def get_fieldsets(self, request, obj=None):
"""
Add fieldsets of placeholders to the list of already
existing fieldsets.
"""
general_fields = list(self.general_fields)
perms = PagePermission(request.user)
# some ugly business to remove freeze_date
# from the field list
general_module = {
'fields': list(self.general_fields),
'classes': ('module-general',),
}
default_fieldsets = list(self.fieldsets)
if not perms.check('freeze'):
general_module['fields'].remove('freeze_date')
default_fieldsets[0][1] = general_module
placeholder_fieldsets = []
template = get_template_from_request(request, obj)
for placeholder in get_placeholders(template):
if placeholder.name not in self.mandatory_placeholders:
placeholder_fieldsets.append(placeholder.name)
additional_fieldsets = []
additional_fieldsets.append((_('Content'), {
'fields': placeholder_fieldsets,
'classes': ('module-content',),
}))
return default_fieldsets + additional_fieldsets
示例4: list_pages
def list_pages(self, request, template_name=None, extra_context=None):
"""List root pages"""
if not admin.site.has_permission(request):
return admin.site.login(request)
language = get_language_from_request(request)
query = request.POST.get("q", "").strip()
if query:
page_ids = list(set([c.page.pk for c in Content.objects.filter(body__icontains=query)]))
pages = Page.objects.filter(pk__in=page_ids)
else:
pages = Page.objects.filter(parent__isnull=True)
if settings.PAGE_HIDE_SITES:
pages = pages.filter(sites=settings.SITE_ID)
perms = PagePermission(request.user)
context = {
"can_publish": perms.check("publish"),
"language": language,
"name": _("page"),
"pages": pages,
"opts": self.model._meta,
"q": query,
}
context.update(extra_context or {})
change_list = self.changelist_view(request, context)
return change_list
示例5: get_fieldsets
def get_fieldsets(self, request, obj=None):
"""
Add fieldsets of placeholders to the list of already
existing fieldsets.
"""
general_fields = list(self.general_fields)
perms = PagePermission(request.user)
# some ugly business to remove freeze_date
# from the field list
general_module = {"fields": list(self.general_fields), "classes": ("module-general",)}
default_fieldsets = list(self.fieldsets)
if not perms.check("freeze"):
general_module["fields"].remove("freeze_date")
if not perms.check("publish"):
general_module["fields"].remove("status")
default_fieldsets[0][1] = general_module
placeholder_fieldsets = []
template = get_template_from_request(request, obj)
for placeholder in get_placeholders(template):
if placeholder.name not in self.mandatory_placeholders:
placeholder_fieldsets.append(placeholder.name)
additional_fieldsets = []
additional_fieldsets.append((_("Content"), {"fields": placeholder_fieldsets, "classes": ("module-content",)}))
return default_fieldsets + additional_fieldsets
示例6: list_pages_ajax
def list_pages_ajax(request, invalid_move=False):
"""Render pages table for ajax function."""
language = get_language_from_request(request)
pages = Page.objects.root()
perms = PagePermission(request.user)
context = {
'can_publish': perms.check('publish'),
'invalid_move':invalid_move,
'language': language,
'pages': pages,
}
return "admin/pages/page/change_list_table.html", context
示例7: sub_menu
def sub_menu(request, page_id):
"""Render the children of the requested page with the sub_menu
template."""
page = Page.objects.get(id=page_id)
pages = page.children.all()
page_languages = settings.PAGE_LANGUAGES
perms = PagePermission(request.user)
return render_to_response("admin/pages/page/sub_menu.html", {
'can_publish': perms.check('publish'),
'page':page,
'pages':pages,
'page_languages':page_languages,
}, context_instance=RequestContext(request))
示例8: test_permissions
def test_permissions(self):
"""Test the permissions lightly."""
from pages.permissions import PagePermission
admin = User.objects.get(username='admin')
page = Page(author=admin, status=Page.PUBLISHED)
page.save()
pp = PagePermission(user=admin)
self.assertTrue(pp.check('change', page=page, method='GET'))
self.assertTrue(pp.check('change', page=page, method='POST'))
staff = User.objects.get(username='staff')
pp = PagePermission(user=staff)
# weird because nonstaff?
self.assertTrue(pp.check('change', page=page, method='GET',
lang='en-us'))
self.assertFalse(pp.check('change', page=page, method='POST',
lang='en-us'))