Exemplo n.º 1
0
def add_device_token(request, name):
    """
    Notification
    """
    device_id = request.DATA['device']
    token = request.DATA['token']
    try:
        device = APPDevice.objects.get(identifier=device_id)
    except APPDevice.DoesNotExist:
        device = APPDevice(identifier=device_id, system='', platform='')
        device.save()

    try:
        service = APNService.objects.get(app__area__en_name=name)
    except APNService.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    deviceTokens = DeviceToken.objects.filter(token=token, service=service)
    if deviceTokens.exists():
        deviceToken = deviceTokens.get()
        deviceToken.is_active = True
        deviceToken.device = device
        deviceToken.save()
        return Response(status=status.HTTP_201_CREATED)
    else:
        deviceToken = DeviceToken(token=token, device=device, service=service)
        deviceToken.is_active = True
        deviceToken.save()
        return Response(status=status.HTTP_201_CREATED)
    return Response(status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 2
0
def add_device_token(request, name):
    """
    Notification
    """
    device_id = request.DATA['device']
    token = request.DATA['token']
    try:
        device = APPDevice.objects.get(identifier=device_id)
    except APPDevice.DoesNotExist:
        device = APPDevice(identifier=device_id, system='', platform='')
        device.save()

    try:
        service = APNService.objects.get(app__area__en_name=name)
    except APNService.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    deviceTokens = DeviceToken.objects.filter(token=token, service=service)
    if deviceTokens.exists():
        deviceToken = deviceTokens.get()
        deviceToken.is_active = True
        deviceToken.device = device
        deviceToken.save()
        return Response(status=status.HTTP_201_CREATED)
    else:
        deviceToken = DeviceToken(token=token, device=device, service=service)
        deviceToken.is_active = True
        deviceToken.save()
        return Response(status=status.HTTP_201_CREATED)
    return Response(status=status.HTTP_400_BAD_REQUEST)
Exemplo n.º 3
0
def export_device_token():
    from cityapp.apps.city_viewer.models.appinfo import APPDeviceToken
    from cityapp.apps.ios_notifications.models import DeviceToken, APNService
    tokens = APPDeviceToken.objects.all()
    for token in tokens:
        print token.token
        services = APNService.objects.filter(app=token.app)
        if services.exists():
            service = services.get()
        else:
            service = APNService(app=token.app)
            service.save()

        new_token = DeviceToken(service=service, device=token.device, token=token.token, is_active=True)
        new_token.save()
Exemplo n.º 4
0
def export_device_token():
    from cityapp.apps.city_viewer.models.appinfo import APPDeviceToken
    from cityapp.apps.ios_notifications.models import DeviceToken, APNService
    tokens = APPDeviceToken.objects.all()
    for token in tokens:
        print token.token
        services = APNService.objects.filter(app=token.app)
        if services.exists():
            service = services.get()
        else:
            service = APNService(app=token.app)
            service.save()

        new_token = DeviceToken(service=service,
                                device=token.device,
                                token=token.token,
                                is_active=True)
        new_token.save()