views.py 文件源码

python
阅读 14 收藏 0 点赞 0 评论 0

项目:django-ios-notifications 作者: nnsnodnb 项目源码 文件源码
def device_token_receive(request):
    if request.method != 'PUT':
        return HttpResponse(status=405)

    if request.body is b'':
        return JsonResponse({'error': 'Bad Request'}, status=400)

    query_dict = request.body.decode('utf-8')
    body = json.loads(query_dict)

    error = False
    if 'device_token' not in body:
        error = True
    if 'uuid' not in body:
        error = True
    if 'sandbox' not in body:
        error = True

    if error:
        return JsonResponse({'error': 'Bad Request'}, status=400)

    device_token = body['device_token']
    uuid = body['uuid']
    sandbox = body['sandbox']

    if DeviceToken.objects.filter(uuid=uuid).count() != 0:
        token = DeviceToken.objects.get(uuid=uuid)
        token.device_token = device_token
        token.use_sandbox = sandbox
        token.save()
    else:
        token = DeviceToken()
        token.device_token = device_token
        token.uuid = uuid
        token.use_sandbox = sandbox
        token.save()

    return JsonResponse({'result': 'success'}, status=200)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号