Skip to content

Commit

Permalink
Merge pull request #1750 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
lc
  • Loading branch information
adnankattekaden authored Dec 5, 2023
2 parents 6d392ad + 5c57362 commit 08b4e42
Showing 1 changed file with 33 additions and 3 deletions.
36 changes: 33 additions & 3 deletions api/common/common_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,21 @@ def get(self, request):

class CollegeWiseLcReportCSV(APIView):
def get(self, request):
learning_circle_count_subquery = (
LearningCircle.objects.filter(org__org_type=OrganizationType.COLLEGE.value)
.values(org_title=F("org__title"))
.annotate(learning_circle_count=Count("id"))
.filter(org_title=OuterRef("org_title"))
.values("learning_circle_count")
[:1]
)

learning_circles_info = (
LearningCircle.objects.filter(org__org_type=OrganizationType.COLLEGE.value)
.values(org_title=F("org__title"))
.annotate(
learning_circle_count=Count("id"), user_count=Count("user_circle_link_circle")
learning_circle_count=Subquery(learning_circle_count_subquery),
user_count=Count("user_circle_link_circle__user"),
)
.order_by("org_title")
)
Expand All @@ -241,20 +251,40 @@ class CollegeWiseLcReport(APIView):
def get(self, request):
date = request.query_params.get('date')
if date:
learning_circle_count_subquery = (
LearningCircle.objects.filter(org__org_type=OrganizationType.COLLEGE.value, created_at__date=date)
.values(org_title=F("org__title"))
.annotate(learning_circle_count=Count("id"))
.filter(org_title=OuterRef("org_title"))
.values("learning_circle_count")
[:1]
)

learning_circles_info = (
LearningCircle.objects.filter(org__org_type=OrganizationType.COLLEGE.value, created_at__date=date)
.values(org_title=F("org__title"))
.annotate(
learning_circle_count=Count("id"), user_count=Count("user_circle_link_user")
learning_circle_count=Subquery(learning_circle_count_subquery),
user_count=Count("user_circle_link_circle__user")
)
.order_by("org_title")
)
else:
learning_circle_count_subquery = (
LearningCircle.objects.filter(org__org_type=OrganizationType.COLLEGE.value)
.values(org_title=F("org__title"))
.annotate(learning_circle_count=Count("id"))
.filter(org_title=OuterRef("org_title"))
.values("learning_circle_count")
[:1]
)

learning_circles_info = (
LearningCircle.objects.filter(org__org_type=OrganizationType.COLLEGE.value)
.values(org_title=F("org__title"))
.annotate(
learning_circle_count=Count("id"), user_count=Count("user_circle_link_user")
learning_circle_count=Subquery(learning_circle_count_subquery),
user_count=Count("user_circle_link_circle__user"),
)
.order_by("org_title")
)
Expand Down

0 comments on commit 08b4e42

Please sign in to comment.