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


Python views.Response方法代碼示例

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


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

示例1: get_paginated_response

# 需要導入模塊: from rest_framework import views [as 別名]
# 或者: from rest_framework.views import Response [as 別名]
def get_paginated_response(self, data):
        next = None
        previous = None

        if self.page.has_next():
            next = self.page.next_page_number()
        if self.page.has_previous():
            previous = self.page.previous_page_number()

        return Response({
            'results': data,
            'meta': {
                'pagination': OrderedDict([
                    ('page', self.page.number),
                    ('pages', self.page.paginator.num_pages),
                    ('count', self.page.paginator.count),
                ])
            },
            'links': OrderedDict([
                ('first', self.build_link(1)),
                ('last', self.build_link(self.page.paginator.num_pages)),
                ('next', self.build_link(next)),
                ('prev', self.build_link(previous))
            ])
        }) 
開發者ID:django-json-api,項目名稱:django-rest-framework-json-api,代碼行數:27,代碼來源:pagination.py

示例2: get

# 需要導入模塊: from rest_framework import views [as 別名]
# 或者: from rest_framework.views import Response [as 別名]
def get(self, request, *args, **kwargs):
        connect = redis.StrictRedis(
            host=settings.REDIS_HOST,
            port=settings.REDIS_PORT,
            db=settings.REDIS_SPACE,
            password=settings.REDIS_PASSWD
        )
        week_list = ['Won', 'Tue', 'Wed', 'Thur', 'Fri', 'Sat', 'Sun']
        TEMP = connect.hgetall('WORK',)
        WORK = []
        for key in week_list:
            WORK.append({
                'time': str(key, encoding='utf-8'),
                '執行次數': TEMP[key]
            })
        return Response(
            {'title': '一周內工單執行','dataset': WORK} or {}, status.HTTP_200_OK
        ) 
開發者ID:YoLoveLife,項目名稱:DevOps,代碼行數:20,代碼來源:dashboard.py

示例3: delete

# 需要導入模塊: from rest_framework import views [as 別名]
# 或者: from rest_framework.views import Response [as 別名]
def delete(self, request, *args, **kwargs):
        if self.qrcode_check(request):
            group = self.get_object()
            if group.hosts.count() != 0:
                return self.msg.format(
                    USER=request.user.full_name,
                    NAME=group.name,
                    UUID=group.uuid
                ), Response({
                    'detail': settings.LANGUAGE.ManagerGroupDeleteAPIExsistHost
                }, status=status.HTTP_406_NOT_ACCEPTABLE)
            else:
                return self.msg.format(
                    USER=request.user.full_name,
                    NAME=group.name,
                    UUID=group.uuid
                ), super(ManagerGroupDeleteAPI, self).delete(request, *args, **kwargs)
        else:
            return '', self.qrcode_response 
開發者ID:YoLoveLife,項目名稱:DevOps,代碼行數:21,代碼來源:group.py

示例4: get

# 需要導入模塊: from rest_framework import views [as 別名]
# 或者: from rest_framework.views import Response [as 別名]
def get(self, request, *args, **kwargs):
        user = request.user
        if user.have_qrcode is False:
            response_dist = {
                'url': get_qrcode(request.user)
            }
            user.have_qrcode = True
            user.save()
            response = Response(response_dist, status=status.HTTP_201_CREATED)
            return self.msg.format(
                USER=request.user.full_name,
            ), response
        else:
            return '', Response({
                'detail': settings.LANGUAGE.UserQRCodeAPIHaveQRCode
            }, status=status.HTTP_406_NOT_ACCEPTABLE) 
開發者ID:YoLoveLife,項目名稱:DevOps,代碼行數:18,代碼來源:user.py

示例5: delete

# 需要導入模塊: from rest_framework import views [as 別名]
# 或者: from rest_framework.views import Response [as 別名]
def delete(self, request, *args, **kwargs):
        if self.qrcode_check(request):
            key = self.get_object()
            try:
                group = key.group
                return '', Response({
                    'detail': settings.LANGUAGE.KeyDeleteAPICanNotDelete.format(
                        GROUP=group.name
                    )}, status=status.HTTP_406_NOT_ACCEPTABLE)
            except ObjectDoesNotExist:
                response = super(KeyDeleteAPI, self).delete(request, *args, **kwargs)
                return self.msg.format(
                    USER=request.user.full_name,
                    NAME=key.name,
                    UUID=key.uuid
                ), response
        else:
            return '', self.qrcode_response 
開發者ID:YoLoveLife,項目名稱:DevOps,代碼行數:20,代碼來源:key.py

示例6: update

# 需要導入模塊: from rest_framework import views [as 別名]
# 或者: from rest_framework.views import Response [as 別名]
def update(self, request, *args, **kwargs):
        work = self.get_object()
        user = request.user
        if self.qrcode_check(request):
            pass
        else:
            return '', self.qrcode_response

        codework = models.Code_Work.objects.filter(uuid=kwargs['pk']).get()

        if codework.mission.group.users.filter(id=user.id).exists():
            response = super(CodeWorkCheckAPI,self).update(request, *args, **kwargs)
            return self.msg.format(
                USER=request.user.full_name,
                MISSION=work.mission.info,
                REASON=work.info,
                UUID=work.uuid,
            ), response
        else:
            return '', Response({'detail': u'您沒有審核的權限'}, status=status.HTTP_406_NOT_ACCEPTABLE) 
開發者ID:YoLoveLife,項目名稱:DevOps,代碼行數:22,代碼來源:code.py

示例7: acl_save_draft

# 需要導入模塊: from rest_framework import views [as 別名]
# 或者: from rest_framework.views import Response [as 別名]
def acl_save_draft(request, id_vlan, type_acl):

    type_to_check = type_acl.strip().lower()
    content_draft = request.DATA.get('content_draft', '')

    if not is_valid_int_greater_zero_param(id_vlan):
        raise exceptions.InvalidIdVlanException()

    vlan_obj = Vlan.objects.get(pk=id_vlan)

    if type_to_check == TYPE_ACL_V4:
        vlan_obj.acl_draft = content_draft
    else:
        vlan_obj.acl_draft_v6 = content_draft

    vlan_obj.save(request.user)

    return Response() 
開發者ID:globocom,項目名稱:GloboNetworkAPI,代碼行數:20,代碼來源:v1.py

示例8: acl_remove_draft

# 需要導入模塊: from rest_framework import views [as 別名]
# 或者: from rest_framework.views import Response [as 別名]
def acl_remove_draft(request, id_vlan, type_acl):

    type_to_check = type_acl.strip().lower()

    if not is_valid_int_greater_zero_param(id_vlan):
        raise exceptions.InvalidIdVlanException()

    vlan_obj = Vlan.objects.get(pk=id_vlan)

    if type_to_check == TYPE_ACL_V4:
        vlan_obj.acl_draft = None
    else:
        vlan_obj.acl_draft_v6 = None

    vlan_obj.save(request.user)

    return Response() 
開發者ID:globocom,項目名稱:GloboNetworkAPI,代碼行數:19,代碼來源:v1.py

示例9: create

# 需要導入模塊: from rest_framework import views [as 別名]
# 或者: from rest_framework.views import Response [as 別名]
def create(self, request, *args, **kwargs):
        try:
            return super().create(request, *args, **kwargs)
        except FileExistsError:
            return Response(
                {"xpi": "An extension with this filename already exists."},
                status=status.HTTP_400_BAD_REQUEST,
            ) 
開發者ID:mozilla,項目名稱:normandy,代碼行數:10,代碼來源:views.py

示例10: update

# 需要導入模塊: from rest_framework import views [as 別名]
# 或者: from rest_framework.views import Response [as 別名]
def update(self, request, *args, **kwargs):
        try:
            return super().update(request, *args, **kwargs)
        except FileExistsError:
            return Response(
                {"xpi": "An extension with this filename already exists."},
                status=status.HTTP_400_BAD_REQUEST,
            ) 
開發者ID:mozilla,項目名稱:normandy,代碼行數:10,代碼來源:views.py

示例11: destroy

# 需要導入模塊: from rest_framework import views [as 別名]
# 或者: from rest_framework.views import Response [as 別名]
def destroy(self, request, *args, **kwargs):
        instance = self.get_object()

        revisions = RecipeRevision.objects.filter(action__name="opt-out-study").exclude(
            latest_for_recipe=None, approved_for_recipe=None
        )

        for r in revisions:
            if r.arguments.get("extensionId") == instance.id:
                return Response(
                    ["Extension cannot be updated while in use by a recipe."],
                    status=status.HTTP_400_BAD_REQUEST,
                )

        return super().destroy(request, *args, **kwargs) 
開發者ID:mozilla,項目名稱:normandy,代碼行數:17,代碼來源:views.py

示例12: delete

# 需要導入模塊: from rest_framework import views [as 別名]
# 或者: from rest_framework.views import Response [as 別名]
def delete(self, request, *args, **kwargs):
        obj = self.get_object()
        if not obj.pushmission.exists():
            response = super(UtilsFileDeleteAPI, self).delete(request, *args, **kwargs)
            return self.msg.format(
                USER=request.user.full_name,
                UUID=obj.uuid,
                FILENAME=obj.name,
            ), response
        else:
            return '', Response({'detail': '該文件已經屬於某個任務無法被刪除'}, status=status.HTTP_406_NOT_ACCEPTABLE) 
開發者ID:YoLoveLife,項目名稱:DevOps,代碼行數:13,代碼來源:file.py

示例13: create

# 需要導入模塊: from rest_framework import views [as 別名]
# 或者: from rest_framework.views import Response [as 別名]
def create(self, request, *args, **kwargs):
        data = request.data
        if models.Instance.objects.filter(port=data['detail']['port'],host_id=data['host']).exists():
            return Response({'detail': '該主機上已經存在該實例信息'}, status=status.HTTP_406_NOT_ACCEPTABLE)
        else:
            return super(ZDBInstanceCreateAPI,self).create(request, *args, **kwargs) 
開發者ID:YoLoveLife,項目名稱:DevOps,代碼行數:8,代碼來源:instance.py

示例14: get

# 需要導入模塊: from rest_framework import views [as 別名]
# 或者: from rest_framework.views import Response [as 別名]
def get(self, request, *args, **kwargs):
        obj = self.get_object()
        obj.check_status()
        return Response({
            'detail': settings.LANGUAGE.JumperStatusAPI
        }, status=status.HTTP_200_OK) 
開發者ID:YoLoveLife,項目名稱:DevOps,代碼行數:8,代碼來源:jumper.py

示例15: get

# 需要導入模塊: from rest_framework import views [as 別名]
# 或者: from rest_framework.views import Response [as 別名]
def get(self, request, *args, **kwargs):
        obj = self.get_object()
        if obj.status > 0:
            return Response({'detail': u'該工單處於正常狀態'}, status=status.HTTP_406_NOT_ACCEPTABLE)
        else:
            return Response({'results': obj.push_mission.results}, status=status.HTTP_202_ACCEPTED) 
開發者ID:YoLoveLife,項目名稱:DevOps,代碼行數:8,代碼來源:code.py


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