diff --git a/api/dashboard/organisation/organisation_views.py b/api/dashboard/organisation/organisation_views.py index 9b78ceab..e6225114 100644 --- a/api/dashboard/organisation/organisation_views.py +++ b/api/dashboard/organisation/organisation_views.py @@ -128,28 +128,35 @@ def delete(self, request, org_code): class InstitutionAPI(APIView): - def get(self, request, org_type): - organizations = ( - Organization.objects.filter(org_type=org_type) - .select_related( - "affiliation", - "district__zone__state__country", - "district__zone__state", - "district__zone", - "district", + def get(self, request, org_type, district_id=None): + + if district_id: + organisations = Organization.objects.filter( + org_type=org_type, + district_id=district_id ) - .prefetch_related( - Prefetch( - "user_organization_link_org", - queryset=UserOrganizationLink.objects.filter( - verified=True - ).select_related("user"), - ) + else: + organisations = Organization.objects.filter( + org_type=org_type + ) + + org_queryset = organisations.select_related( + "affiliation", + "district__zone__state__country", + "district__zone__state", + "district__zone", + "district", + ).prefetch_related( + Prefetch( + "user_organization_link_org", + queryset=UserOrganizationLink.objects.filter( + verified=True + ).select_related("user"), ) ) paginated_queryset = CommonUtils.get_paginated_queryset( - organizations, + org_queryset, request, [ "title", diff --git a/api/dashboard/organisation/serializers.py b/api/dashboard/organisation/serializers.py index 17015a05..da7adbf7 100644 --- a/api/dashboard/organisation/serializers.py +++ b/api/dashboard/organisation/serializers.py @@ -38,34 +38,34 @@ def get_user_count(self, obj): ).count() -class InstitutionSerializer(serializers.ModelSerializer): - affiliation = serializers.SlugRelatedField( - many=False, read_only=True, slug_field="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", - "org_type", - "district", - "zone", - "state", - "country", - "user_count", - ] - - def get_user_count(self, obj): - return len({link.user for link in obj.user_organization_link_org.all()}) +# class InstitutionSerializer(serializers.ModelSerializer): +# affiliation = serializers.SlugRelatedField( +# many=False, read_only=True, slug_field="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", +# "org_type", +# "district", +# "zone", +# "state", +# "country", +# "user_count", +# ] +# +# def get_user_count(self, obj): +# return len({link.user for link in obj.user_organization_link_org.all()}) class StateSerializer(serializers.ModelSerializer): diff --git a/api/dashboard/organisation/urls.py b/api/dashboard/organisation/urls.py index 0e9c83b6..541ccbec 100644 --- a/api/dashboard/organisation/urls.py +++ b/api/dashboard/organisation/urls.py @@ -7,11 +7,11 @@ path('institutes/create/', organisation_views.InstitutionPostUpdateDeleteAPI.as_view()), path('institutes/edit//', organisation_views.InstitutionPostUpdateDeleteAPI.as_view()), path('institutes/delete//', organisation_views.InstitutionPostUpdateDeleteAPI.as_view()), - path('institutes//', organisation_views.InstitutionAPI.as_view()), + # path('institutes//', organisation_views.InstitutionAPI.as_view()), path('institutes//csv/', organisation_views.InstitutionCSVAPI.as_view()), path('institutes/info//', organisation_views.InstitutionDetailsAPI.as_view()), - path('institutes/show//', organisation_views.GetInstitutionsAPI.as_view()), - path('institutes/show///', organisation_views.GetInstitutionsAPI.as_view()), + path('institutes//', organisation_views.InstitutionAPI.as_view()), + path('institutes///', organisation_views.InstitutionAPI.as_view()), path('institutes/org/affiliation/', organisation_views.AffiliationGetPostUpdateDeleteAPI.as_view()), path('institutes/org/affiliation/create/', organisation_views.AffiliationGetPostUpdateDeleteAPI.as_view()), path('institutes/org/affiliation/edit//', organisation_views.AffiliationGetPostUpdateDeleteAPI.as_view()),