當前位置: 首頁>>代碼示例>>Python>>正文


Python decorators.api_view方法代碼示例

本文整理匯總了Python中rest_framework.decorators.api_view方法的典型用法代碼示例。如果您正苦於以下問題:Python decorators.api_view方法的具體用法?Python decorators.api_view怎麽用?Python decorators.api_view使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rest_framework.decorators的用法示例。


在下文中一共展示了decorators.api_view方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: typed_api_view

# 需要導入模塊: from rest_framework import decorators [as 別名]
# 或者: from rest_framework.decorators import api_view [as 別名]
def typed_api_view(methods):
    def wrap_validate_and_render(view):
        prevalidate(view)

        @api_view(methods)
        @wraps_drf(view)
        def wrapper(*original_args, **original_kwargs):
            original_args = list(original_args)
            request = find_request(original_args)
            transformed = transform_view_params(
                inspect.signature(view).parameters.values(), request, original_kwargs
            )
            return view(*transformed)

        return wrapper

    return wrap_validate_and_render 
開發者ID:rsinger86,項目名稱:drf-typed-views,代碼行數:19,代碼來源:decorators.py

示例2: input_post_view

# 需要導入模塊: from rest_framework import decorators [as 別名]
# 或者: from rest_framework.decorators import api_view [as 別名]
def input_post_view():
    return (api_view(['POST']))(dummy_view_func) 
開發者ID:apragacz,項目名稱:django-rest-registration,代碼行數:4,代碼來源:test_api_view_serializer_class_getter.py

示例3: input_put_view

# 需要導入模塊: from rest_framework import decorators [as 別名]
# 或者: from rest_framework.decorators import api_view [as 別名]
def input_put_view():
    return (api_view(['PUT']))(dummy_view_func) 
開發者ID:apragacz,項目名稱:django-rest-registration,代碼行數:4,代碼來源:test_api_view_serializer_class_getter.py

示例4: test_get_invoked_action_from_function_based_view

# 需要導入模塊: from rest_framework import decorators [as 別名]
# 或者: from rest_framework.decorators import api_view [as 別名]
def test_get_invoked_action_from_function_based_view(self):
        @api_view(["GET"])
        def my_view(request):
            return ""

        policy = AccessPolicy()
        view_instance = my_view.cls()

        result = policy._get_invoked_action(view_instance)
        self.assertEqual(result, "my_view") 
開發者ID:rsinger86,項目名稱:drf-access-policy,代碼行數:12,代碼來源:test_access_policy.py

示例5: deploy_general_remaining_sites

# 需要導入模塊: from rest_framework import decorators [as 別名]
# 或者: from rest_framework.decorators import api_view [as 別名]
def deploy_general_remaining_sites(request, is_project, pk):
    fxf_id = request.data.get('id')
    fxf_status = request.data.get('is_deployed')
    try:
        if is_project == "1":
            with transaction.atomic():
                fxf = FieldSightXF.objects.get(pk=fxf_id)
                if fxf_status:
                    site_ids=[]
                    for site in fxf.project.sites.filter(is_active=True):
                        child, created = FieldSightXF.objects.get_or_create(is_staged=False, is_scheduled=False, xf=fxf.xf, site=site, fsform_id=fxf_id)
                        child.is_deployed = True
                        child.save()
                        if created:
                            site_ids.append(site.id)
                    send_bulk_message_stages(site_ids)
                else:
                    return Response({'error':"Deploy Form First and deploy to remaining.."}, status=status.HTTP_400_BAD_REQUEST)
            return Response({'msg': 'ok'}, status=status.HTTP_200_OK)
        else:
            return Response({'error':"Site level Deploy to remaining Not permitted."}, status=status.HTTP_400_BAD_REQUEST)
    except Exception as e:
        return Response({'error':e.message}, status=status.HTTP_400_BAD_REQUEST)



# @group_required("Project")
# @api_view([])
# def deploy_general(request, fxf_id):
#     with transaction.atomic():
#         fxf = FieldSightXF.objects.get(pk=fxf_id)
#         FieldSightXF.objects.filter(fsform=fxf, is_scheduled=False, is_staged=False).delete()
#         for site in fxf.project.sites.filter(is_active=True):
#             # cloning from parent
#             child = FieldSightXF(is_staged=False, is_scheduled=False, xf=fxf.xf, site=site, fsform_id=fxf_id,
#                                  is_deployed=True)
#             child.save()
#     messages.info(request, 'General Form {} Deployed to Sites'.format(fxf.xf.title))
#     return HttpResponseRedirect(reverse("forms:project-general", kwargs={'project_id': fxf.project.pk})) 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:41,代碼來源:views.py

示例6: search_indrz

# 需要導入模塊: from rest_framework import decorators [as 別名]
# 或者: from rest_framework.decorators import api_view [as 別名]
def search_indrz(request, campus_id, search_string, format=None):
    # query_string = ''
    # found_entries = None

    # if using a url like http://www.campus.com/search/?q=sometext
    # use this if statement and indent code block

    # if ('q' in request.GET) and request.GET['q'].strip():
    #     query_string = request.GET['q']

    entry_query = get_query(search_string, ['short_name', 'long_name', 'room_code', 'room_description'])

    # return only first 20 results
    found_entries = BuildingFloorSpace.objects.filter(fk_building__fk_campus=campus_id).filter(entry_query)[:20]

    # buildings_on_campus = BuildingFloorSpace.objects.filter(Q(short_name__icontains=search_string) | Q(room_code__icontains=search_string))
    serializer = BuildingFloorSpaceSerializer(found_entries, many=True)

    if found_entries:

        return Response(serializer.data)

    # elif:
    #     pass
        # return Response({'error': 'sorry nothing found with the text:  ' + search_string})

    else:
        return Response({'error': 'sorry nothing found with the text:  ' + search_string})

# old silly search
# @api_view(['GET'])
# def campus_search(request, campus_id, search_string, format=None):
#     """
#     Search campus spaces in system and pois
#     """
#     if request.method == 'GET':
#
#         buildings_on_campus = BuildingFloorSpace.objects.filter(Q(short_name__icontains=search_string) | Q(room_code__icontains=search_string))
#         serializer = BuildingFloorSpaceSerializer(buildings_on_campus, many=True)
#
#         return Response(serializer.data) 
開發者ID:indrz,項目名稱:indrz,代碼行數:43,代碼來源:search.py


注:本文中的rest_framework.decorators.api_view方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。