当前位置: 首页>>代码示例>>Python>>正文


Python models.UserPagePermissionsProxy类代码示例

本文整理汇总了Python中wagtail.wagtailcore.models.UserPagePermissionsProxy的典型用法代码示例。如果您正苦于以下问题:Python UserPagePermissionsProxy类的具体用法?Python UserPagePermissionsProxy怎么用?Python UserPagePermissionsProxy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了UserPagePermissionsProxy类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: unpublish

def unpublish(request, page_id):
    page = get_object_or_404(Page, id=page_id).specific

    user_perms = UserPagePermissionsProxy(request.user)
    if not user_perms.for_page(page).can_unpublish():
        raise PermissionDenied

    next_url = get_valid_next_url_from_request(request)

    if request.method == 'POST':
        include_descendants = request.POST.get("include_descendants", False)

        page.unpublish()

        if include_descendants:
            live_descendant_pages = page.get_descendants().live().specific()
            for live_descendant_page in live_descendant_pages:
                if user_perms.for_page(live_descendant_page).can_unpublish():
                    live_descendant_page.unpublish()

        messages.success(request, _("Page '{0}' unpublished.").format(page.title), buttons=[
            messages.button(reverse('wagtailadmin_pages:edit', args=(page.id,)), _('Edit'))
        ])

        if next_url:
            return redirect(next_url)
        return redirect('wagtailadmin_explore', page.get_parent().id)

    return render(request, 'wagtailadmin/pages/confirm_unpublish.html', {
        'page': page,
        'next': next_url,
        'live_descendant_count': page.get_descendants().live().count(),
    })
开发者ID:bmihelac,项目名称:wagtail,代码行数:33,代码来源:pages.py

示例2: test_lock_page_for_moderator

    def test_lock_page_for_moderator(self):
        user = get_user_model().objects.get(username='eventmoderator')
        christmas_page = EventPage.objects.get(url_path='/home/events/christmas/')

        perms = UserPagePermissionsProxy(user).for_page(christmas_page)

        self.assertTrue(perms.can_lock())
开发者ID:Tivix,项目名称:wagtail,代码行数:7,代码来源:test_page_permissions.py

示例3: test_editable_pages_for_non_editing_user

    def test_editable_pages_for_non_editing_user(self):
        user = get_user_model().objects.get(username='admin_only_user')
        homepage = Page.objects.get(url_path='/home/')
        christmas_page = EventPage.objects.get(url_path='/home/events/christmas/')
        unpublished_event_page = EventPage.objects.get(url_path='/home/events/tentative-unpublished-event/')
        someone_elses_event_page = EventPage.objects.get(url_path='/home/events/someone-elses-event/')

        user_perms = UserPagePermissionsProxy(user)
        editable_pages = user_perms.editable_pages()
        can_edit_pages = user_perms.can_edit_pages()
        publishable_pages = user_perms.publishable_pages()
        can_publish_pages = user_perms.can_publish_pages()

        self.assertFalse(editable_pages.filter(id=homepage.id).exists())
        self.assertFalse(editable_pages.filter(id=christmas_page.id).exists())
        self.assertFalse(editable_pages.filter(id=unpublished_event_page.id).exists())
        self.assertFalse(editable_pages.filter(id=someone_elses_event_page.id).exists())

        self.assertFalse(can_edit_pages)

        self.assertFalse(publishable_pages.filter(id=homepage.id).exists())
        self.assertFalse(publishable_pages.filter(id=christmas_page.id).exists())
        self.assertFalse(publishable_pages.filter(id=unpublished_event_page.id).exists())
        self.assertFalse(publishable_pages.filter(id=someone_elses_event_page.id).exists())

        self.assertFalse(can_publish_pages)
开发者ID:Tivix,项目名称:wagtail,代码行数:26,代码来源:test_page_permissions.py

示例4: unpublish

def unpublish(request, page_id):
    page = get_object_or_404(Page, id=page_id).specific

    user_perms = UserPagePermissionsProxy(request.user)
    if not user_perms.for_page(page).can_unpublish():
        raise PermissionDenied

    next_url = get_valid_next_url_from_request(request)

    if request.method == "POST":
        include_descendants = request.POST.get("include_descendants", False)

        page.unpublish()

        if include_descendants:
            live_descendant_pages = page.get_descendants().live().specific()
            for live_descendant_page in live_descendant_pages:
                if user_perms.for_page(live_descendant_page).can_unpublish():
                    live_descendant_page.unpublish()

        messages.success(
            request,
            _("Page '{0}' unpublished.").format(page.get_admin_display_title()),
            buttons=[messages.button(reverse("wagtailadmin_pages:edit", args=(page.id,)), _("Edit"))],
        )

        if next_url:
            return redirect(next_url)
        return redirect("wagtailadmin_explore", page.get_parent().id)

    return render(
        request,
        "wagtailadmin/pages/confirm_unpublish.html",
        {"page": page, "next": next_url, "live_descendant_count": page.get_descendants().live().count()},
    )
开发者ID:mvantellingen,项目名称:wagtail,代码行数:35,代码来源:pages.py

示例5: test_lock_page_for_non_editing_user

    def test_lock_page_for_non_editing_user(self):
        user = get_user_model().objects.get(username='admin_only_user')
        christmas_page = EventPage.objects.get(url_path='/home/events/christmas/')

        perms = UserPagePermissionsProxy(user).for_page(christmas_page)

        self.assertFalse(perms.can_lock())
开发者ID:Tivix,项目名称:wagtail,代码行数:7,代码来源:test_page_permissions.py

示例6: test_editable_pages_for_user_with_edit_permission

    def test_editable_pages_for_user_with_edit_permission(self):
        event_moderator = get_user_model().objects.get(username="eventmoderator")
        homepage = Page.objects.get(url_path="/home/")
        christmas_page = EventPage.objects.get(url_path="/home/events/christmas/")
        unpublished_event_page = EventPage.objects.get(url_path="/home/events/tentative-unpublished-event/")
        someone_elses_event_page = EventPage.objects.get(url_path="/home/events/someone-elses-event/")

        user_perms = UserPagePermissionsProxy(event_moderator)
        editable_pages = user_perms.editable_pages()
        can_edit_pages = user_perms.can_edit_pages()
        publishable_pages = user_perms.publishable_pages()
        can_publish_pages = user_perms.can_publish_pages()

        self.assertFalse(editable_pages.filter(id=homepage.id).exists())
        self.assertTrue(editable_pages.filter(id=christmas_page.id).exists())
        self.assertTrue(editable_pages.filter(id=unpublished_event_page.id).exists())
        self.assertTrue(editable_pages.filter(id=someone_elses_event_page.id).exists())

        self.assertTrue(can_edit_pages)

        self.assertFalse(publishable_pages.filter(id=homepage.id).exists())
        self.assertTrue(publishable_pages.filter(id=christmas_page.id).exists())
        self.assertTrue(publishable_pages.filter(id=unpublished_event_page.id).exists())
        self.assertTrue(publishable_pages.filter(id=someone_elses_event_page.id).exists())

        self.assertTrue(can_publish_pages)
开发者ID:romali,项目名称:wagtail,代码行数:26,代码来源:test_page_permissions.py

示例7: account

def account(request):
    user_perms = UserPagePermissionsProxy(request.user)
    show_notification_preferences = user_perms.can_edit_pages() or user_perms.can_publish_pages()

    return render(request, 'wagtailadmin/account/account.html', {
        'show_change_password': password_management_enabled() and request.user.has_usable_password(),
        'show_notification_preferences': show_notification_preferences
    })
开发者ID:didorothy,项目名称:wagtail,代码行数:8,代码来源:account.py

示例8: account

def account(request):
    user_perms = UserPagePermissionsProxy(request.user)
    show_notification_preferences = user_perms.can_edit_pages() or user_perms.can_publish_pages()

    return render(request, 'wagtailadmin/account/account.html', {
        'show_change_password': getattr(settings, 'WAGTAIL_PASSWORD_MANAGEMENT_ENABLED', True) and request.user.has_usable_password(),
        'show_notification_preferences': show_notification_preferences
    })
开发者ID:akrawchyk,项目名称:wagtail,代码行数:8,代码来源:account.py

示例9: __init__

 def __init__(self, *args, **kwargs):
     super(NotificationPreferencesForm, self).__init__(*args, **kwargs)
     user_perms = UserPagePermissionsProxy(self.instance.user)
     if not user_perms.can_publish_pages():
         del self.fields['submitted_notifications']
     if not user_perms.can_edit_pages():
         del self.fields['approved_notifications']
         del self.fields['rejected_notifications']
开发者ID:dRockolla,项目名称:wagtail,代码行数:8,代码来源:forms.py

示例10: find_rca_now_index_page

def find_rca_now_index_page(user):
    """Look for the RCA Now index page: a page of type RcaNowIndex where this user can add pages"""
    user_perms = UserPagePermissionsProxy(user)

    for page in RcaNowIndex.objects.all():
        if user_perms.for_page(page).can_add_subpage():
            return page

    raise Exception('No usable RCA Now section found (using the RcaNowIndex page type and with add permission for students)')
开发者ID:spapas,项目名称:verdant-rca,代码行数:9,代码来源:admin_views.py

示例11: find_student_index_page

def find_student_index_page(user):
    """Look for the student index page: a page of type StandardIndex with slug "students" where this user can add pages"""
    user_perms = UserPagePermissionsProxy(user)

    for page in StandardIndex.objects.filter(slug='students'):
        if user_perms.for_page(page).can_add_subpage():
            return page

    raise Exception('No usable student index found (using the StandardIndex page type and with add permission for students)')
开发者ID:spapas,项目名称:verdant-rca,代码行数:9,代码来源:admin_views.py

示例12: test_lock_page_for_superuser

    def test_lock_page_for_superuser(self):
        user = get_user_model().objects.get(username='superuser')
        christmas_page = EventPage.objects.get(url_path='/home/events/christmas/')
        locked_page = Page.objects.get(url_path='/home/my-locked-page/')

        perms = UserPagePermissionsProxy(user).for_page(christmas_page)
        locked_perms = UserPagePermissionsProxy(user).for_page(locked_page)

        self.assertTrue(perms.can_lock())
        self.assertFalse(locked_perms.can_unpublish())  # locked pages can't be unpublished
开发者ID:Tivix,项目名称:wagtail,代码行数:10,代码来源:test_page_permissions.py

示例13: get_forms_for_user

def get_forms_for_user(user):
    """
    Return a queryset of form pages that this user is allowed to access the submissions for
    """
    editable_forms = UserPagePermissionsProxy(user).editable_pages()
    editable_forms = editable_forms.filter(content_type__in=get_form_types())

    # Apply hooks
    for fn in hooks.get_hooks('filter_form_submissions_for_user'):
        editable_forms = fn(user, editable_forms)

    return editable_forms
开发者ID:thenewguy,项目名称:wagtail,代码行数:12,代码来源:models.py

示例14: test_editable_pages_for_superuser

    def test_editable_pages_for_superuser(self):
        user = User.objects.get(username='superuser')
        homepage = Page.objects.get(url_path='/home/')
        christmas_page = EventPage.objects.get(url_path='/home/events/christmas/')
        unpublished_event_page = EventPage.objects.get(url_path='/home/events/tentative-unpublished-event/')
        someone_elses_event_page = EventPage.objects.get(url_path='/home/events/someone-elses-event/')

        editable_pages = UserPagePermissionsProxy(user).editable_pages()

        self.assertTrue(editable_pages.filter(id=homepage.id).exists())
        self.assertTrue(editable_pages.filter(id=christmas_page.id).exists())
        self.assertTrue(editable_pages.filter(id=unpublished_event_page.id).exists())
        self.assertTrue(editable_pages.filter(id=someone_elses_event_page.id).exists())
开发者ID:rockingskier,项目名称:wagtail,代码行数:13,代码来源:tests.py

示例15: push_to_intranet

def push_to_intranet(request, page_id):
    # Get page
    page = get_object_or_404(Page, id=page_id)

    # User must have publish permission
    user_perms = UserPagePermissionsProxy(request.user)
    page_perms = user_perms.for_page(page)
    if not page_perms.can_publish():
        raise PermissionDenied

    if request.method == "POST":
        # Perform request
        url = settings.INTRANET_PUSH_URL.format(
            type=page._meta.app_label + '.' + page.__class__.__name__,
            id=page.id,
        )
        response = requests.post(url)

        if response.status_code == 200:
            intranet_url = response.json()['public_url']

            # Success message
            message = "Successfully pushed '{0}' to the intranet.".format(page.title)
            messages.success(request, message, buttons=[
                messages.button(
                    intranet_url,
                    'View on intranet'
                ),
            ])
        else:
            # Error message
            message = "Error received while pushing '{0}' to the intranet. (status code: {1})".format(page.title, request.status_code)
            messages.error(request, message)

        return redirect('wagtailadmin_explore', page.get_parent().id)

    return render(request, 'rca/admin/push_to_intranet.html', {
        'page': page,
    })
开发者ID:spapas,项目名称:verdant-rca,代码行数:39,代码来源:admin_views.py


注:本文中的wagtail.wagtailcore.models.UserPagePermissionsProxy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。