Skip to content

Commit

Permalink
Merge pull request #1485 from gtech-mulearn/dev
Browse files Browse the repository at this point in the history
fix org api
  • Loading branch information
adnankattekaden authored Oct 30, 2023
2 parents 09a9077 + 1aaa4f5 commit 659be76
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
45 changes: 31 additions & 14 deletions api/dashboard/organisation/organisation_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,13 +197,14 @@ class InstitutionCSVAPI(APIView):
@role_required([RoleType.ADMIN.value])
def get(self, request, org_type):
organizations = (
Organization.objects.filter(org_type=org_type)
.select_related(
Organization.objects.filter(
org_type=org_type
).select_related(
"affiliation",
"district__zone__state__country",
"district__zone__state",
"district__zone",
"district",
# "district__zone__state__country",
# "district__zone__state",
# "district__zone",
# "district",
)
.prefetch_related(
Prefetch(
Expand All @@ -215,9 +216,15 @@ def get(self, request, org_type):
)
)

serializer = InstitutionSerializer(organizations, many=True).data
serializer = InstitutionSerializer(
organizations,
many=True
).data

return CommonUtils.generate_csv(serializer, f"{org_type} data")
return CommonUtils.generate_csv(
serializer,
f"{org_type} data"
)


class InstitutionDetailsAPI(APIView):
Expand Down Expand Up @@ -276,18 +283,26 @@ def get(self, request, org_type, district_id=None):
class AffiliationGetPostUpdateDeleteAPI(APIView):
authentication_classes = [CustomizePermission]

@role_required([RoleType.ADMIN.value])
def get(self, request):
affiliation = OrgAffiliation.objects.all()
paginated_queryset = CommonUtils.get_paginated_queryset(
affiliation, request, ["id", "title"]
affiliation,
request,
[
"id",
"title"
]
)

serializer = AffiliationSerializer(
paginated_queryset.get("queryset"), many=True
paginated_queryset.get("queryset"),
many=True
)

return CustomResponse().paginated_response(
data=serializer.data, pagination=paginated_queryset.get("pagination")
data=serializer.data,
pagination=paginated_queryset.get(
"pagination"
)
)

@role_required([RoleType.ADMIN.value])
Expand All @@ -308,7 +323,9 @@ def post(self, request):
general_message=f"{request.data.get('title')} added successfully"
).get_success_response()

return CustomResponse(general_message=serializer.errors).get_failure_response()
return CustomResponse(
general_message=serializer.errors
).get_failure_response()

@role_required([RoleType.ADMIN.value])
def put(self, request, affiliation_id):
Expand Down
5 changes: 4 additions & 1 deletion api/dashboard/organisation/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,10 @@ class AffiliationSerializer(serializers.ModelSerializer):

class Meta:
model = OrgAffiliation
fields = ["value", "label"]
fields = [
"value",
"label"
]


class AffiliationCreateUpdateSerializer(serializers.ModelSerializer):
Expand Down
3 changes: 1 addition & 2 deletions api/dashboard/organisation/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,12 @@
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>/csv/', organisation_views.InstitutionCSVAPI.as_view()),
path('institutes/info/<str:org_code>/', organisation_views.InstitutionDetailsAPI.as_view()),
path('institutes/prefill/<str:org_code>/', organisation_views.InstitutionPrefillAPI.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/show/', 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()),
path('institutes/org/affiliation/delete/<str:affiliation_id>/', organisation_views.AffiliationGetPostUpdateDeleteAPI.as_view()),
Expand Down

0 comments on commit 659be76

Please sign in to comment.