示例#1
0
def cat_deregister_push(request):
    cat_push_register_form = CatPushRegisterForm(request.data)
    profile = request.get_user().catprofile
    content = {
        'error': 0
    }
    cat_push_register_form.data["profile"] = profile
    if cat_push_register_form.is_valid():
        try:
            CatPushDevice.objects.get(
                type=cat_push_register_form.cleaned_data['type'],
                token=cat_push_register_form.cleaned_data['token'],
                profile_id=profile.id
            ).delete()
        except ObjectDoesNotExist:
            content['error'] = 4
    else:
        content['error'] = 2

    return Response(content)
示例#2
0
def cat_register_push(request):
    cat_push_register_form = CatPushRegisterForm(request.data)
    profile = request.get_user().catprofile
    cat_push_register_form.data["profile"] = profile
    content = {
        'error': 4
    }
    if cat_push_register_form.is_valid():
        try:
            existing_device = CatPushDevice.objects.get(
                type=cat_push_register_form.cleaned_data['type'],
                profile_id=profile.id
            )
            existing_device.push_token = cat_push_register_form.cleaned_data['token']
            existing_device.save()
            content['error'] = 0
        except ObjectDoesNotExist:
            cat_push_register_form.save()
            content['error'] = 0
    else:
        content['error'] = 2

    return Response(content)