From 4df0af8c36519f1188cc0b675c1097c5cfbbc578 Mon Sep 17 00:00:00 2001 From: Sushil Tiwari Date: Fri, 22 Nov 2024 13:54:29 +0545 Subject: [PATCH] Add organization type api and enum for learning type --- per/admin.py | 3 ++- per/drf_views.py | 26 ++++++++++++++++++++++++++ per/enums.py | 1 + per/serializers.py | 10 ++++++++++ 4 files changed, 39 insertions(+), 1 deletion(-) diff --git a/per/admin.py b/per/admin.py index a0c63d8b2..c19612c73 100644 --- a/per/admin.py +++ b/per/admin.py @@ -188,7 +188,7 @@ class OpsLearningAdmin(GotoNextModelAdmin): ls = ("organization", "organization_validated", "sector", "sector_validated", "per_component", "per_component_validated") list_filter = ("is_validated", "appeal_code__atype") + ls autocomplete_fields = ("appeal_code",) + ls - search_fields = ("learning", "learning_validated") + search_fields = ("learning", "learning_validated", "appeal_code__aid", "appeal_code__code") list_display = ("learning", "appeal_code", "is_validated", "modified_at") change_form_template = "admin/opslearning_change_form.html" actions = ["export_selected_records"] @@ -311,6 +311,7 @@ class OpsLearningCacheResponseAdmin(TranslationAdmin): search_fields = ( "id", "used_ops_learning__appeal_code__aid", + "used_ops_learning__appeal_code__code", ) list_display = ( "__str__", diff --git a/per/drf_views.py b/per/drf_views.py index 71973269b..4a3d284e9 100644 --- a/per/drf_views.py +++ b/per/drf_views.py @@ -17,6 +17,7 @@ from rest_framework.authentication import TokenAuthentication from rest_framework.decorators import action from rest_framework.permissions import IsAuthenticated +from rest_framework.response import Response from rest_framework.settings import api_settings from api.models import Country @@ -79,6 +80,7 @@ NiceDocumentSerializer, OpsLearningCSVSerializer, OpsLearningInSerializer, + OpsLearningOrganizationTypeSerializer, OpsLearningSerializer, OpsLearningSummarySerializer, PerAssessmentSerializer, @@ -866,6 +868,30 @@ def get_renderer_context(self): return context + @extend_schema( + request=None, + filters=False, + responses=OpsLearningOrganizationTypeSerializer(many=True), + ) + @action( + detail=False, + methods=["GET"], + permission_classes=[DenyGuestUserMutationPermission, OpsLearningPermission], + serializer_class=OpsLearningOrganizationTypeSerializer, + url_path="organization-type", + ) + def organization(self, request): + """ + Get the Organization Types + """ + queryset = OrganizationTypes.objects.exclude(is_deprecated=True) + serializer = OpsLearningOrganizationTypeSerializer(queryset, many=True) + page = self.paginate_queryset(queryset) + if page is not None: + serializer = OpsLearningOrganizationTypeSerializer(page, many=True) + return self.get_paginated_response(serializer.data) + return Response(serializer.data) + @extend_schema( request=None, filters=True, diff --git a/per/enums.py b/per/enums.py index 92cece111..608d6930f 100644 --- a/per/enums.py +++ b/per/enums.py @@ -6,4 +6,5 @@ "overviewassessmentmethods": models.Overview.AssessmentMethod, "component_status": models.FormComponent.FormComponentStatus, "supported_by_organization_type": models.PerWorkPlanComponent.SupportedByOrganizationType, + "learning_type": models.LearningType, } diff --git a/per/serializers.py b/per/serializers.py index f5d27e907..b2e699e15 100644 --- a/per/serializers.py +++ b/per/serializers.py @@ -42,6 +42,7 @@ OpsLearningCacheResponse, OpsLearningComponentCacheResponse, OpsLearningSectorCacheResponse, + OrganizationTypes, Overview, PerAssessment, PerComponentRating, @@ -1243,3 +1244,12 @@ def get_latest_appeal_date(self, obj): return Appeal.objects.filter(id__in=obj.used_ops_learning.values("appeal_code__id")).aggregate( max_start_date=models.Max("start_date"), )["max_start_date"] + + +class OpsLearningOrganizationTypeSerializer(serializers.ModelSerializer): + class Meta: + model = OrganizationTypes + fields = [ + "id", + "title", + ]