def check_phone_import_recorded(request): try: recorded = models.UserContactsImport.check_phone_record(user=request.user) context = {"recorded": recorded} return Response(success_resp(data=context), status=status.HTTP_200_OK) except ValueError as ve: return Response(error_resp(message=str(ve)), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return Response(error_resp(message=str(e)), status=status.HTTP_400_BAD_REQUEST)
def set_last_opened(request): try: request.user.userprofile.set_last_opened() context = {'message': 'success'} return Response(success_resp(data=context), status=status.HTTP_200_OK) except ValueError as ve: return Response(error_resp(message=str(ve)), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return Response(error_resp(message=str(e)), status=status.HTTP_400_BAD_REQUEST)
def update_phone(request): phone = get_value_or_404(request.data, 'phone') OTP = get_value_or_404(request.data, 'OTP') try: data = request.user.userprofile.update_phone(phone=phone, OTP=OTP) return Response(success_resp(data=data), status=status.HTTP_200_OK) except ValueError as ve: return Response(error_resp(message=str(ve)), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return Response(error_resp(message=str(e)), status=status.HTTP_400_BAD_REQUEST)
def post(self, request, username, format=None): try: followee = User.objects.get(username=username) data = models.UserFollower.update(followee=followee, follower=request.user) return Response(success_resp(data=data), status=status.HTTP_200_OK) except ValueError as ve: return Response(error_resp(message=str(ve)), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return Response(error_resp(message=str(e)), status=status.HTTP_400_BAD_REQUEST)
def import_contacts(request): try: contacts = get_value_or_404(request.data, 'contacts') contacts = json.loads(contacts) print(type(contacts)) tasks.import_contacts_from_phone.delay(user_id=request.user.id, contacts=contacts) context = {"status": "success"} return Response(success_resp(data=context), status=status.HTTP_200_OK) except ValueError as ve: return Response(error_resp(message=str(ve)), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return Response(error_resp(message=str(e)), status=status.HTTP_400_BAD_REQUEST)
def get_suggestions_list(request): try: data = request.user.userprofile.get_suggestions() connections = serializers.UserMiniSerializer(data['suggestions'], many=True).data context = {'connections': connections} return Response(success_resp(data=context), status=status.HTTP_200_OK) except ValueError as ve: return Response(error_resp(message=str(ve)), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return Response(error_resp(message=str(e)), status=status.HTTP_400_BAD_REQUEST)
def get_status_feed(request): try: data = models.UserFollower.find_followings_and_status_updates( user=request.user) followings = serializers.UserProfileMiniSerializer(data['followings'], many=True).data context = {'followings': followings, 'count': data['count']} return Response(success_resp(data=context), status=status.HTTP_200_OK) except ValueError as ve: return Response(error_resp(message=str(ve)), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return Response(error_resp(message=str(e)), status=status.HTTP_400_BAD_REQUEST)
def get_connections_list(request): try: operation = get_value_or_404(request.GET, 'operation') data = models.UserFollower.get_connections(user=request.user, operation=operation) connections = serializers.UserMiniSerializer(data['connections'], many=True).data context = {'connections': connections, 'count': data['count']} return Response(success_resp(data=context), status=status.HTTP_200_OK) except ValueError as ve: return Response(error_resp(message=str(ve)), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return Response(error_resp(message=str(e)), status=status.HTTP_400_BAD_REQUEST)
def get_user_profile(request, username): user_profile = models.UserProfile.get_from_username(username) try: sdata = serializers.UserProfilePublicSerializer(user_profile, context={ 'user': request.user }).data data = {'user': sdata} return Response(success_resp(data=data), status=status.HTTP_200_OK) except ValueError as ve: return Response(error_resp(message=str(ve)), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return Response(error_resp(message=str(e)), status=status.HTTP_400_BAD_REQUEST)
def update_email(request): email = get_value_or_404(request.data, 'email') otp = get_value_or_404(request.data, 'otp') password = get_value_or_404(request.data, 'password') try: models.UserProfile.update_email(user=request.user, new_email=email, otp=otp, password=password) context = {'message': 'Email updated successfully'} return Response(success_resp(data=context), status=status.HTTP_200_OK) except ValueError as ve: return Response(error_resp(message=str(ve)), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return Response(error_resp(message=str(e)), status=status.HTTP_400_BAD_REQUEST)
def get_notification_feed(request): try: offset = get_value_or_default(request.GET, 'offset', 0) data = models.UserNotification.get_notifications(user=request.user, offset=offset) notifications = serializers.UserNotificationFeedSerializer( data['notifications'], many=True).data context = { 'notifications': notifications, 'total_count': data['total_count'], 'read_count': data['read_count'] } return Response(success_resp(data=context), status=status.HTTP_200_OK) except ValueError as ve: return Response(error_resp(message=str(ve)), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return Response(error_resp(message=str(e)), status=status.HTTP_400_BAD_REQUEST)
def get_connections_list_in_common_param(request): try: parameter = get_value_or_404(request.GET, 'parameter') data = models.UserFollower.get_connections_with_common( user=request.user, parameter=parameter) connections = serializers.UserMiniConnectionSerializer(data['all'], many=True, context={ 'user': request.user }).data context = {'connections': connections} return Response(success_resp(data=context), status=status.HTTP_200_OK) except ValueError as ve: return Response(error_resp(message=str(ve)), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return Response(error_resp(message=str(e)), status=status.HTTP_400_BAD_REQUEST)
def get_people_list(request): try: code = get_value_or_404(request.GET, 'code') type = get_value_or_404(request.GET, 'type') data = models.UserFollower.get_people(user=request.user, code=code, type=type) connections = serializers.UserMiniConnectionSerializer(data['all'], many=True, context={ 'user': request.user }).data context = {'connections': connections} return Response(success_resp(data=context), status=status.HTTP_200_OK) except ValueError as ve: return Response(error_resp(message=str(ve)), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return Response(error_resp(message=str(e)), status=status.HTTP_400_BAD_REQUEST)
def check_phone_verification(request): phone = get_value_or_404(request.data, 'phone') operation = get_value_or_404(request.data, 'operation') OTP = get_value_or_default(request.data, 'OTP', None) try: data = models.UserProfile.phone_input(operation=operation, phone=phone, OTP=OTP) if operation == 'VERIFY_USER_PHONE': context = {'phone_verified': data['phone_verified']} elif operation == 'VERIFY_USER_REGISTRATION': context = {'user_registered': data['user_registered']} elif operation == 'SEND_PHONE_VERIFICATION_OTP': context = {'message': data['message']} elif operation == 'SEND_PHONE_VERIFICATION_OTP_ALLOW_ANY': context = {'message': data['message']} return Response(success_resp(data=context), status=status.HTTP_200_OK) except ValueError as ve: return Response(error_resp(message=str(ve)), status=status.HTTP_400_BAD_REQUEST) except Exception as e: return Response(error_resp(message=str(e)), status=status.HTTP_400_BAD_REQUEST)