def updateUser(request): response = { 'success': False, 'username': request.user.username, 'debug': '', } try: request_json = json.loads(request.body) try: profile = Profile.objects.get(owner=request.user) except Exception as e: print(e) profile = Profile() profile.owner = request.user if 'push_token' in request_json and request_json['push_token']: profile.push_token = request_json['push_token'] if 'push_notification' in request_json: profile.push_notification = request_json['push_notification'] if 'telegram_notification' in request_json: profile.telegram_notification = request_json[ 'telegram_notification'] if 'email_notification' in request_json: profile.email_notification = request_json['email_notification'] if 'notification_message' in request_json and request_json[ 'notification_message']: profile.notification_message = request_json['notification_message'] profile.save() response['success'] = True except Exception as e: response['debug'] = str(e) return Response(response)