Skip to content

Commit

Permalink
Merge branch 'dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
adnankattekaden authored Dec 21, 2023
2 parents 9177091 + e3f316f commit 2b3f3b3
Show file tree
Hide file tree
Showing 30 changed files with 364 additions and 244 deletions.
8 changes: 4 additions & 4 deletions api/common/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,19 @@ class UserLeaderboardSerializer(serializers.ModelSerializer):
interest_groups = serializers.SerializerMethodField()
organizations = serializers.SerializerMethodField()
karma = serializers.IntegerField(source="wallet_user.karma")
fullname = serializers.SerializerMethodField()
full_name = serializers.SerializerMethodField()

class Meta:
model = User
fields = (
'fullname',
'full_name',
"karma",
"interest_groups",
"organizations",
)

def get_fullname(self, obj):
return obj.fullname
def get_full_name(self, obj):
return obj.full_name

def get_organizations(self, obj):
return obj.user_organization_link_user.all().values_list("org__title", flat=True)
Expand Down
7 changes: 4 additions & 3 deletions api/dashboard/affiliation/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@


class AffiliationListSerializer(serializers.ModelSerializer):
created_by = serializers.CharField(source="created_by.fullname")
updated_by = serializers.CharField(source="updated_by.fullname")
created_by = serializers.CharField(source="created_by.full_name")
updated_by = serializers.CharField(source="updated_by.full_name")
organization_count = serializers.SerializerMethodField()

class Meta:
model = OrgAffiliation
fields = ['id', 'title', 'organization_count', 'created_by', 'updated_by', 'updated_at', 'created_at']
fields = ['id', 'title', 'organization_count',
'created_by', 'updated_by', 'updated_at', 'created_at']

def get_organization_count(self, obj):
return obj.organization_affiliation.count()
Expand Down
32 changes: 17 additions & 15 deletions api/dashboard/campus/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ def get_lead(self, obj):
user_role_link_user__role__title=RoleType.CAMPUS_LEAD.value,
).first()
if campus_lead:
campus_lead = campus_lead.fullname
campus_lead = campus_lead.full_name

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.LEAD_ENABLER.value,
).first()
if enabler:
enabler = enabler.fullname
enabler = enabler.full_name

return {'campus_lead': campus_lead, 'enabler': enabler}

Expand All @@ -78,17 +78,18 @@ def get_active_members(self, obj):

def get_total_karma(self, obj):
return (
obj.org.user_organization_link_org.filter(
org__org_type=OrganizationType.COLLEGE.value,
verified=True,
user__wallet_user__isnull=False,
).aggregate(total_karma=Sum("user__wallet_user__karma"))["total_karma"]
or 0
obj.org.user_organization_link_org.filter(
org__org_type=OrganizationType.COLLEGE.value,
verified=True,
user__wallet_user__isnull=False,
).aggregate(total_karma=Sum("user__wallet_user__karma"))["total_karma"]
or 0
)

def get_rank(self, obj):
org_karma_dict = (
UserOrganizationLink.objects.filter(org__org_type=OrganizationType.COLLEGE.value)
UserOrganizationLink.objects.filter(
org__org_type=OrganizationType.COLLEGE.value)
.values("org")
.annotate(total_karma=Sum("user__wallet_user__karma"))
).order_by("-total_karma", "org__created_at")
Expand All @@ -110,7 +111,7 @@ def get_rank(self, obj):

class CampusStudentDetailsSerializer(serializers.Serializer):
user_id = serializers.CharField()
fullname = serializers.SerializerMethodField()
full_name = serializers.SerializerMethodField()
muid = serializers.CharField()
karma = serializers.IntegerField()
rank = serializers.SerializerMethodField()
Expand All @@ -125,15 +126,15 @@ class CampusStudentDetailsSerializer(serializers.Serializer):
is_alumni = serializers.BooleanField()

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

def get_rank(self, obj):
ranks = self.context.get("ranks")
return ranks.get(obj.id, None)

def get_fullname(self, obj):
return obj.fullname
def get_full_name(self, obj):
return obj.full_name


class WeeklyKarmaSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -179,12 +180,13 @@ def update(self, instance, validated_data):

class ListAluminiSerializer(serializers.Serializer):
user_id = serializers.CharField()
fullname = serializers.SerializerMethodField()
full_name = serializers.SerializerMethodField()
muid = serializers.CharField()
karma = serializers.IntegerField()
rank = serializers.SerializerMethodField()
level = serializers.CharField()
join_date = serializers.CharField()

class Meta:
fields = ("user_id", "fullname", "karma", "muid", "rank", "level", "join_date")
fields = ("user_id", "full_name", "karma",
"muid", "rank", "level", "join_date")
7 changes: 4 additions & 3 deletions api/dashboard/channels/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


class ChannelListSerializer(serializers.ModelSerializer):
created_by = serializers.CharField(source="created_by.fullname")
updated_by = serializers.CharField(source="updated_by.fullname")
created_by = serializers.CharField(source="created_by.full_name")
updated_by = serializers.CharField(source="updated_by.full_name")

class Meta:
model = Channel
Expand All @@ -33,7 +33,8 @@ def update(self, instance, validated_data):
user_id = self.context.get("user_id")

instance.name = validated_data.get("name", instance.name)
instance.discord_id = validated_data.get("discord_id", instance.discord_id)
instance.discord_id = validated_data.get(
"discord_id", instance.discord_id)
instance.updated_by_id = user_id
instance.updated_at = DateTimeUtils.get_current_utc_time()
instance.save()
Expand Down
17 changes: 11 additions & 6 deletions api/dashboard/discord_moderator/discord_mod_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,16 @@ def get(self, request):
tasks = KarmaActivityLog.objects.filter(created_at=date)
peerpending = tasks.filter(peer_approved=False).count()
appraiserpending = tasks.filter(appraiser_approved=False).count()
data = {'peer_pending': peerpending, 'appraise_pending': appraiserpending}
data = {'peer_pending': peerpending,
'appraise_pending': appraiserpending}
return CustomResponse(response=data).get_success_response()

peerpending = KarmaActivityLog.objects.filter(peer_approved=False).count()
appraiserpending = KarmaActivityLog.objects.filter(appraiser_approved=False).count()
data = {'peer_pending': peerpending, 'appraise_pending': appraiserpending}
peerpending = KarmaActivityLog.objects.filter(
peer_approved=False).count()
appraiserpending = KarmaActivityLog.objects.filter(
appraiser_approved=False).count()
data = {'peer_pending': peerpending,
'appraise_pending': appraiserpending}
return CustomResponse(response=data).get_success_response()


Expand All @@ -44,13 +48,14 @@ def get(self, request):

approval_field = f"{choice}_approved_by"
logs_with_approval = KarmaActivityLog.objects.filter(
Q(**{f"{approval_field}__isnull": False}) & ~Q(**{approval_field: ''})
Q(**{f"{approval_field}__isnull": False}
) & ~Q(**{approval_field: ''})
)

data = defaultdict(lambda: {"count": 0, "muid": None})

for obj in logs_with_approval:
approver_name = getattr(obj, approval_field).fullname
approver_name = getattr(obj, approval_field).full_name
if data[approver_name]["muid"] is None:
data[approver_name]["muid"] = getattr(obj, approval_field).muid
data[approver_name]["count"] += 1
Expand Down
16 changes: 8 additions & 8 deletions api/dashboard/discord_moderator/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@
from db.task import KarmaActivityLog
from db.user import User


class KarmaActivityLogSerializer(serializers.ModelSerializer):
fullname = serializers.CharField(source = 'user.fullname')
task_name = serializers.CharField(source = 'task.title')
full_name = serializers.CharField(source='user.full_name')
task_name = serializers.CharField(source='task.title')
status = serializers.SerializerMethodField()
discordlink = serializers.CharField(source = 'task.discord_link')
discordlink = serializers.CharField(source='task.discord_link')

class Meta:
model = KarmaActivityLog
fields = ['id', 'fullname', 'task_name', 'status', 'discordlink']
fields = ['id', 'full_name', 'task_name', 'status', 'discordlink']

def get_status(self,obj):
def get_status(self, obj):
if obj.peer_approved == True and obj.appraiser_approved == True:
return "Karma Awarded"
elif obj.peer_approved== True:
elif obj.peer_approved == True:
return "Peer Approved"
elif obj.appraiser_approved == True:
return "Appraiser Approved"
else:
return "Pending"


15 changes: 8 additions & 7 deletions api/dashboard/district/dash_district_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class Meta:

def get_rank(self, obj):
org_karma_dict = (
UserOrganizationLink.objects.filter(org__org_type=OrganizationType.COLLEGE.value)
UserOrganizationLink.objects.filter(
org__org_type=OrganizationType.COLLEGE.value)
.values("org__district")
.annotate(total_karma=Sum("user__wallet_user__karma"))
).order_by("-total_karma", "org__created_at")
Expand All @@ -60,7 +61,7 @@ def get_district_lead(self, obj):
org__district=obj.org.district,
user__user_role_link_user__role__title=RoleType.DISTRICT_CAMPUS_LEAD.value,
).first()
return user_org_link.user.fullname if user_org_link else None
return user_org_link.user.full_name if user_org_link else None

def get_karma(self, obj):
return UserOrganizationLink.objects.filter(
Expand Down Expand Up @@ -128,7 +129,7 @@ def get_students_count(self, obj):

class DistrictStudentDetailsSerializer(serializers.Serializer):
user_id = serializers.CharField()
fullname = serializers.SerializerMethodField()
full_name = serializers.SerializerMethodField()
muid = serializers.CharField()
karma = serializers.IntegerField()
rank = serializers.SerializerMethodField()
Expand All @@ -137,7 +138,7 @@ class DistrictStudentDetailsSerializer(serializers.Serializer):
class Meta:
fields = (
"user_id"
"fullname",
"full_name",
"karma",
"muid",
"rank",
Expand All @@ -148,8 +149,8 @@ def get_rank(self, obj):
ranks = self.context.get("ranks")
return ranks.get(obj.id, None)

def get_fullname(self, obj):
return obj.fullname
def get_full_name(self, obj):
return obj.full_name


class DistrictCollegeDetailsSerializer(serializers.Serializer):
Expand All @@ -173,7 +174,7 @@ class Meta:
def get_lead(self, obj):
leads = self.context.get("leads")
college_lead = [lead for lead in leads if lead.college == obj["id"]]
return college_lead[0].fullname if college_lead else None
return college_lead[0].full_name if college_lead else None

def get_lead_number(self, obj):
leads = self.context.get("leads")
Expand Down
7 changes: 4 additions & 3 deletions api/dashboard/events/events_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@


class EventsListSerializer(serializers.ModelSerializer):
created_by = serializers.CharField(source="created_by.fullname")
updated_by = serializers.CharField(source="updated_by.fullname")
created_by = serializers.CharField(source="created_by.full_name")
updated_by = serializers.CharField(source="updated_by.full_name")

class Meta:
model = Events
Expand All @@ -30,7 +30,8 @@ def update(self, instance, validated_data):
user_id = self.context.get("user_id")

instance.name = validated_data.get("name", instance.name)
instance.description = validated_data.get("description", instance.description)
instance.description = validated_data.get(
"description", instance.description)
instance.updated_by_id = user_id
instance.updated_at = DateTimeUtils.get_current_utc_time()
instance.save()
Expand Down
4 changes: 2 additions & 2 deletions api/dashboard/ig/dash_ig_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

class InterestGroupSerializer(serializers.ModelSerializer):

updated_by = serializers.CharField(source='updated_by.fullname')
created_by = serializers.CharField(source='created_by.fullname')
updated_by = serializers.CharField(source='updated_by.full_name')
created_by = serializers.CharField(source='created_by.full_name')
members = serializers.SerializerMethodField()

class Meta:
Expand Down
Loading

0 comments on commit 2b3f3b3

Please sign in to comment.