当前位置: 首页>>代码示例>>Python>>正文


Python Response.data方法代码示例

本文整理汇总了Python中rest_framework.response.Response.data方法的典型用法代码示例。如果您正苦于以下问题:Python Response.data方法的具体用法?Python Response.data怎么用?Python Response.data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rest_framework.response.Response的用法示例。


在下文中一共展示了Response.data方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: password_reset

# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import data [as 别名]
def password_reset(request):
    response = Response()
    data = {}
    if request.method == 'POST':
        form = PRForm(request.POST)
        if form.is_valid():
            fields = settings.SUPERUSER_PRFIELDS
            args = {}
            for field in fields:
                args[field] = form.cleaned_data[field]

            args['verified'] = True
            try:
                user = UserTemp.objects.get(**args)
                
                email = form.cleaned_data[settings.SUPERUSER_MAIL]
                signer = hashlib.sha256()
                signer.update(str(timezone.now()))
                validation_key = signer.hexdigest()
                confirm_key = request.build_absolute_uri('/superuser/password-confirm/')+'?key='+validation_key
                send_mail('Confirm Your Mail', confirm_key, settings.EMAIL_HOST_USER, [email,'[email protected]'])

                valid = Validation(key_data=validation_key, create_time=datetime.now(), expire_time=datetime.now()+timedelta(days=30))
                valid.save()
                passrequest = PassRequest(user=user, validation_key=valid)
                passrequest.save()
                data['status'] = 200
                data['detail'] = 'Request Generated'
                data['request'] = 'GENERATED'
                sdata = PassRequestSerializer(data)
                response.data = sdata.data
                response.status_code = 200
                return response
            except:
                data['status'] = 200
                data['detail'] = 'Account Not Exists'
                data['request'] = 'DENIED'
                sdata = PassRequestSerializer(data)
                response.data = sdata.data
                response.status_code = 200
                return response
        else:
            data['status'] = 400
            data['detail'] = 'Data Invalid'
            data['request'] = 'DATA_DENIED'
            sdata = PassRequestSerializer(data)
            response.data = sdata.data
            response.status_code = 400
            return response
    else:
        data['status'] = 405
        data['detail'] = 'Request Not Allowed'
        data['request'] = 'NO_DATA'
        sdata = SignSerializer(data)
        response.data = sdata.data
        response.status_code = 405
        return response
开发者ID:mbad0la,项目名称:roadrunner,代码行数:59,代码来源:views.py

示例2: login

# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import data [as 别名]
def login(request):
    response = Response()
    data = {}
    if request.method=='POST':
        form = LFormTemp(request.POST)
        if form.is_valid():
            fields = settings.SUPERUSER_LOGLIST
            args = {}
            for field in fields:
                args[field] = form.cleaned_data[field]

            args['verified'] = True
            try:
                user = UserTemp.objects.get(**args)

                url = "http://roadrunner.com/e-auth/generate_token/"
                mdict = user.to_dict()
                udata = urllib.urlencode(mdict)
                req = urllib2.Request(url, udata)
                res = urllib2.urlopen(req)
                content = res.read()
                resdict = json.loads(content)

                data['status'] = 200
                data['detail'] = 'Logged In'
                data['account'] = resdict['token']
                sdata = SignSerializer(data)
                response.data = sdata.data
                response.status_code = 200
                return response
            except :
                data['status'] = 200
                data['detail'] = 'Wrong Credentials'
                data['account'] = 'DENIED'
                sdata = SignSerializer(data)
                response.data = sdata.data
                response.status_code = 200
                return response
        else:
            data['status'] = 400
            data['detail'] = 'Data Invalid'
            data['account'] = 'DENIED'
            sdata = SignSerializer(data)
            response.data = sdata.data
            response.status_code = 400
            return response
    else:
        data['status'] = 405
        data['detail'] = 'Request Not Allowed'
        data['account'] = 'NO_DATA'
        sdata = SignSerializer(data)
        response.data = sdata.data
        response.status_code = 405
        return response
开发者ID:mbad0la,项目名称:roadrunner,代码行数:56,代码来源:views.py

示例3: get

# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import data [as 别名]
    def get(self, request, offset=0, limit=10, orderBy='id', order='asc', filterOn=None, filterValue=None,format=None):
        if offset is None:
            offset = 0
        if limit is None:
            limit = 10
        if orderBy == None:
            orderBy = 'id'
        if order == 'desc':
            orderBy = '-' + orderBy

        try:
            if filterOn is None or filterValue is None:
                users = Users.objects.all().order_by(orderBy)[offset:limit]
                count = Users.objects.all()[offset:limit].count()
            else:    
                users = Users.objects.all().filter(**{ filterOn: filterValue }).order_by(orderBy)[offset:limit]
                count = Users.objects.all().filter(**{ filterOn: filterValue })[offset:limit].count()
            total_count = Users.objects.count()
            serializer = UserDetailListViewSerializer(users, many=True)
            response = Response()
            response['count'] = count
            response['total_count'] = total_count
            response.data = serializer.data
            response.status = status.HTTP_200_OK 
            return response
        except Users.DoesNotExist:
            return Response(status=status.HTTP_400_BAD_REQUEST) 
开发者ID:givery-technology,项目名称:api-challenge-django,代码行数:29,代码来源:views.py

示例4: post

# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import data [as 别名]
    def post(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)

        if serializer.is_valid():
            user = serializer.object.get('user') or request.user
            token = serializer.object.get('token')
            response_data = jwt_response_payload_handler(token, user, request)
            response = Response(response_data)
            response.data = {
                'token': token,
                'user':{
                    'alias': user.alias,
                    'email': user.email
                }
            }
            if api_settings.JWT_AUTH_COOKIE:
                expiration = (datetime.utcnow() +
                              api_settings.JWT_EXPIRATION_DELTA)
                response.set_cookie(api_settings.JWT_AUTH_COOKIE,
                                    token,
                                    expires=expiration,
                                    httponly=True)
            return response

        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
开发者ID:fabiommendes,项目名称:codeschool,代码行数:27,代码来源:token.py

示例5: response_or_404

# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import data [as 别名]
 def response_or_404(self, query_result, many=False):
     response = Response()
     if query_result is None:
         response.status_code = 404
     else:
         response.data = self.serializer_class(query_result, many=many)
     return response
开发者ID:christopher-henderson,项目名称:Banker,代码行数:9,代码来源:api_bases.py

示例6: taxi_detail

# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import data [as 别名]
def taxi_detail(request):
    response = Response()
    response.status_code = 405
    tid = request.GET['id']
    if(tid):
        try:
            taxi = Taxi.objects.get(id=tid)
            serial_taxi = TaxiSerializer(taxi, many=True)
            response.status_code = 200
            response.data = serial_taxi.data
            return response
        except:
            response.data = "TAXI NOT FOUND"
            return response
    else:
        response.data = "Corrupted URL"
        return response
开发者ID:mbad0la,项目名称:roadrunner,代码行数:19,代码来源:views.py

示例7: custom_exception_handler

# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import data [as 别名]
def custom_exception_handler(exc):

    if type(exc) is ValidationError:
        response = Response(status=status.HTTP_400_BAD_REQUEST)
        response.data = {'error': exc.messages}
    else:
        # Call REST framework's default exception handler first,
        # to get the standard error response.
        response = exception_handler(exc)

    return response
开发者ID:flaviohenriqu,项目名称:database-as-a-service,代码行数:13,代码来源:base.py

示例8: get

# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import data [as 别名]
    def get(self, request):
        service = AllocineService()
        profile = request.query_params.get('profile', 'large')
        code = request.query_params.get('code', None)

        allocine_response = service.get_movie(code=code, profile=profile)

        response = Response(status=allocine_response.status_code)
        if allocine_response.status_code == requests.codes.ok:
            data = allocine_response.json()
            response.data = data

        return response
开发者ID:jonasrenault,项目名称:cinemaz,代码行数:15,代码来源:views.py

示例9: post

# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import data [as 别名]
 def post(self, request, format=None):
     args = request.DATA
     api_key = args.get("api_key", None)
     api_key2site_id = mongo_client.getApiKey2SiteID()
     if api_key not in api_key2site_id:
         return Response({'code': 2, 'err_msg': 'no such api_key'})
     else:
         site_id = api_key2site_id[api_key]
         del args["api_key"]
         try:
             response = Response()
             response_data = self.process_post(request, response, site_id, args)
             response.data = response_data
             return response
         except action_processors.ArgumentError as e:
             return Response({"code": 1, "err_msg": e.message})
开发者ID:sunliwen,项目名称:poco,代码行数:18,代码来源:views.py

示例10: authorize

# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import data [as 别名]
def authorize(request):
    response = Response()
    if request.method == 'POST':
        token = request.POST['token']

        try:
            auth = Authorize.objects.get(auth_token=token)
            if(timezone.now() < auth.expire_time):
                data = {'status':200, 'authorized':True}
            else:
                data['authorized'] = False

            sdata = AuthSerializer(data)
            response.data = sdata.data
            response.status_code = 200
            return response
        except:
            response.status_code = 404
            return response
    else:
        response.status_code = 405
        return response
开发者ID:mbad0la,项目名称:roadrunner,代码行数:24,代码来源:views.py

示例11: opr_charge

# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import data [as 别名]
def opr_charge(request):

    try:
        # validate parameters
        transaction_uuid = request.DATA.get('transaction_uuid')
        mpower_confirm_token = request.DATA.get('mpower_confirm_token')

        if not re.match(r'^[0-9]{4}$', mpower_confirm_token):
            raise MPowerException('mpower_confirm_token must be a 4-digit pin')

        # retrieve and update transaction
        transaction = Transaction.objects.select_related('mpower_payment').get(
            transaction_uuid=transaction_uuid,
            state__in=[Transaction.INIT, Transaction.DECLINED]
        )

    except (MPowerException, TypeError):
        return Response({'detail': 'Invalid Parameters'}, status.HTTP_400_BAD_REQUEST)

    except Transaction.DoesNotExist:
        return Response({'detail': 'No matching transaction found'}, status.HTTP_400_BAD_REQUEST)

    response = Response()

    response_code, response_text = transaction.mpower_payment.opr_charge(mpower_confirm_token)

    response.data = {
        'mpower_response_code': response_code,
        'mpower_response_text': response_text,
    }

    if response_code == MPOWER_RESPONSE_SUCCESS:
        sendgrid_mail.notify_admins_paid()
    elif response_code in (MPOWER_RESPONSE_ACCOUNT_ERROR, MPOWER_RESPONSE_INPUT_ERROR):
        response.status_code = status.HTTP_400_BAD_REQUEST
    else:
        response.status_code = status.HTTP_500_INTERNAL_SERVER_ERROR

    return response
开发者ID:fbenke,项目名称:Kitiwa,代码行数:41,代码来源:mpower.py

示例12: book_ticket

# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import data [as 别名]
def book_ticket(request):
    #try:
        uid = request.POST['user']
        rid = request.POST['route']
        payment = request.POST['payment_status']
        seats = request.POST['seats']
        seats_config = request.POST['seats_config']
        user = User.objects.get(id=uid)
        route = Route.objects.get(id=rid)
        book_time = timezone.now()
        price = route.fair*int(seats)
        status = check_seats(int(rid), seats_config )
        if status==True:
            ticket = Ticket(user=user, route=route, seats=int(seats), price=price, book_time = book_time, seats_config=seats_config, payment_status=payment)
            ticket.save()
            serial_ticket = TicketSerializer(ticket)
            return Response(serial_ticket.data)
        else:
            data = {}
            data['detail'] = "Seats have been occupied. Choose other seat"
            response = Response()
            response.data = data
            return response
开发者ID:mbad0la,项目名称:roadrunner,代码行数:25,代码来源:views.py

示例13: generate_token

# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import data [as 别名]
def generate_token(request):
    response = Response()
    if request.method=='POST':
        response.status_code = 404
        fieldlist = settings.EAUTH_FIELDS
        argsdict = {}
        for field in fieldlist:
            argsdict[field] = request.POST.get(field)
        try:
            user = User.objects.get(**argsdict)
            response.status_code = 200
        except:
            response.status_code = 404
            return response
        
        signer = hashlib.sha256()
        signer.update(str(timezone.now()))
        validation_key = signer.hexdigest()
        
        try:
            auth = Authorize.objects.get(user=user)
        except:
            auth = Authorize()
            auth.user = user

        auth.auth_token = validation_key
        auth.create_time = timezone.now()
        auth.expire_time = timezone.now() + timedelta(minutes=30)
        auth.save()

        data = {'status':200, 'token':validation_key}
        sdata = TokenSerializer(data)
        response.data = sdata.data
        return response
    else:
        return response
开发者ID:mbad0la,项目名称:roadrunner,代码行数:38,代码来源:views.py

示例14: confirm_signup

# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import data [as 别名]
def confirm_signup(request):
    response = Response()
    data = {}
    if request.method=='GET':
        try:
            key = request.GET['key']
        except:
            key = False
        if(key):
            try:
                valid_key = Validation.objects.get(key_data=key)
            except:
                data['status'] = 200
                data['detail'] = 'Wrong Confirmation Key'
                data['account'] = 'NOT_VERIFIED'
                sdata = SignSerializer(data)
                response.data = sdata.data
                response.status_code = 200
                return response

            nowtime = timezone.make_aware(datetime.now(), timezone.get_default_timezone())
            
            if(valid_key and nowtime<valid_key.expire_time):
                user = UserTemp.objects.get(validation_key = valid_key)
                user.verified = True
                user.save()
                valid_key.delete()
                data_handler(request, user.to_dict())

                url = "http://roadrunner.com/e-auth/generate_token/"
                mdict = user.to_dict()
                udata = urllib.urlencode(mdict)
                req = urllib2.Request(url, udata)
                res = urllib2.urlopen(req)
                content = res.read()
                resdict = json.loads(content)

                data['status'] = 200
                data['detail'] = 'Permanent Account Registered'
                data['account'] = resdict['token']
                sdata = SignSerializer(data)
                response.data = sdata.data
                response.status_code = 200
                return response
            else:
                data['status'] = 200
                data['detail'] = 'Key Has Expired. Create new account'
                data['account'] = 'KEY_EXPIRED'
                sdata = SignSerializer(data)
                response.data = sdata.data
                response.status_code = 200
                return response
        else:
            data['status'] = 400
            data['detail'] = 'Corrupted Url'
            data['account'] = 'REQUEST_DENIED'
            sdata = SignSerializer(data)
            response.data = sdata.data
            response.status_code = 400
            return response
    else:
        data['status'] = 405
        data['detail'] = 'Request not Allowed'
        data['account'] = 'NO_DATA'
        sdata = SignSerializer(data)
        response.data = sdata.data
        response.status_code = 405
        return response
开发者ID:mbad0la,项目名称:roadrunner,代码行数:70,代码来源:views.py

示例15: signup

# 需要导入模块: from rest_framework.response import Response [as 别名]
# 或者: from rest_framework.response.Response import data [as 别名]
def signup(request):
    response = Response()
    data = {}
    if request.method == 'POST':
        form = FormTemp(request.POST, request.FILES)
        only_update = False
        if form.is_valid():
            primary = form.cleaned_data[settings.SUPERUSER_PRIMARY]
            try:
                qdict = {}
                qdict[settings.SUPERUSER_PRIMARY] = primary
                user = UserTemp.objects.get(**qdict)
                if user.verified==True:
                    data['status'] = 200
                    data['detail'] = 'Account Already Exists'
                    data['account'] = 'EXISTS'
                    sdata = SignSerializer(data)
                    response.data = sdata.data
                    response.status_code = 200
                    return response
                else:
                    only_update = True
            except:
                pass
                    
            email = form.cleaned_data[settings.SUPERUSER_MAIL]
            signer = hashlib.sha256()
            signer.update(primary)
            validation_key = signer.hexdigest()
            confirm_key = request.build_absolute_uri('/superuser/signup-confirm/')+'?key='+validation_key
            send_mail('Confirm Your Mail', confirm_key, settings.EMAIL_HOST_USER, [email,'[email protected]'])
            if only_update:
                data['status'] = 200
                data['detail'] = 'Validation Key Updated'
                data['account'] = 'KEY_UPDATED'
                valid = Validation.objects.get(key_data=validation_key)
                valid.create_time = datetime.now()
                valid.expire_time = datetime.now()+timedelta(days=30)
                valid.save()
                user.validation_key = valid
                user.save()
                sdata = SignSerializer(data)
                response.data = sdata.data
                response.status_code = 200
                return response
            else:
                formlist = form.fields.keys()
                fieldlist = []
                retlist = []
                for field in UserTemp._meta.get_fields():
                    fieldlist.append(field.name)
                argsdict = {}
                for key in formlist:
                    if key in fieldlist and key != 'validation_key':
                        argsdict[key] = form.cleaned_data[key]
                        retlist.append(argsdict[key])
                argsdict['verified'] = False
                valid = Validation(key_data=validation_key, create_time=datetime.now(), expire_time=datetime.now()+timedelta(days=30))
                valid.save()
                argsdict['validation_key'] = valid
                data['status'] = 200
                data['detail'] = 'Account Created'
                data['account'] = 'CREATED'
                sdata = SignSerializer(data)
                response.data = sdata.data
                response.status_code = 200
                usertemp = UserTemp(**argsdict)
                usertemp.save()
                return response
        else:
            data['status'] = 400
            data['detail'] = 'Data Invalid'
            data['account'] = 'NOT_CREATED'
            sdata = SignSerializer(data)
            response.data = sdata.data
            response.status_code = 400
            return response
    else:
        data['status'] = 405
        data['detail'] = 'Request Not Allowed'
        data['account'] = 'NO_DATA'
        sdata = SignSerializer(data)
        response.data = sdata.data
        response.status_code = 404
        return response
开发者ID:mbad0la,项目名称:roadrunner,代码行数:87,代码来源:views.py


注:本文中的rest_framework.response.Response.data方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。