Skip to content

Commit

Permalink
Merge pull request #1415 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
sandshore
  • Loading branch information
adnankattekaden authored Oct 24, 2023
2 parents eff4737 + 70214f3 commit af349b3
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 15 deletions.
35 changes: 35 additions & 0 deletions api/common/common_views.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import json

import requests
from django.db.models import Sum, F, Case, When, Value, CharField, Count, Q
from django.db.models.functions import Coalesce
from rest_framework.views import APIView
Expand Down Expand Up @@ -158,3 +161,35 @@ def get(self, request):
'learning_circle_count': learning_circles_count
}
return CustomResponse(response=data).get_success_response()


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
with open('response.json', 'w') as json_file:
json.dump(response.json(), json_file)

with open('response.json', 'r') as file:
data = json.load(file)
else:
with open('response.json', 'r') as file:
data = json.load(file)

# 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()

# Check if the cleaned name already exists in the grouped_colleges dictionary
if cleaned_college in grouped_colleges:
# If it exists, add the count to the existing entry
grouped_colleges[cleaned_college] += int(count)
else:
# If it doesn't exist, create a new entry
grouped_colleges[cleaned_college] = int(count)
return CustomResponse(response=grouped_colleges).get_success_response()
1 change: 1 addition & 0 deletions api/common/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
path('college-wise-lc-report/', common_views.CollegeWiseLcReport.as_view()),
path('download/lc-report/', common_views.LcReportDownloadAPI.as_view()),
path('global-count/', common_views.GlobalCountAPI.as_view()),
path('gta-sandshore/',common_views.GTASANDSHOREAPI.as_view())
]
62 changes: 47 additions & 15 deletions api/dashboard/organisation/serializers.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,44 @@
import uuid

from django.db.models import Sum, Count
from django.db.models import Count
from rest_framework import serializers

from db.organization import Organization, District, Zone, State, OrgAffiliation, Department
from utils.permission import JWTUtils
from utils.types import OrganizationType
from utils.utils import DateTimeUtils

from rest_framework import serializers
class InstitutionSerializer(serializers.ModelSerializer):
affiliation = serializers.ReadOnlyField(source="affiliation.title")
district = serializers.ReadOnlyField(source="district.name")
zone = serializers.ReadOnlyField(source="district.zone.name")
state = serializers.ReadOnlyField(source="district.zone.state.name")
country = serializers.ReadOnlyField(source="district.zone.state.country.name")
user_count = serializers.SerializerMethodField()

class Meta:
model = Organization
fields = [
"id",
"title",
"code",
"affiliation",
"district",
"zone",
"state",
"country",
"user_count"
]

def get_user_count(self, obj):
return obj.user_organization_link_org.annotate(
user_count=Count(
'user'
)
).count()




from db.organization import (
Organization,
District,
Zone,
State,
OrgAffiliation,
Department,
)


class InstitutionSerializer(serializers.ModelSerializer):
Expand Down Expand Up @@ -75,6 +98,8 @@ class Meta:


class InstitutionCreateUpdateSerializer(serializers.ModelSerializer):
district = serializers.CharField(required=False)

class Meta:
model = Organization
fields = ["title", "code", "org_type", "affiliation", "district"]
Expand Down Expand Up @@ -112,8 +137,8 @@ def validate_affiliation(self, affiliation_id):


class AffiliationSerializer(serializers.ModelSerializer):
label = serializers.ReadOnlyField(source="title")
value = serializers.ReadOnlyField(source="id")
label = serializers.ReadOnlyField(source='title')
value = serializers.ReadOnlyField(source='id')

class Meta:
model = OrgAffiliation
Expand Down Expand Up @@ -141,8 +166,15 @@ def update(self, instance, validated_data):
return instance

def validate_title(self, title):
if OrgAffiliation.objects.filter(title=title).first():
raise serializers.ValidationError("Affiliation already exist")
org_affiliation = OrgAffiliation.objects.filter(
title=title
).first()

if org_affiliation:
raise serializers.ValidationError(
"Affiliation already exist"
)

return title


Expand Down

0 comments on commit af349b3

Please sign in to comment.