当前位置: 首页>>代码示例>>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;未经允许,请勿转载。