Skip to content

Commit

Permalink
Merge pull request #1221 from gtech-mulearn/dev-server
Browse files Browse the repository at this point in the history
campus fix
  • Loading branch information
adnankattekaden authored Oct 7, 2023
2 parents c33f479 + 7966a68 commit a82eff2
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions api/dashboard/campus/campus_views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django.db.models import Count, Q, F, Case, When, Value
from django.db.models import Sum
from django.db.models.functions import Coalesce
from rest_framework.views import APIView

from db.task import Level, Wallet
Expand Down Expand Up @@ -105,6 +107,23 @@ def get(self, request):

ranks = {user["user_id"]: i + 1 for i, user in enumerate(rank)}

# user_org_links = (
# User.objects.filter(
# user_organization_link_user__org=user_org_link.org,
# user_organization_link_user__org__org_type=OrganizationType.COLLEGE.value,
# )
# .distinct()
# .annotate(
# user_id=F("id"),
# muid=F("mu_id"),
# karma=F("wallet_user__karma"),
# level=F("user_lvl_link_user__level__name"),
# join_date=F("created_at"),
# is_active=Case(
# When(Q(karma_activity_log_user__created_at__range=(start_date, end_date)), then=Value("Active")),
# default=Value("Not Active")
# )
# ))
user_org_links = (
User.objects.filter(
user_organization_link_user__org=user_org_link.org,
Expand All @@ -114,14 +133,18 @@ def get(self, request):
.annotate(
user_id=F("id"),
muid=F("mu_id"),
karma=F("wallet_user__karma"),
karma=Coalesce(Sum("wallet_user__karma"), 0),
level=F("user_lvl_link_user__level__name"),
join_date=F("created_at"),
is_active=Case(
When(Q(karma_activity_log_user__created_at__range=(start_date, end_date)), then=Value("Active")),
When(
Q(karma_activity_log_user__created_at__range=(start_date, end_date)),
then=Value("Active")
),
default=Value("Not Active")
)
))
)
)
paginated_queryset = CommonUtils.get_paginated_queryset(
user_org_links,
request,
Expand Down

0 comments on commit a82eff2

Please sign in to comment.