Skip to content

Commit

Permalink
Merge pull request #1491 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
adnankattekaden authored Oct 31, 2023
2 parents 85ca6c3 + fbf677a commit bba1971
Show file tree
Hide file tree
Showing 5 changed files with 292 additions and 81 deletions.
2 changes: 0 additions & 2 deletions api/common/common_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,6 @@ def get(self, request):

class GTASANDSHOREAPI(APIView):
def get(self, request):

response = requests.get('https://devfolio.vez.social/rank')
if response.status_code == 200:
# Save JSON response to a local file
Expand All @@ -276,7 +275,6 @@ def get(self, request):

# Create a dictionary to store the grouped data
grouped_colleges = {}

for college, count in data.items():
# Clean the college name by removing spaces and converting to lowercase
cleaned_college = college.replace(" ", "").lower()
Expand Down
93 changes: 69 additions & 24 deletions api/dashboard/lc/dash_lc_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ class LearningCircleSerializer(serializers.ModelSerializer):
member_count = serializers.SerializerMethodField()

def get_member_count(self, obj):
return UserCircleLink.objects.filter(circle_id=obj.id, accepted=1).count()
return UserCircleLink.objects.filter(
circle_id=obj.id,
accepted=1
).count()

class Meta:
model = LearningCircle
Expand All @@ -39,12 +42,18 @@ class Meta:


class LearningCircleCreateSerializer(serializers.ModelSerializer):
ig = serializers.CharField(required=True, error_messages={
'required': 'ig field must not be left blank.'
})
name = serializers.CharField(required=True, error_messages={
'required': 'name field must not be left blank.'}
)
ig = serializers.CharField(
required=True,
error_messages={
'required': 'ig field must not be left blank.'
}
)
name = serializers.CharField(
required=True,
error_messages={
'required': 'name field must not be left blank.'
}
)

class Meta:
model = LearningCircle
Expand All @@ -57,25 +66,42 @@ def validate(self, data):
user_id = self.context.get('user_id')

ig_id = data.get('ig')
if not InterestGroup.objects.filter(id=ig_id).exists():
raise serializers.ValidationError("Invalid interest group")
if not InterestGroup.objects.filter(
id=ig_id
).exists():
raise serializers.ValidationError(
"Invalid interest group"
)

# org_link = UserOrganizationLink.objects.filter(user_id=user_id,
# org__org_type=OrganizationType.COLLEGE.value).first()
# if not org_link:
# raise serializers.ValidationError("User must be associated with a college organization")

if UserCircleLink.objects.filter(user_id=user_id, circle__ig_id=ig_id, accepted=True).exists():
raise serializers.ValidationError("Already a member of a learning circle with the same interest group")
if UserCircleLink.objects.filter(
user_id=user_id,
circle__ig_id=ig_id,
accepted=True
).exists():

raise serializers.ValidationError(
"Already a member of a learning circle with the same interest group"
)

return data

def create(self, validated_data):
user_id = self.context.get('user_id')
org_link = UserOrganizationLink.objects.filter(user_id=user_id,
org__org_type=OrganizationType.COLLEGE.value).first()
org_link = UserOrganizationLink.objects.filter(
user_id=user_id,
org__org_type=OrganizationType.COLLEGE.value
).first()

ig = InterestGroup.objects.filter(id=validated_data.get('ig')).first()
ig = InterestGroup.objects.filter(
id=validated_data.get(
'ig'
)
).first()

if org_link:
if len(org_link.org.code) > 4:
Expand Down Expand Up @@ -183,8 +209,8 @@ def get_is_lead(self, obj):
def get_total_karma(self, obj):
return (
KarmaActivityLog.objects.filter(
user__usercirclelink__circle=obj,
user__usercirclelink__accepted=True,
user__user_circle_link_user__circle=obj,
user__user_circle_link_user__accepted=True,
task__ig=obj.ig,
appraiser_approved=True,
).aggregate(
Expand Down Expand Up @@ -230,8 +256,8 @@ def _get_member_info(self, obj, accepted):

def get_rank(self, obj):
total_karma = KarmaActivityLog.objects.filter(
user__usercirclelink__circle=obj,
user__usercirclelink__accepted=True,
user__user_circle_link_user__circle=obj,
user__user_circle_link_user__accepted=True,
task__ig=obj.ig,
appraiser_approved=True
).aggregate(
Expand All @@ -250,8 +276,8 @@ def get_rank(self, obj):

for lc in all_learning_circles:
total_karma_lc = KarmaActivityLog.objects.filter(
user__usercirclelink__circle=lc,
user__usercirclelink__accepted=True,
user__user_circle_link_user__circle=lc,
user__user_circle_link_user__accepted=True,
task__ig=lc.ig,
appraiser_approved=True
).aggregate(
Expand Down Expand Up @@ -383,10 +409,23 @@ class LearningCircleMainSerializer(serializers.ModelSerializer):

class Meta:
model = LearningCircle
fields = ['name', 'ig_name', 'member_count', 'members', 'meet_place', 'meet_time', 'lead_name']
fields = [
'name',
'ig_name',
'member_count',
'members',
'meet_place',
'meet_time',
'lead_name'
]

def get_lead_name(self, obj):
user_circle_link = UserCircleLink.objects.filter(circle=obj, accepted=1, lead=True).first()
user_circle_link = UserCircleLink.objects.filter(
circle=obj,
accepted=1,
lead=True
).first()

if user_circle_link:
user = user_circle_link.user
return f'{user.first_name} {user.last_name}'
Expand All @@ -396,10 +435,16 @@ def get_ig_name(self, obj):
return obj.ig.name if obj.ig else None

def get_member_count(self, obj):
return UserCircleLink.objects.filter(circle=obj, accepted=1).count()
return UserCircleLink.objects.filter(
circle=obj,
accepted=1
).count()

def get_members(self, obj):
members = UserCircleLink.objects.filter(circle=obj, accepted=1)
members = UserCircleLink.objects.filter(
circle=obj,
accepted=1
)
return [
{
'username': f'{member.user.first_name} {member.user.last_name}'
Expand Down
Loading

0 comments on commit bba1971

Please sign in to comment.