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


Python rest_framework.status方法代碼示例

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


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

示例1: get

# 需要導入模塊: import rest_framework [as 別名]
# 或者: from rest_framework import status [as 別名]
def get(self, request):
        if request.user.is_authenticated:
            # 獲取所有數據
            roles = Product.objects.all()
            # 創建分頁對象
            pg = PageNumberPagination()
            # pg = MyLimitOffsetPagination()
            # 獲取分頁的數據
            page_roles = pg.paginate_queryset(queryset=roles, request=request, view=self)
            # 對數據進行序列化
            ser = ProductSerializer(instance=page_roles, many=True)
            # print('ser.data的類型:' + str(ser.data))
            msg = sort_out_list(request, ser.data)
            return Response(msg, status=HTTP_200_OK)
        else:
            msg = {
                'stateCode': 201,
                'msg': '沒有訪問權限'
            }
            return Response(msg, 201)


# 獲取搜索列表,暫時不分頁 
開發者ID:michwh,項目名稱:onehome-server,代碼行數:25,代碼來源:views.py

示例2: post

# 需要導入模塊: import rest_framework [as 別名]
# 或者: from rest_framework import status [as 別名]
def post(self, request):
        '''
        Add new tags (array of tag names) to user's profile
        '''
        if not request.data["tags"]:
            return Response({"error": "tags were not included"}, status=400)
        user = EngageUserProfile.objects.get(user=request.user)
        for tag in request.data["tags"]:
            try:
                tag_to_add = Tag.objects.filter(name__contains=tag).first()
                if tag_to_add is not None:
                    user.tags.add(tag_to_add)
            except:
                username = request.user.username
                print(
                    "Could not add tag ({}) to user ({}) since it doesn't exist in the ingest_tag table.".format(tag, username))
        try:
            user.save()
        except:
            return Response(status=500)
        return Response(status=200) 
開發者ID:hackla-engage,項目名稱:engage-backend,代碼行數:23,代碼來源:Tags.py

示例3: limited

# 需要導入模塊: import rest_framework [as 別名]
# 或者: from rest_framework import status [as 別名]
def limited(user=None):
    illegality = Illegality.objects.filter(user=user,duration_status=True).order_by("-illegality_endtime")

    if len(illegality) != 0 and illegality[0].duration_status:
        illegality = illegality[0]
        start_time = illegality.illegality_starttime
        end_time = illegality.illegality_endtime
        now = datetime.datetime.now()
        if now >= start_time and now <= end_time:
            raise serializers.ValidationError({"405": {"notice": "攻擊比賽平台", "type": illegality.illegality_action,
                                                       "start_time": illegality.illegality_starttime,
                                                       "endtime": illegality.illegality_endtime,
                                                       'status': illegality.duration_status}})
        elif now > end_time:
            illegality.duration_status = False
            illegality.save()
        else:
            pass
    else:
        pass 
開發者ID:xuchaoa,項目名稱:CTF_AWD_Platform,代碼行數:22,代碼來源:IllegalityLimited.py

示例4: dependencies

# 需要導入模塊: import rest_framework [as 別名]
# 或者: from rest_framework import status [as 別名]
def dependencies(self, request, uuid=None):
        from api.serializers import URLRunSerializer, URLTemplateSerializer
        context = {'request': request}
        try:
            dependencies = models.DataObject.get_dependencies(uuid)
            serialized_dependencies = {
                'runs': [URLRunSerializer(
                        run, context=context).data 
                         for run in dependencies.get('runs', [])],
                'templates': [URLTemplateSerializer(
                        template, context=context).data
                              for template in dependencies.get(
                        'templates', [])],
                'truncated': dependencies.get('truncated')
                }
        except ObjectDoesNotExist:
            raise rest_framework.exceptions.NotFound()
        return JsonResponse(serialized_dependencies, status=200) 
開發者ID:StanfordBioinformatics,項目名稱:loom,代碼行數:20,代碼來源:views.py

示例5: get_task_monitor_settings

# 需要導入模塊: import rest_framework [as 別名]
# 或者: from rest_framework import status [as 別名]
def get_task_monitor_settings(self, request, uuid=None):
        task_attempt = self._get_task_attempt(request, uuid)
        return JsonResponse({
            'SERVER_NAME': get_setting('SERVER_NAME'),
            'DEBUG': get_setting('DEBUG'),
            'WORKING_DIR_ROOT': os.path.join(
                get_setting('INTERNAL_STORAGE_ROOT'), 'tmp', task_attempt.uuid),
            'DEFAULT_DOCKER_REGISTRY': get_setting('DEFAULT_DOCKER_REGISTRY'),
            'PRESERVE_ALL': get_setting('PRESERVE_ON_FAILURE'),
            'PRESERVE_ON_FAILURE': get_setting('PRESERVE_ON_FAILURE'),
            'HEARTBEAT_INTERVAL_SECONDS':
            get_setting('TASKRUNNER_HEARTBEAT_INTERVAL_SECONDS'),
            # container name is duplicated in TaskAttempt cleanup playbook
            'PROCESS_CONTAINER_NAME': '%s-attempt-%s' % (
                get_setting('SERVER_NAME'), uuid),
        }, status=200) 
開發者ID:StanfordBioinformatics,項目名稱:loom,代碼行數:18,代碼來源:views.py

示例6: post

# 需要導入模塊: import rest_framework [as 別名]
# 或者: from rest_framework import status [as 別名]
def post(self, request):
        data = request.data
        # username = data.get('username')
        serializer = ProductSerializer(data=data)

        if request.user.is_authenticated:
            # print(data)
            if serializer.is_valid(raise_exception=True):
                serializer.save()
                return Response({"stateCode": 200, "msg": "發布成功"}, 200)
            return Response(serializer.errors, status=HTTP_400_BAD_REQUEST)
        else:
            return Response({"stateCode": 201, "msg": "沒有上傳權限"}, 201) 
開發者ID:michwh,項目名稱:onehome-server,代碼行數:15,代碼來源:views.py

示例7: staffdesignations

# 需要導入模塊: import rest_framework [as 別名]
# 或者: from rest_framework import status [as 別名]
def staffdesignations(request):
    return HttpResponse(json.dumps(STAFF_TYPES), status=200) 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:4,代碼來源:staffViewset.py

示例8: staffgender

# 需要導入模塊: import rest_framework [as 別名]
# 或者: from rest_framework import status [as 別名]
def staffgender(request):
    return HttpResponse(json.dumps(GENDER_TYPES), status=200) 
開發者ID:awemulya,項目名稱:kobo-predict,代碼行數:4,代碼來源:staffViewset.py

示例9: get_agenda

# 需要導入模塊: import rest_framework [as 別名]
# 或者: from rest_framework import status [as 別名]
def get_agenda(request, meeting_id):
    '''
    Returns specified JSON serialized agenda if it exists
    '''
    agenda = Agenda.objects.get(meeting_id=meeting_id)
    if agenda is None:
        return Response(data={"error": "No agenda item with id:" + str(meeting_id)}, status=404)
    data = AgendaSerializer(agenda, many=False).data
    return Response(data=data, status=200) 
開發者ID:hackla-engage,項目名稱:engage-backend,代碼行數:11,代碼來源:Agenda.py

示例10: mailchimpUpdRequest

# 需要導入模塊: import rest_framework [as 別名]
# 或者: from rest_framework import status [as 別名]
def mailchimpUpdRequest(payload=None, user=None, key=None, member_id=None):
    """
    HTTP Method: PATCH
    MailChimp API request used to update the status of existing users.
    """
    user = user
    key = key
    url = f'https://{REGION}.api.mailchimp.com/3.0/lists/6ca892a88b/members/{member_id}'

    r = requests.patch(url, auth=(user, key), data=payload)

    return r 
開發者ID:hackla-engage,項目名稱:engage-backend,代碼行數:14,代碼來源:MailChimp.py

示例11: get

# 需要導入模塊: import rest_framework [as 別名]
# 或者: from rest_framework import status [as 別名]
def get(self, request):
        user = EngageUserProfile.objects.get(user=request.user)
        tags = user.tags.all()
        tags_list = []
        for tag in tags:
            tags_list.append(tag.name)
        return Response(data=tags_list, status=200) 
開發者ID:hackla-engage,項目名稱:engage-backend,代碼行數:9,代碼來源:Tags.py

示例12: wechat_notify_url

# 需要導入模塊: import rest_framework [as 別名]
# 或者: from rest_framework import status [as 別名]
def wechat_notify_url(request):
    '''
    微信支付回調接口
    '''
    try:
        print('請求方法:',request.method)
        return_xml = """<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>"""
        webData = request.body
        print('回調返回信息:',webData)
        if bool(webData):
            xmlData = ET.fromstring(webData)
            if xmlData.find('return_code').text != 'SUCCESS':
                print('回調出現錯誤')
                return HttpResponse(return_xml,content_type='application/xml;charset=utf-8')
            else:
                if xmlData.find('result_code').text != 'SUCCESS':
                    print('支付失敗!')
                    return HttpResponse(return_xml,content_type='application/xml;charset=utf-8')
                else:
                    print('訂單支付成功...準備修改訂單狀態')
                    order_num = xmlData.find('out_trade_no').text
                    order = Order.objects.filter(order_num=order_num).first()
                    # 更新狀態 更新支付時間 更新支付方式
                    order.status = 1
                    order.pay_time = datetime.datetime.now()
                    order.pay_type = 1
                    order.save()
                    # 整理庫存和銷量,當訂單到這裏時會將庫存鎖死
                    for detail in order.order_details.all():
                        detail.good_grade.sales += detail.buy_num
                        detail.good_grade.stock -= detail.buy_num
                        detail.good_grade.save()
                    return HttpResponse(return_xml,content_type='application/xml;charset=utf-8')
        return HttpResponse(return_xml,content_type='application/xml;charset=utf-8')
    except Exception as e:
        print(e)
        print({"message": "網絡錯誤:%s"%str(e), "errorCode": 1, "data": {}})
        return_xml = """<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>"""
        return HttpResponse(return_xml,content_type='application/xml;charset=utf-8') 
開發者ID:aeasringnar,項目名稱:django-RESTfulAPI,代碼行數:41,代碼來源:views.py

示例13: post

# 需要導入模塊: import rest_framework [as 別名]
# 或者: from rest_framework import status [as 別名]
def post(self, request):
        """
        處理支付寶的notify_url
        :param request:
        :return:
        """
        try:
            processed_dict = {}
            for key, value in request.data.items():
                processed_dict[key] = value
            if processed_dict:
                print('支付寶的參數', processed_dict)
                sign = processed_dict.pop("sign", None)
                alipay = AliPay(method='alipay.trade.app.pay')
                verify_re = alipay.verify(processed_dict, sign)
                print('支付寶的參數', processed_dict)
                print('檢驗參數結果', verify_re)
                out_trade_no = processed_dict.get('out_trade_no', None)
                trade_no = processed_dict.get('trade_no', None)
                # response = VerifyAndDo(out_trade_no, pay_way='alipay')
                order = Order.objects.filter(order_num=out_trade_no, status=0).first()
                if order:
                    order.status = 1
                    order.wechat_order_num = trade_no
                    order.pay_time = datetime.datetime.now()
                    order.pay_type = 2
                    order.save()
                    # 整理庫存和銷量,當訂單到這裏時會將庫存鎖死
                    for detail in order.order_details.all():
                        detail.good_grade.sales += detail.buy_num
                        detail.good_grade.stock -= detail.buy_num
                        detail.good_grade.save()
                else:
                    print('未找到訂單編號為:的訂單...' % order_num)
            return Response('success')
        except Exception as e:
            print('發生錯誤:',e)
            return Response({"message": "出現了無法預料的view視圖錯誤:%s" % e, "errorCode": 1, "data": {}}) 
開發者ID:aeasringnar,項目名稱:django-RESTfulAPI,代碼行數:40,代碼來源:views.py

示例14: test_get_crawl_by_status

# 需要導入模塊: import rest_framework [as 別名]
# 或者: from rest_framework import status [as 別名]
def test_get_crawl_by_status(self):
        response = self.client.get(self.url + "?status=%s" % self.test_nutch_crawl.status)
        assert self.parse_response(response)["status"] == "NOT STARTED" 
開發者ID:nasa-jpl-memex,項目名稱:memex-explorer,代碼行數:5,代碼來源:test_rest_crawl.py

示例15: destroy

# 需要導入模塊: import rest_framework [as 別名]
# 或者: from rest_framework import status [as 別名]
def destroy(self, *args, **kwargs):
        if get_setting('DISABLE_DELETE'):
            return JsonResponse({
                'message': 'Delete is forbidden because DISABLE_DELETE is True.'},
                                status=403)
        else:
            try:
                return super(ProtectedDeleteModelViewSet, self).destroy(
                    *args, **kwargs)
            except ProtectedError:
                return JsonResponse({
                        'message':
                        'Delete failed because resource is still in use.'},
                                    status=409) 
開發者ID:StanfordBioinformatics,項目名稱:loom,代碼行數:16,代碼來源:views.py


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