From ba1cd356354ef33cf6ca65f2eae85e6ed22071ab Mon Sep 17 00:00:00 2001 From: Pawan Verma Date: Thu, 21 Sep 2023 19:27:56 +0530 Subject: [PATCH] Add deliver_progress and passing_score to opportunity api --- commcare_connect/opportunity/api/serializers.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/commcare_connect/opportunity/api/serializers.py b/commcare_connect/opportunity/api/serializers.py index a2ce7fa9..d2297ba1 100644 --- a/commcare_connect/opportunity/api/serializers.py +++ b/commcare_connect/opportunity/api/serializers.py @@ -24,7 +24,7 @@ class CommCareAppSerializer(serializers.ModelSerializer): class Meta: model = CommCareApp - fields = ["cc_domain", "cc_app_id", "name", "description", "organization", "learn_modules"] + fields = ["cc_domain", "cc_app_id", "name", "description", "organization", "learn_modules", "passing_score"] class OpportunityClaimSerializer(serializers.ModelSerializer): @@ -39,6 +39,7 @@ class OpportunitySerializer(serializers.ModelSerializer): deliver_app = CommCareAppSerializer() claim = serializers.SerializerMethodField() learn_progress = serializers.SerializerMethodField() + deliver_progress = serializers.SerializerMethodField() class Meta: model = Opportunity @@ -58,6 +59,7 @@ class Meta: "total_budget", "claim", "learn_progress", + "deliver_progress", ] def get_claim(self, obj): @@ -73,10 +75,14 @@ def get_learn_progress(self, obj): completed_modules = CompletedModule.objects.filter(opportunity=opp_access.opportunity) return {"total_modules": total_modules.count(), "completed_modules": completed_modules.count()} + def get_deliver_progress(self, obj): + opp_access = _get_opp_access(self.context.get("request").user, obj) + return opp_access.visit_count + -@quickcache(vary_on=["user.pk", "obj.pk"], timeout=60 * 60) -def _get_opp_access(user, obj): - return OpportunityAccess.objects.filter(user=user, opportunity=obj).first() +@quickcache(vary_on=["user.pk", "opportunity.pk"], timeout=60 * 60) +def _get_opp_access(user, opportunity): + return OpportunityAccess.objects.filter(user=user, opportunity=opportunity).first() class UserLearnProgressSerializer(serializers.ModelSerializer):