Skip to content

Commit

Permalink
Add deliver_progress and passing_score to opportunity api
Browse files Browse the repository at this point in the history
  • Loading branch information
pxwxnvermx committed Sep 21, 2023
1 parent b4d80ff commit ba1cd35
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions commcare_connect/opportunity/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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
Expand All @@ -58,6 +59,7 @@ class Meta:
"total_budget",
"claim",
"learn_progress",
"deliver_progress",
]

def get_claim(self, obj):
Expand All @@ -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):
Expand Down

0 comments on commit ba1cd35

Please sign in to comment.