微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

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, "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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐