Skip to content

Commit

Permalink
Merge pull request #1425 from gtech-mulearn/dev-server
Browse files Browse the repository at this point in the history
org fix
  • Loading branch information
adnankattekaden authored Oct 24, 2023
2 parents 3907f52 + 1314404 commit 6eba624
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 48 deletions.
41 changes: 24 additions & 17 deletions api/dashboard/organisation/organisation_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
56 changes: 28 additions & 28 deletions api/dashboard/organisation/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 3 additions & 3 deletions api/dashboard/organisation/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
path('institutes/create/', organisation_views.InstitutionPostUpdateDeleteAPI.as_view()),
path('institutes/edit/<str:org_code>/', organisation_views.InstitutionPostUpdateDeleteAPI.as_view()),
path('institutes/delete/<str:org_code>/', organisation_views.InstitutionPostUpdateDeleteAPI.as_view()),
path('institutes/<str:org_type>/', organisation_views.InstitutionAPI.as_view()),
# path('institutes/<str:org_type>/', organisation_views.InstitutionAPI.as_view()),
path('institutes/<str:org_type>/csv/', organisation_views.InstitutionCSVAPI.as_view()),
path('institutes/info/<str:org_code>/', organisation_views.InstitutionDetailsAPI.as_view()),
path('institutes/show/<str:org_type>/', organisation_views.GetInstitutionsAPI.as_view()),
path('institutes/show/<str:org_type>/<str:district_id>/', organisation_views.GetInstitutionsAPI.as_view()),
path('institutes/<str:org_type>/', organisation_views.InstitutionAPI.as_view()),
path('institutes/<str:org_type>/<str:district_id>/', 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/<str:affiliation_id>/', organisation_views.AffiliationGetPostUpdateDeleteAPI.as_view()),
Expand Down

0 comments on commit 6eba624

Please sign in to comment.