Python django.contrib.auth.decorators 模块,permission_required() 实例源码

我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用django.contrib.auth.decorators.permission_required()

项目:sensu_drive    作者:ilavender    | 项目源码 | 文件源码
def rules(request):

    mimetype = 'application/json'
    data = {}

    return HttpResponse(json.dumps(data), mimetype)


#@permission_required('is_staff', login_url=reverse_lazy('login'))
#@login_required(login_url=reverse_lazy('login'))
项目:tecken    作者:mozilla-services    | 项目源码 | 文件源码
def api_permission_required(perm):
    """Slight override on django.contrib.auth.decorators.permission_required
    that forces the `raise_exception` to be set to True.
    """
    return permission_required(perm, raise_exception=True)
项目:django-audit-tools    作者:PeRDy    | 项目源码 | 文件源码
def access_required(view):
    return permission_required('audit.api')(permission_required('audit.search')(view))
项目:db_platform    作者:speedocjx    | 项目源码 | 文件源码
def batch_add(request):

    return render(request, 'batch_add.html', locals())


# @login_required(login_url='/accounts/login/')
# @permission_required('myapp.can_see_mysqladmin', login_url='/')
# def test_tb(request):
#     dbtag = request.GET['dbtag']
#     if dbtag!='all':
#         mydata = {'dupresult':get_dupreport(dbtag,request.GET['email'])}
#     # return render(request, 'batch_add.html', locals())
#     return JsonResponse(mydata)
项目:website    作者:hackerspace-ntnu    | 项目源码 | 文件源码
def change_multiple_items(request):
    """ For å endre flere itmes, tilgjengelig hvis man merker gjenstander i search og trykker 'endre'. """
    # TODO søk på "arduino": hverken arduino eller OculusRift lar seg avmerke i boksen, det fungerer på resten
    # TODO endre her så man også kan lage nye tags
    # TODO endre så man kan endre zone og/eller shelf
    # TODO lag en form og gjør viewet lesbart.
    if request.method == "POST":
        try:
            """ Items marked in search-view for changing """
            # items_for_changing: String of all item_id's to be changed, separated with '_' (also one at the end)
            items_for_changing = request.POST['items']
        except KeyError:
            form = ItemForm(request.POST)
            # TODO is_valid() returnerer ikke true
            form.is_valid()
            items = form.cleaned_data['tags_chips']
            try:
                new_tags = form.cleaned_data['name']
            except KeyError:
                """ Deletes all marked items """
                ItemForm.delete_all_items(items)
                messages.add_message(request, messages.SUCCESS, "Gjenstander ble slettet.")
                return HttpResponseRedirect(reverse('inventory:index'))
            else:
                """ Changes tag on all marked items """
                ItemForm.change_tags(items, new_tags)
                messages.add_message(request, messages.SUCCESS, "Tagger ble oppdatert.")
                return HttpResponseRedirect(reverse('inventory:index'))
        else:
            items = [get_object_or_404(Item, pk=item_id) for item_id in items_for_changing.split('_')[:-1]]
            context = {
                'autocomplete_dict': ItemForm.get_autocomplete_dict(),
                'form': ItemForm(initial={'tags_chips': items_for_changing, 'name': 'skip'}),
                'items': items,
            }
            return render(request, 'inventory/change_multiple_items.html', context)
    else:
        return render(request, 'inventory/search.html', show_all_items())


# TODO permission_required redirecter ikke til dit man kom fra når man må logge inn
# TODO gjør så man kan sette sone og hylle for alle items med denne tagen.
项目:django-learning    作者:adoggie    | 项目源码 | 文件源码
def my_view(request):


#PermissionRequiredMixin

    from django.contrib.auth.mixins import PermissionRequiredMixin

    class MyView(PermissionRequiredMixin, View):
        permission_required = 'polls.can_vote'
        # Or multiple of permissions:
        permission_required = ('polls.can_open', 'polls.can_edit')

#AccessMixin