Skip to content

Commit

Permalink
Merge pull request #1663 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
last karma fixed
  • Loading branch information
adnankattekaden authored Nov 30, 2023
2 parents 61e3c18 + 855d70e commit 8fcf2a2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 12 deletions.
18 changes: 10 additions & 8 deletions api/dashboard/campus/campus_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db.models import Count, F
from django.db.models import Q, Case, When, Value
from django.db.models import Q
from rest_framework.views import APIView

from db.organization import UserOrganizationLink
Expand All @@ -8,7 +8,7 @@
from utils.permission import CustomizePermission, JWTUtils, role_required
from utils.response import CustomResponse
from utils.types import OrganizationType, RoleType
from utils.utils import CommonUtils, DateTimeUtils
from utils.utils import CommonUtils
from . import serializers
from .dash_campus_helper import get_user_college_link

Expand All @@ -29,7 +29,7 @@ class CampusDetailsAPI(APIView):
authentication_classes = [CustomizePermission]

# Use the role_required decorator to specify the allowed roles for this view
@role_required([RoleType.CAMPUS_LEAD.value, RoleType.ENABLER.value, RoleType.LEAD_ENABLER.value])
@role_required([RoleType.CAMPUS_LEAD.value, RoleType.LEAD_ENABLER.value])
def get(self, request):
# Fetch the user's ID from the request using JWTUtils
user_id = JWTUtils.fetch_user_id(request)
Expand All @@ -54,7 +54,7 @@ def get(self, request):
class CampusStudentInEachLevelAPI(APIView):
authentication_classes = [CustomizePermission]

@role_required([RoleType.CAMPUS_LEAD.value, RoleType.ENABLER.value, RoleType.LEAD_ENABLER.value])
@role_required([RoleType.CAMPUS_LEAD.value, RoleType.LEAD_ENABLER.value])
def get(self, request):
user_id = JWTUtils.fetch_user_id(request)

Expand All @@ -80,7 +80,7 @@ def get(self, request):
class CampusStudentDetailsAPI(APIView):
authentication_classes = [CustomizePermission]

@role_required([RoleType.CAMPUS_LEAD.value, RoleType.ENABLER.value, RoleType.LEAD_ENABLER.value])
@role_required([RoleType.CAMPUS_LEAD.value, RoleType.LEAD_ENABLER.value])
def get(self, request):
user_id = JWTUtils.fetch_user_id(request)
user_org_link = get_user_college_link(user_id)
Expand Down Expand Up @@ -121,6 +121,7 @@ def get(self, request):
karma=F("wallet_user__karma"),
level=F("user_lvl_link_user__level__name"),
join_date=F("created_at"),
last_karma_gained=F("wallet_user__karma_last_update_at"),
department=F('user_organization_link_user__department__title'),
graduation_year=F("user_organization_link_user__graduation_year"),
is_alumni=F('user_organization_link_user__is_alumni'),
Expand Down Expand Up @@ -154,6 +155,7 @@ def get(self, request):
karma=F("wallet_user__karma"),
level=F("user_lvl_link_user__level__name"),
join_date=F("created_at"),
last_karma_gained=F("wallet_user__karma_last_update_at"),
department=F('user_organization_link_user__department__title'),
graduation_year=F("user_organization_link_user__graduation_year"),
is_alumni=F('user_organization_link_user__is_alumni'),
Expand Down Expand Up @@ -189,7 +191,7 @@ def get(self, request):
class CampusStudentDetailsCSVAPI(APIView):
authentication_classes = [CustomizePermission]

@role_required([RoleType.CAMPUS_LEAD.value, RoleType.ENABLER.value, RoleType.LEAD_ENABLER.value])
@role_required([RoleType.CAMPUS_LEAD.value, RoleType.LEAD_ENABLER.value])
def get(self, request):
user_id = JWTUtils.fetch_user_id(request)
user_org_link = get_user_college_link(user_id)
Expand Down Expand Up @@ -292,7 +294,7 @@ def get(self, request):
class WeeklyKarmaAPI(APIView):
authentication_classes = [CustomizePermission]

@role_required([RoleType.CAMPUS_LEAD.value, RoleType.ENABLER.value, RoleType.LEAD_ENABLER.value])
@role_required([RoleType.CAMPUS_LEAD.value, RoleType.LEAD_ENABLER.value])
def get(self, request):
user_id = JWTUtils.fetch_user_id(request)

Expand All @@ -310,7 +312,7 @@ def get(self, request):
class ChangeStudentTypeAPI(APIView):
authentication_classes = [CustomizePermission]

@role_required([RoleType.CAMPUS_LEAD.value, RoleType.ENABLER.value, RoleType.LEAD_ENABLER.value])
@role_required([RoleType.CAMPUS_LEAD.value, RoleType.LEAD_ENABLER.value])
def patch(self, request, member_id):
user_id = JWTUtils.fetch_user_id(request)

Expand Down
8 changes: 4 additions & 4 deletions api/dashboard/campus/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class CampusDetailsSerializer(serializers.ModelSerializer):
college_name = serializers.ReadOnlyField(source="org.title")
campus_code = serializers.ReadOnlyField(source="org.code")
campus_zone = serializers.ReadOnlyField(source="org.district.zone.name")
campus_lead = serializers.ReadOnlyField(source="user.fullname")
campus_level = serializers.SerializerMethodField()
total_karma = serializers.SerializerMethodField()
total_members = serializers.SerializerMethodField()
Expand All @@ -28,7 +27,6 @@ class Meta:
model = UserOrganizationLink
fields = [
"college_name",
"campus_lead",
"campus_code",
"campus_zone",
"campus_level",
Expand All @@ -52,7 +50,7 @@ def get_lead(self, obj):
enabler = User.objects.filter(
user_organization_link_user__org=obj.org,
user_organization_link_user__org__org_type=OrganizationType.COLLEGE.value,
user_role_link_user__role__title=RoleType.ENABLER.value,
user_role_link_user__role__title=RoleType.LEAD_ENABLER.value,
).first()
if enabler:
enabler = enabler.fullname
Expand Down Expand Up @@ -119,14 +117,16 @@ class CampusStudentDetailsSerializer(serializers.Serializer):
level = serializers.CharField()
# is_active = serializers.CharField()
join_date = serializers.CharField()
last_karma_gained = serializers.CharField()
email = serializers.CharField()
mobile = serializers.CharField()
graduation_year = serializers.CharField()
department = serializers.CharField()
is_alumni = serializers.CharField()

class Meta:
fields = ("user_id", "email", "mobile", "fullname", "karma", "muid", "rank", "level", "join_date", "is_alumni")
fields = ("user_id", "email", "mobile", "fullname", "karma", "muid", "rank", "level", "join_date", "is_alumni",
"last_karma_update_at")

def get_rank(self, obj):
ranks = self.context.get("ranks")
Expand Down

0 comments on commit 8fcf2a2

Please sign in to comment.