diff --git a/api/dashboard/profile/profile_serializer.py b/api/dashboard/profile/profile_serializer.py index a83d5817..cadbbc2d 100644 --- a/api/dashboard/profile/profile_serializer.py +++ b/api/dashboard/profile/profile_serializer.py @@ -71,13 +71,11 @@ class Meta: ) def get_percentile(self, obj): - try: - user_count = Wallet.objects.filter( - karma__lt=obj.wallet_user.karma).count() - usr_count = User.objects.all().count() - return 0 if usr_count == 0 else (user_count * 100) / usr_count - except Exception as e: - return 0 + users_count_lt_user_karma = Wallet.objects.filter( + karma__lt=obj.wallet_user.karma + ).count() + user_count = User.objects.all().count() + return 0 if user_count == 0 else 100 - ((users_count_lt_user_karma * 100) / user_count) def get_roles(self, obj): return list({link.role.title for link in obj.user_role_link_user.filter(verified=True)}) diff --git a/api/register/serializers.py b/api/register/serializers.py index 0beb8e70..96b978a8 100644 --- a/api/register/serializers.py +++ b/api/register/serializers.py @@ -261,10 +261,13 @@ class UserSerializer(serializers.ModelSerializer): role = serializers.PrimaryKeyRelatedField( queryset=Role.objects.all(), required=False, write_only=True ) + area_of_interest = serializers.PrimaryKeyRelatedField( + queryset=InterestGroup.objects.all(), many=True, required=False + ) def create(self, validated_data): role = validated_data.pop("role", None) - + area_of_interest = validated_data.pop("area_of_interest", None) validated_data["muid"] = register_helper.generate_muid( validated_data["full_name"] @@ -294,6 +297,19 @@ def create(self, validated_data): **additional_values, ) + if area_of_interest: + UserIgLink.objects.bulk_create( + { + UserIgLink( + user=user, + ig=ig, + created_by=user, + created_at=DateTimeUtils.get_current_utc_time(), + ) + for ig in area_of_interest + } + ) + return user class Meta: @@ -306,7 +322,8 @@ class Meta: "dob", "gender", "role", - "district" + "district", + "area_of_interest", ] class RegisterSerializer(serializers.Serializer): diff --git a/utils/types.py b/utils/types.py index 08fe766f..36a424dd 100644 --- a/utils/types.py +++ b/utils/types.py @@ -41,8 +41,8 @@ class RoleType(Enum): SUSPEND = "Suspended" STUDENT = "Student" ENABLER = "Enabler" - IG_FACILITATOR = "IG Facilitator" TECH_TEAM = 'Tech Team' + IG_LEAD = 'IG Lead' CAMPUS_ACTIVATION_TEAM = "Campus Activation Team" LEAD_ENABLER = "Lead Enabler"