Skip to content

Commit 4df0af8

Browse files
committed
Add organization type api and enum for learning type
1 parent 8c668ca commit 4df0af8

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

per/admin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ class OpsLearningAdmin(GotoNextModelAdmin):
188188
ls = ("organization", "organization_validated", "sector", "sector_validated", "per_component", "per_component_validated")
189189
list_filter = ("is_validated", "appeal_code__atype") + ls
190190
autocomplete_fields = ("appeal_code",) + ls
191-
search_fields = ("learning", "learning_validated")
191+
search_fields = ("learning", "learning_validated", "appeal_code__aid", "appeal_code__code")
192192
list_display = ("learning", "appeal_code", "is_validated", "modified_at")
193193
change_form_template = "admin/opslearning_change_form.html"
194194
actions = ["export_selected_records"]
@@ -311,6 +311,7 @@ class OpsLearningCacheResponseAdmin(TranslationAdmin):
311311
search_fields = (
312312
"id",
313313
"used_ops_learning__appeal_code__aid",
314+
"used_ops_learning__appeal_code__code",
314315
)
315316
list_display = (
316317
"__str__",

per/drf_views.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from rest_framework.authentication import TokenAuthentication
1818
from rest_framework.decorators import action
1919
from rest_framework.permissions import IsAuthenticated
20+
from rest_framework.response import Response
2021
from rest_framework.settings import api_settings
2122

2223
from api.models import Country
@@ -79,6 +80,7 @@
7980
NiceDocumentSerializer,
8081
OpsLearningCSVSerializer,
8182
OpsLearningInSerializer,
83+
OpsLearningOrganizationTypeSerializer,
8284
OpsLearningSerializer,
8385
OpsLearningSummarySerializer,
8486
PerAssessmentSerializer,
@@ -866,6 +868,30 @@ def get_renderer_context(self):
866868

867869
return context
868870

871+
@extend_schema(
872+
request=None,
873+
filters=False,
874+
responses=OpsLearningOrganizationTypeSerializer(many=True),
875+
)
876+
@action(
877+
detail=False,
878+
methods=["GET"],
879+
permission_classes=[DenyGuestUserMutationPermission, OpsLearningPermission],
880+
serializer_class=OpsLearningOrganizationTypeSerializer,
881+
url_path="organization-type",
882+
)
883+
def organization(self, request):
884+
"""
885+
Get the Organization Types
886+
"""
887+
queryset = OrganizationTypes.objects.exclude(is_deprecated=True)
888+
serializer = OpsLearningOrganizationTypeSerializer(queryset, many=True)
889+
page = self.paginate_queryset(queryset)
890+
if page is not None:
891+
serializer = OpsLearningOrganizationTypeSerializer(page, many=True)
892+
return self.get_paginated_response(serializer.data)
893+
return Response(serializer.data)
894+
869895
@extend_schema(
870896
request=None,
871897
filters=True,

per/enums.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@
66
"overviewassessmentmethods": models.Overview.AssessmentMethod,
77
"component_status": models.FormComponent.FormComponentStatus,
88
"supported_by_organization_type": models.PerWorkPlanComponent.SupportedByOrganizationType,
9+
"learning_type": models.LearningType,
910
}

per/serializers.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
OpsLearningCacheResponse,
4343
OpsLearningComponentCacheResponse,
4444
OpsLearningSectorCacheResponse,
45+
OrganizationTypes,
4546
Overview,
4647
PerAssessment,
4748
PerComponentRating,
@@ -1243,3 +1244,12 @@ def get_latest_appeal_date(self, obj):
12431244
return Appeal.objects.filter(id__in=obj.used_ops_learning.values("appeal_code__id")).aggregate(
12441245
max_start_date=models.Max("start_date"),
12451246
)["max_start_date"]
1247+
1248+
1249+
class OpsLearningOrganizationTypeSerializer(serializers.ModelSerializer):
1250+
class Meta:
1251+
model = OrganizationTypes
1252+
fields = [
1253+
"id",
1254+
"title",
1255+
]

0 commit comments

Comments
 (0)