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


Python utils.permission_denied函数代码示例

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


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

示例1: dispatch

    def dispatch(self, request, *args, **kwargs):
        if self.permission_policy is not None:

            if self.permission_required is not None:
                if not self.permission_policy.user_has_permission(request.user, self.permission_required):
                    return permission_denied(request)

            if self.any_permission_required is not None:
                if not self.permission_policy.user_has_any_permission(request.user, self.any_permission_required):
                    return permission_denied(request)

        return super(PermissionCheckedMixin, self).dispatch(request, *args, **kwargs)
开发者ID:shredding,项目名称:wagtail,代码行数:12,代码来源:generic.py

示例2: edit

def edit(request, redirect_id):
    theredirect = get_object_or_404(models.Redirect, id=redirect_id)

    if not permission_policy.user_has_permission_for_instance(request.user, "change", theredirect):
        return permission_denied(request)

    if request.POST:
        form = RedirectForm(request.POST, request.FILES, instance=theredirect)
        if form.is_valid():
            form.save()
            messages.success(
                request,
                _("Redirect '{0}' updated.").format(theredirect.title),
                buttons=[messages.button(reverse("wagtailredirects:edit", args=(theredirect.id,)), _("Edit"))],
            )
            return redirect("wagtailredirects:index")
        else:
            messages.error(request, _("The redirect could not be saved due to errors."))
    else:
        form = RedirectForm(instance=theredirect)

    return render(
        request,
        "wagtailredirects/edit.html",
        {
            "redirect": theredirect,
            "form": form,
            "user_can_delete": permission_policy.user_has_permission(request.user, "delete"),
        },
    )
开发者ID:thrawny,项目名称:wagtail,代码行数:30,代码来源:views.py

示例3: delete

def delete(request, content_type_app_name, content_type_model_name, id):
    content_type = get_content_type_from_url_params(content_type_app_name, content_type_model_name)
    model = content_type.model_class()

    permission = get_permission_name("delete", model)
    if not request.user.has_perm(permission):
        return permission_denied(request)

    snippet_type_name = get_snippet_type_name(content_type)[0]

    instance = get_object_or_404(model, id=id)

    if request.POST:
        instance.delete()
        messages.success(
            request,
            _("{snippet_type} '{instance}' deleted.").format(
                snippet_type=capfirst(snippet_type_name), instance=instance
            ),
        )
        return redirect("wagtailsnippets:list", content_type.app_label, content_type.model)

    return render(
        request,
        "wagtailsnippets/snippets/confirm_delete.html",
        {"content_type": content_type, "snippet_type_name": snippet_type_name, "instance": instance},
    )
开发者ID:niceguydave,项目名称:wagtail,代码行数:27,代码来源:snippets.py

示例4: list

def list(request, content_type_app_name, content_type_model_name):
    content_type = get_content_type_from_url_params(content_type_app_name, content_type_model_name)
    model = content_type.model_class()

    permissions = [
        get_permission_name(action, model)
        for action in ['add', 'change', 'delete']
    ]
    if not any([request.user.has_perm(perm) for perm in permissions]):
        return permission_denied(request)

    snippet_type_name, snippet_type_name_plural = get_snippet_type_name(content_type)

    items = model.objects.all()

    # Pagination
    p = request.GET.get('p', 1)
    paginator = Paginator(items, 20)

    try:
        paginated_items = paginator.page(p)
    except PageNotAnInteger:
        paginated_items = paginator.page(1)
    except EmptyPage:
        paginated_items = paginator.page(paginator.num_pages)

    return render(request, 'wagtailsnippets/snippets/type_index.html', {
        'content_type': content_type,
        'snippet_type_name': snippet_type_name,
        'snippet_type_name_plural': snippet_type_name_plural,
        'items': paginated_items,
        'can_add_snippet': request.user.has_perm(get_permission_name('add', model)),
    })
开发者ID:njamaleddine,项目名称:wagtail,代码行数:33,代码来源:snippets.py

示例5: edit

def edit(request, redirect_id):
    theredirect = get_object_or_404(models.Redirect, id=redirect_id)

    if not permission_policy.user_has_permission_for_instance(
        request.user, 'change', theredirect
    ):
        return permission_denied(request)

    if request.method == 'POST':
        form = RedirectForm(request.POST, request.FILES, instance=theredirect)
        if form.is_valid():
            form.save()
            messages.success(request, _("Redirect '{0}' updated.").format(theredirect.title), buttons=[
                messages.button(reverse('wagtailredirects:edit', args=(theredirect.id,)), _('Edit'))
            ])
            return redirect('wagtailredirects:index')
        else:
            messages.error(request, _("The redirect could not be saved due to errors."))
    else:
        form = RedirectForm(instance=theredirect)

    return render(request, "wagtailredirects/edit.html", {
        'redirect': theredirect,
        'form': form,
        'user_can_delete': permission_policy.user_has_permission(request.user, 'delete'),
    })
开发者ID:kapito,项目名称:wagtail,代码行数:26,代码来源:views.py

示例6: dispatch

    def dispatch(self, request, *args, **kwargs):
        if self.permission_required is not None:
            if not request.user.has_perm(self.permission_required):
                return permission_denied(request)

        if self.any_permission_required is not None:
            has_permission = False

            for perm in self.any_permission_required:
                if request.user.has_perm(perm):
                    has_permission = True
                    break

            if not has_permission:
                return permission_denied(request)

        return super(PermissionCheckedMixin, self).dispatch(request, *args, **kwargs)
开发者ID:Tivix,项目名称:wagtail,代码行数:17,代码来源:generic.py

示例7: edit

def edit(request, document_id):
    Document = get_document_model()
    DocumentForm = get_document_form(Document)

    doc = get_object_or_404(Document, id=document_id)

    if not permission_policy.user_has_permission_for_instance(request.user, 'change', doc):
        return permission_denied(request)

    if request.POST:
        original_file = doc.file
        form = DocumentForm(request.POST, request.FILES, instance=doc, user=request.user)
        if form.is_valid():
            if 'file' in form.changed_data:
                # if providing a new document file, delete the old one.
                # NB Doing this via original_file.delete() clears the file field,
                # which definitely isn't what we want...
                original_file.storage.delete(original_file.name)
            doc = form.save()

            # Reindex the document to make sure all tags are indexed
            for backend in get_search_backends():
                backend.add(doc)

            messages.success(request, _("Document '{0}' updated").format(doc.title), buttons=[
                messages.button(reverse('wagtaildocs:edit', args=(doc.id,)), _('Edit'))
            ])
            return redirect('wagtaildocs:index')
        else:
            messages.error(request, _("The document could not be saved due to errors."))
    else:
        form = DocumentForm(instance=doc, user=request.user)

    filesize = None

    # Get file size when there is a file associated with the Document object
    if doc.file:
        try:
            filesize = doc.file.size
        except OSError:
            # File doesn't exist
            pass

    if not filesize:
        messages.error(
            request,
            _("The file could not be found. Please change the source or delete the document"),
            buttons=[messages.button(reverse('wagtaildocs:delete', args=(doc.id,)), _('Delete'))]
        )

    return render(request, "wagtaildocs/documents/edit.html", {
        'document': doc,
        'filesize': filesize,
        'form': form,
        'user_can_delete': permission_policy.user_has_permission_for_instance(
            request.user, 'delete', doc
        ),
    })
开发者ID:Jimmy570,项目名称:wagtail,代码行数:58,代码来源:documents.py

示例8: url_generator

def url_generator(request, image_id):
    image = get_object_or_404(get_image_model(), id=image_id)

    if not permission_policy.user_has_permission_for_instance(request.user, "change", image):
        return permission_denied(request)

    form = URLGeneratorForm(initial={"filter_method": "original", "width": image.width, "height": image.height})

    return render(request, "wagtailimages/images/url_generator.html", {"image": image, "form": form})
开发者ID:tomdyson,项目名称:wagtail,代码行数:9,代码来源:images.py

示例9: list

def list(request, content_type_app_name, content_type_model_name):
    content_type = get_content_type_from_url_params(content_type_app_name, content_type_model_name)
    model = content_type.model_class()

    permissions = [
        get_permission_name(action, model)
        for action in ['add', 'change', 'delete']
    ]
    if not any([request.user.has_perm(perm) for perm in permissions]):
        return permission_denied(request)

    snippet_type_name, snippet_type_name_plural = get_snippet_type_name(content_type)

    items = model.objects.all()

    # Search
    is_searchable = class_is_indexed(model)
    is_searching = False
    search_query = None
    if is_searchable and 'q' in request.GET:
        search_form = SearchForm(request.GET, placeholder=_("Search %(snippet_type_name)s") % {
            'snippet_type_name': snippet_type_name_plural
        })

        if search_form.is_valid():
            search_query = search_form.cleaned_data['q']

            search_backend = get_search_backend()
            items = search_backend.search(search_query, items)
            is_searching = True

    else:
        search_form = SearchForm(placeholder=_("Search %(snippet_type_name)s") % {
            'snippet_type_name': snippet_type_name_plural
        })

    paginator, paginated_items = paginate(request, items)

    # Template
    if request.is_ajax():
        template = 'wagtailsnippets/snippets/results.html'
    else:
        template = 'wagtailsnippets/snippets/type_index.html'

    return render(request, template, {
        'content_type': content_type,
        'snippet_type_name': snippet_type_name,
        'snippet_type_name_plural': snippet_type_name_plural,
        'items': paginated_items,
        'can_add_snippet': request.user.has_perm(get_permission_name('add', model)),
        'is_searchable': is_searchable,
        'search_form': search_form,
        'is_searching': is_searching,
        'query_string': search_query,
    })
开发者ID:Tivix,项目名称:wagtail,代码行数:55,代码来源:snippets.py

示例10: list

def list(request, app_label, model_name):
    model = get_snippet_model_from_url_params(app_label, model_name)

    permissions = [
        get_permission_name(action, model)
        for action in ['add', 'change', 'delete']
    ]
    if not any([request.user.has_perm(perm) for perm in permissions]):
        return permission_denied(request)

    items = model.objects.all()

    # Preserve the snippet's model-level ordering if specified, but fall back on PK if not
    # (to ensure pagination is consistent)
    if not items.ordered:
        items = items.order_by('pk')

    # Search
    is_searchable = class_is_indexed(model)
    is_searching = False
    search_query = None
    if is_searchable and 'q' in request.GET:
        search_form = SearchForm(request.GET, placeholder=_("Search %(snippet_type_name)s") % {
            'snippet_type_name': model._meta.verbose_name_plural
        })

        if search_form.is_valid():
            search_query = search_form.cleaned_data['q']

            search_backend = get_search_backend()
            items = search_backend.search(search_query, items)
            is_searching = True

    else:
        search_form = SearchForm(placeholder=_("Search %(snippet_type_name)s") % {
            'snippet_type_name': model._meta.verbose_name_plural
        })

    paginator, paginated_items = paginate(request, items)

    # Template
    if request.is_ajax():
        template = 'wagtailsnippets/snippets/results.html'
    else:
        template = 'wagtailsnippets/snippets/type_index.html'

    return render(request, template, {
        'model_opts': model._meta,
        'items': paginated_items,
        'can_add_snippet': request.user.has_perm(get_permission_name('add', model)),
        'is_searchable': is_searchable,
        'search_form': search_form,
        'is_searching': is_searching,
        'query_string': search_query,
    })
开发者ID:kapito,项目名称:wagtail,代码行数:55,代码来源:snippets.py

示例11: delete

def delete(request, image_id):
    image = get_object_or_404(get_image_model(), id=image_id)

    if not permission_policy.user_has_permission_for_instance(request.user, "delete", image):
        return permission_denied(request)

    if request.POST:
        image.delete()
        messages.success(request, _("Image '{0}' deleted.").format(image.title))
        return redirect("wagtailimages:index")

    return render(request, "wagtailimages/images/confirm_delete.html", {"image": image})
开发者ID:tomdyson,项目名称:wagtail,代码行数:12,代码来源:images.py

示例12: delete

def delete(request, redirect_id):
    theredirect = get_object_or_404(models.Redirect, id=redirect_id)

    if not permission_policy.user_has_permission_for_instance(request.user, "delete", theredirect):
        return permission_denied(request)

    if request.POST:
        theredirect.delete()
        messages.success(request, _("Redirect '{0}' deleted.").format(theredirect.title))
        return redirect("wagtailredirects:index")

    return render(request, "wagtailredirects/confirm_delete.html", {"redirect": theredirect})
开发者ID:thrawny,项目名称:wagtail,代码行数:12,代码来源:views.py

示例13: list

def list(request, app_label, model_name):
    model = get_snippet_model_from_url_params(app_label, model_name)

    permissions = [get_permission_name(action, model) for action in ["add", "change", "delete"]]
    if not any([request.user.has_perm(perm) for perm in permissions]):
        return permission_denied(request)

    items = model.objects.all()

    # Search
    is_searchable = class_is_indexed(model)
    is_searching = False
    search_query = None
    if is_searchable and "q" in request.GET:
        search_form = SearchForm(
            request.GET,
            placeholder=_("Search %(snippet_type_name)s") % {"snippet_type_name": model._meta.verbose_name_plural},
        )

        if search_form.is_valid():
            search_query = search_form.cleaned_data["q"]

            search_backend = get_search_backend()
            items = search_backend.search(search_query, items)
            is_searching = True

    else:
        search_form = SearchForm(
            placeholder=_("Search %(snippet_type_name)s") % {"snippet_type_name": model._meta.verbose_name_plural}
        )

    paginator, paginated_items = paginate(request, items)

    # Template
    if request.is_ajax():
        template = "wagtailsnippets/snippets/results.html"
    else:
        template = "wagtailsnippets/snippets/type_index.html"

    return render(
        request,
        template,
        {
            "model_opts": model._meta,
            "items": paginated_items,
            "can_add_snippet": request.user.has_perm(get_permission_name("add", model)),
            "is_searchable": is_searchable,
            "search_form": search_form,
            "is_searching": is_searching,
            "query_string": search_query,
        },
    )
开发者ID:qjardon,项目名称:wagtail,代码行数:52,代码来源:snippets.py

示例14: edit

def edit(request, content_type_app_name, content_type_model_name, id):
    content_type = get_content_type_from_url_params(content_type_app_name, content_type_model_name)
    model = content_type.model_class()

    permission = get_permission_name("change", model)
    if not request.user.has_perm(permission):
        return permission_denied(request)

    snippet_type_name = get_snippet_type_name(content_type)[0]

    instance = get_object_or_404(model, id=id)
    edit_handler_class = get_snippet_edit_handler(model)
    form_class = edit_handler_class.get_form_class(model)

    if request.POST:
        form = form_class(request.POST, request.FILES, instance=instance)

        if form.is_valid():
            form.save()

            messages.success(
                request,
                _("{snippet_type} '{instance}' updated.").format(
                    snippet_type=capfirst(snippet_type_name), instance=instance
                ),
                buttons=[
                    messages.button(
                        reverse(
                            "wagtailsnippets:edit", args=(content_type_app_name, content_type_model_name, instance.id)
                        ),
                        _("Edit"),
                    )
                ],
            )
            return redirect("wagtailsnippets:list", content_type.app_label, content_type.model)
        else:
            messages.error(request, _("The snippet could not be saved due to errors."))
            edit_handler = edit_handler_class(instance=instance, form=form)
    else:
        form = form_class(instance=instance)
        edit_handler = edit_handler_class(instance=instance, form=form)

    return render(
        request,
        "wagtailsnippets/snippets/edit.html",
        {
            "content_type": content_type,
            "snippet_type_name": snippet_type_name,
            "instance": instance,
            "edit_handler": edit_handler,
        },
    )
开发者ID:niceguydave,项目名称:wagtail,代码行数:52,代码来源:snippets.py

示例15: delete

def delete(request, document_id):
    Document = get_document_model()
    doc = get_object_or_404(Document, id=document_id)

    if not permission_policy.user_has_permission_for_instance(request.user, "delete", doc):
        return permission_denied(request)

    if request.method == "POST":
        doc.delete()
        messages.success(request, _("Document '{0}' deleted.").format(doc.title))
        return redirect("wagtaildocs:index")

    return render(request, "wagtaildocs/documents/confirm_delete.html", {"document": doc})
开发者ID:m1kola,项目名称:wagtail,代码行数:13,代码来源:documents.py


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