def set_registration_id(request): """Registration application""" if request.method == 'GET': try: device_id = request.GET['device_id'] registration_id = request.GET['registration_id'] # Check mimimum length if len(device_id) < 8: logger.info('DeviceId too short [%s]' % (device_id,)) return HttpResponse(status=400) if len(registration_id) < 8: logger.info('Registration id too short [%s]' % (registration_id,)) return HttpResponse(status=400) except KeyError, e: # When the input parameters are wrong, the script # is terminated code http 400th logger.info('KeyError [%s] [%s]' % (e, request.GET,)) return HttpResponse(status=400) try: # We check the database if they already have such # device with a given ID ad = AndroidDevice.objects.filter( device_id=device_id)[0] task_registration = send_registration_token(ad.id, registration_id) logger.info('Registration device is in the queue ' '[ad=%s,regid=%s]' % (device_id, registration_id)) response = HttpResponse(status=200) response.task_registration = task_registration return response except ValidationError, e: logger.debug('ValidationError [%s]' % e) return HttpResponse(status=400)
# Registration new device try: ad = AndroidDevice() ad.device_id = request.GET['device_id'] ad.full_clean() ad.save() task_registration = send_registration_token(ad.id, registration_id) logger.info('Re-registration device is in the queue' ' [ad=%s,regid=%s]' % (device_id, registration_id)) response = HttpResponse(status=200) response.task_registration = task_registration return response except ValidationError, e: logger.debug('ValidationError [%s]' % e) return HttpResponse(status=400) else: return HttpResponse(status=501) return HttpResponse(status=500) @csrf_exempt def check_token(request): """Check registration token"""