diff --git a/api/common/common_views.py b/api/common/common_views.py index 03e4d17f..808b8f4d 100644 --- a/api/common/common_views.py +++ b/api/common/common_views.py @@ -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 @@ -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() diff --git a/api/common/urls.py b/api/common/urls.py index 0a695775..808741fd 100644 --- a/api/common/urls.py +++ b/api/common/urls.py @@ -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()) ] diff --git a/api/dashboard/organisation/serializers.py b/api/dashboard/organisation/serializers.py index 42878868..5d584922 100644 --- a/api/dashboard/organisation/serializers.py +++ b/api/dashboard/organisation/serializers.py @@ -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): @@ -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"] @@ -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 @@ -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