From 64ba5a4ae82e1d2296bd2e15e066c6171d07966d Mon Sep 17 00:00:00 2001 From: ParthipPR Date: Thu, 29 Aug 2024 19:41:03 +0530 Subject: [PATCH 1/3] "Fix: Corrected error in User term Serializer" --- api/dashboard/profile/profile_serializer.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/api/dashboard/profile/profile_serializer.py b/api/dashboard/profile/profile_serializer.py index 3839a3a8..0a709119 100644 --- a/api/dashboard/profile/profile_serializer.py +++ b/api/dashboard/profile/profile_serializer.py @@ -443,7 +443,7 @@ class Meta: "is_userterms_approved", "user", ] - def get_userterm(self, instance, validated_data): + def update(self, instance, validated_data): instance.is_userterms_approved = validated_data.get('is_userterms_approved', instance.is_userterms_approved) instance.save() return instance From 571b600cfe0da7e4a952a19b1026c5326b878093 Mon Sep 17 00:00:00 2001 From: ParthipPR Date: Thu, 29 Aug 2024 23:00:02 +0530 Subject: [PATCH 2/3] "Fix: made few change sto the userterm api" --- api/dashboard/profile/profile_view.py | 46 ++++++++++++++++----------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/api/dashboard/profile/profile_view.py b/api/dashboard/profile/profile_view.py index 78682db4..817a2930 100644 --- a/api/dashboard/profile/profile_view.py +++ b/api/dashboard/profile/profile_view.py @@ -439,12 +439,16 @@ def get(self, request, muid): ).get_failure_response() class UsertermAPI(APIView): - def post(self, request,muid): - user = User.objects.get(muid=muid) + def post(self, request, muid): + try: + user = User.objects.get(muid=muid) + except User.DoesNotExist: + return CustomResponse(response="The user does not exist").get_failure_response() + try: settings = UserSettings.objects.get(user=user) except UserSettings.DoesNotExist: - return CustomResponse(response="The user setting doesn't exists").get_failure_response() + return CustomResponse(response="The user settings don't exist").get_failure_response() serializer = UserTermSerializer(settings, data={"is_userterms_approved": True}, partial=True) if serializer.is_valid(): @@ -453,18 +457,24 @@ def post(self, request,muid): response_data = {"message": "User terms have been successfully approved."} return CustomResponse(response=response_data).get_success_response() else: - return CustomResponse(response="The given muid seems to be invalid").get_failure_response() - return CustomResponse(response="Invalid data provided.").get_failure_response() - - def get(self,request,muid): - user = User.objects.get(muid=muid) - try: - settings = UserSettings.objects.get(user=user) - except UserSettings.DoesNotExist: - return CustomResponse(response="The user settings doesn't exists").get_failure_response() - if settings.is_userterms_approved: - response_data = {"message": "User terms are approved."} - return CustomResponse(response=response_data).get_success_response() - else: - response_data = {"message": "User terms are not approved."} - return CustomResponse(response=response_data).get_failure_response() + response_data = {"message": "The user terms have not been successfully approved."} + return CustomResponse(response=response_data).get_failure_response() + return CustomResponse(response="Invalid data provided").get_failure_response() + + def get(self, request, muid): + try: + user = User.objects.get(muid=muid) + except User.DoesNotExist: + return CustomResponse(response="The user does not exist").get_failure_response() + + try: + settings = UserSettings.objects.get(user=user) + except UserSettings.DoesNotExist: + return CustomResponse(response="The user settings don't exist").get_failure_response() + + if settings.is_userterms_approved: + response_data = {"message": "User terms are approved."} + return CustomResponse(response=response_data).get_success_response() + else: + response_data = {"message": "User terms are not approved."} + return CustomResponse(response=response_data).get_failure_response() From 194f7cff18934fc091cfb30967269a5ef4fd9771 Mon Sep 17 00:00:00 2001 From: ParthipPR Date: Thu, 29 Aug 2024 23:16:04 +0530 Subject: [PATCH 3/3] "Fix: corrected an error in user term serializer" --- api/dashboard/profile/profile_serializer.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/api/dashboard/profile/profile_serializer.py b/api/dashboard/profile/profile_serializer.py index 0a709119..2a864ba7 100644 --- a/api/dashboard/profile/profile_serializer.py +++ b/api/dashboard/profile/profile_serializer.py @@ -434,8 +434,6 @@ def create_karma_activity_log(task_hashtag, karma_value): return super().update(instance, validated_data) class UserTermSerializer(serializers.ModelSerializer): - is_userterms_approved = serializers.SerializerMethodField() - class Meta: model = UserSettings