Skip to content

Commit

Permalink
Merge pull request #2237 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
Dev Server
  • Loading branch information
nashnsulthan authored Oct 7, 2024
2 parents 756fe2c + 5126aee commit eb7f607
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 31 deletions.
4 changes: 3 additions & 1 deletion api/dashboard/ig/dash_ig_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ class InterestGroupSerializer(serializers.ModelSerializer):
updated_by = serializers.CharField(source='updated_by.full_name')
created_by = serializers.CharField(source='created_by.full_name')
members = serializers.SerializerMethodField()

category = serializers.ChoiceField(choices=["maker", "software", "creative", "management", "others"])
class Meta:
model = InterestGroup
fields = [
"id",
"name",
"icon",
"code",
"category",
"members",
"updated_by",
"updated_at",
Expand All @@ -35,6 +36,7 @@ class Meta:
fields = [
"name",
"code",
"category",
"icon",
"created_by",
"updated_by"
Expand Down
63 changes: 33 additions & 30 deletions api/dashboard/profile/profile_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,21 @@ class Meta:
"percentile",
)

def _get_user_org_link(self, obj, org_type):
if not getattr(self, "user_org_link", None):
self.user_org_link = obj.user_organization_link_user.filter(
org__org_type=org_type
).first()
return self.user_org_link

def _get_org_type(self, obj):
roles = self.get_roles(obj)
return (
OrganizationType.COMPANY.value
if MainRoles.MENTOR.value in roles
else OrganizationType.COLLEGE.value
)

def get_percentile(self, obj):
users_count_lt_user_karma = Wallet.objects.filter(
karma__lt=obj.wallet_user.karma
Expand All @@ -96,45 +111,36 @@ def get_percentile(self, obj):
)

def get_roles(self, obj):
return list(
if "role_values" in self.context:
return self.context["role_values"]
role_values = list(
{link.role.title for link in obj.user_role_link_user.filter(verified=True)}
)
self.context["role_values"] = role_values
return role_values

def get_college_id(self, obj):
org_type = (
OrganizationType.COMPANY.value
if MainRoles.MENTOR.value in self.get_roles(obj)
else OrganizationType.COLLEGE.value
)
user_org_link = obj.user_organization_link_user.filter(
org__org_type=org_type
).first()
org_type = self._get_org_type(obj)
user_org_link = self._get_user_org_link(obj, org_type)
return user_org_link.org.id if user_org_link else None

def get_org_district_id(self, obj):
org_type = (
OrganizationType.COMPANY.value
if MainRoles.MENTOR.value in self.get_roles(obj)
else OrganizationType.COLLEGE.value
)
user_org_link = obj.user_organization_link_user.filter(
org__org_type=org_type
).first()
org_type = self._get_org_type(obj)
user_org_link = self._get_user_org_link(obj, org_type)
return (
user_org_link.org.district.id
if user_org_link and hasattr(user_org_link.org, "district")
else None
)

def get_college_code(self, obj):
if user_org_link := obj.user_organization_link_user.filter(
org__org_type=OrganizationType.COLLEGE.value
).first():
return user_org_link.org.code
org_type = self._get_org_type(obj)
if org_type == OrganizationType.COLLEGE.value:
user_org_link = self._get_user_org_link(obj, org_type)
return user_org_link.org.code if user_org_link else None
return None

def get_rank(self, obj):

roles = self.get_roles(obj)
user_karma = obj.wallet_user.karma
if RoleType.MENTOR.value in roles:
Expand Down Expand Up @@ -162,10 +168,8 @@ def get_rank(self, obj):
)
.order_by("-karma")
)

for count, _rank in enumerate(ranks, start=1):
if obj.id == _rank.user_id:
return count
ranks = list(ranks.values_list("user_id", flat=True))
return ranks.index(obj.id) + 1

def get_karma_distribution(self, obj):
return (
Expand Down Expand Up @@ -255,7 +259,7 @@ def get_role(self, obj):
return ["Learner"] if len(roles) == 0 else roles

def get_rank(self, obj):
roles = self.get_roles(obj)
roles = self.get_role(obj)
user_karma = obj.wallet_user.karma
if RoleType.MENTOR.value in roles:
ranks = Wallet.objects.filter(
Expand Down Expand Up @@ -283,9 +287,8 @@ def get_rank(self, obj):
.order_by("-karma")
)

for count, _rank in enumerate(ranks, start=1):
if obj.id == _rank.user_id:
return count
ranks = list(ranks.values_list("user_id", flat=True))
return ranks.index(obj.id) + 1

def get_karma(self, obj):
return total_karma.karma if (total_karma := obj.wallet_user) else None
Expand Down
1 change: 1 addition & 0 deletions db/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ class InterestGroup(models.Model):
name = models.CharField(max_length=75, unique=True)
code = models.CharField(max_length=10, unique=True)
icon = models.CharField(max_length=10)
category =models.CharField(max_length=20,default="others",blank=False,null=False)
updated_by = models.ForeignKey(User, on_delete=models.SET(settings.SYSTEM_ADMIN_ID), db_column="updated_by",
related_name="interest_group_updated_by")
updated_at = models.DateTimeField(auto_now=True)
Expand Down

0 comments on commit eb7f607

Please sign in to comment.