Skip to content

Commit

Permalink
Merge pull request #1351 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
[PATCH] User EDIT dashboard
  • Loading branch information
MZaFaRM authored Oct 17, 2023
2 parents 4417a30 + b8d7049 commit cd6c06c
Showing 1 changed file with 16 additions and 34 deletions.
50 changes: 16 additions & 34 deletions api/dashboard/user/dash_user_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,16 @@ def get_roles(self, obj):


class CollegeSerializer(serializers.ModelSerializer):
title = serializers.CharField(source="org.title", allow_null=True)
org_type = serializers.CharField(source="org.org_type")
department = serializers.CharField(source="department.title")
country = serializers.CharField(source="country.name")
state = serializers.CharField(source="state.name")
district = serializers.CharField(source="district.name")
department = serializers.CharField(source="department.pk")
country = serializers.CharField(source="country.pk")
state = serializers.CharField(source="state.pk")
district = serializers.CharField(source="district.pk")

class Meta:
model = UserOrganizationLink
fields = [
"title",
"org",
"org_type",
"department",
"graduation_year",
Expand All @@ -80,33 +79,25 @@ class Meta:
]


class CommunitySerializer(serializers.ModelSerializer):
title = serializers.CharField(source="org.title", read_only=True)
class OrgSerializer(serializers.ModelSerializer):
org_type = serializers.CharField(source="org.org_type", read_only=True)

class Meta:
model = UserOrganizationLink
fields = ["title", "org_type"]


class CompanySerializer(serializers.ModelSerializer):
title = serializers.CharField(source="org.title", read_only=True)
org_type = serializers.CharField(source="org.org_type", read_only=True)

class Meta:
model = UserOrganizationLink
fields = ["title", "org_type"]
fields = ["org", "org_type"]


class UserDetailsSerializer(serializers.ModelSerializer):
user_id = serializers.CharField(source="id")
organizations = serializers.SerializerMethodField(read_only=True)
interest_groups = serializers.SerializerMethodField(read_only=True)

igs = serializers.ListField(write_only=True)
role = serializers.SerializerMethodField(read_only=True)
department = serializers.CharField(write_only=True)
graduation_year = serializers.CharField(write_only=True)

organizations = serializers.SerializerMethodField(read_only=True)
interest_groups = serializers.SerializerMethodField(read_only=True)
role = serializers.SerializerMethodField(read_only=True)

class Meta:
model = User
fields = [
Expand All @@ -125,7 +116,7 @@ class Meta:
"interest_groups",
"igs",
]

def validate(self, data):
if "id" not in data:
raise serializers.ValidationError("User id is a required field")
Expand Down Expand Up @@ -193,26 +184,17 @@ def get_organizations(self, user):
for link in organization_links:
if link.org.org_type == OrganizationType.COLLEGE.value:
serializer = CollegeSerializer(link)
elif link.org.org_type == OrganizationType.COMPANY.value:
serializer = CompanySerializer(link)
else:
serializer = CommunitySerializer(link)
serializer = OrgSerializer(link)

organizations_data.append(serializer.data)
return organizations_data

def get_interest_groups(self, user):
igs = user.user_ig_link_user.all()
if igs:
igs = [ig.ig.name for ig in igs]
return igs
return user.user_ig_link_user.all().values_list("ig", flat=True)

def get_role(self, user):
if roles := UserRoleLink.objects.filter(user=user).values_list(
"role__title", flat=True
):
return list(roles)
return None
return user.user_role_link_user.all().values_list("role", flat=True)


class UserVerificationSerializer(serializers.ModelSerializer):
Expand Down

0 comments on commit cd6c06c

Please sign in to comment.