Skip to content

Commit a32239a

Browse files
committed
feat(eap): add eap options endpoint
1 parent d619f08 commit a32239a

5 files changed

Lines changed: 51 additions & 23 deletions

File tree

eap/enums.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
"eap_status": models.EAPStatus,
55
"eap_type": models.EAPType,
66
"sector": models.PlannedOperation.Sector,
7-
"sector_apcode": models.PlannedOperation.APCode,
87
"timeframe": models.TimeFrame,
98
"years_timeframe_value": models.YearsTimeFrameChoices,
109
"months_timeframe_value": models.MonthsTimeFrameChoices,
1110
"days_timeframe_value": models.DaysTimeFrameChoices,
1211
"hours_timeframe_value": models.HoursTimeFrameChoices,
1312
"approach": models.EnablingApproach.Approach,
14-
"approach_apcode": models.EnablingApproach.APCode,
1513
}

eap/models.py

Lines changed: 30 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -391,19 +391,21 @@ class Sector(models.IntegerChoices):
391391
ENVIRONMENT_SUSTAINABILITY = 111, _("Environment Sustainability")
392392
COMMUNITY_ENGAGEMENT_AND_ACCOUNTABILITY = 112, _("Community Engagement And Accountability")
393393

394-
# NOTE: Use integer values directly in APCode rather than referencing `Sector` directly
395-
class APCode(models.IntegerChoices):
396-
SHELTER_SETTLEMENT_AND_HOUSING = 101, _("AP101, AP103, AP104")
397-
LIVELIHOODS = 102, _("AP007")
398-
PROTECTION_GENDER_AND_INCLUSION = 103, _("AP114, AP116, AP117")
399-
HEALTH_AND_CARE = 104, _("AP107, AP108, AP109")
400-
RISK_REDUCTION_CLIMATE_ADAPTATION_AND_RECOVERY = 105, _("AP101, AP103, AP104, AP105, AP106")
401-
MULTIPURPOSE_CASH = 106, _("AP081")
402-
WATER_SANITATION_AND_HYGIENE = 107, _("AP110, AP111")
403-
EDUCATION = 109, _("AP115")
404-
MIGRATION = 110, _("AP112, AP113")
405-
ENVIRONMENT_SUSTAINABILITY = 111, _("AP102")
406-
COMMUNITY_ENGAGEMENT_AND_ACCOUNTABILITY = 112, _("AP129")
394+
@classmethod
395+
def get_sector_ap_codes(cls) -> dict[int, list[str]]:
396+
return {
397+
cls.SHELTER_SETTLEMENT_AND_HOUSING: ["AP101", "AP103", "AP104"],
398+
cls.LIVELIHOODS: ["AP007"],
399+
cls.PROTECTION_GENDER_AND_INCLUSION: ["AP114", "AP116", "AP117"],
400+
cls.HEALTH_AND_CARE: ["AP107", "AP108", "AP109"],
401+
cls.RISK_REDUCTION_CLIMATE_ADAPTATION_AND_RECOVERY: ["AP101", "AP103", "AP104", "AP105", "AP106"],
402+
cls.MULTIPURPOSE_CASH: ["AP081"],
403+
cls.WATER_SANITATION_AND_HYGIENE: ["AP110", "AP111"],
404+
cls.EDUCATION: ["AP115"],
405+
cls.MIGRATION: ["AP112", "AP113"],
406+
cls.ENVIRONMENT_SUSTAINABILITY: ["AP102"],
407+
cls.COMMUNITY_ENGAGEMENT_AND_ACCOUNTABILITY: ["AP129"],
408+
}
407409

408410
sector = models.IntegerField(choices=Sector.choices, verbose_name=_("sector"))
409411
people_targeted = models.IntegerField(verbose_name=_("People Targeted"))
@@ -451,14 +453,21 @@ class Approach(models.IntegerChoices):
451453
NATIONAL_SOCIETY_STRENGTHENING = 20, _("National Society Strengthening")
452454
PARTNERSHIP_AND_COORDINATION = 30, _("Partnership And Coordination")
453455

454-
# NOTE: AP Codes are read only in EAP forms and passed through ENUMS for now.
455-
# They are not stored in the database but are derived from the Approach field. Make sure to keep them in sync.
456-
class APCode(models.IntegerChoices):
457-
SECRETARIAT_SERVICES = 10, _("AP122")
458-
NATIONAL_SOCIETY_STRENGTHENING = 20, _("AP124, AP125, AP126")
459-
PARTNERSHIP_AND_COORDINATION = 30, _(
460-
"AP049, AP118, AP119, AP120, AP121, AP127, AP128"
461-
)
456+
@classmethod
457+
def get_approach_ap_codes(cls) -> dict[int, list[str]]:
458+
return {
459+
cls.SECRETARIAT_SERVICES: ["AP122"],
460+
cls.NATIONAL_SOCIETY_STRENGTHENING: ["AP124", "AP125", "AP126"],
461+
cls.PARTNERSHIP_AND_COORDINATION: [
462+
"AP049",
463+
"AP118",
464+
"AP119",
465+
"AP120",
466+
"AP121",
467+
"AP127",
468+
"AP128",
469+
],
470+
}
462471

463472
approach = models.IntegerField(choices=Approach.choices, verbose_name=_("Approach"))
464473
budget_per_approach = models.IntegerField(verbose_name=_("Budget per approach (CHF)"))

eap/serializers.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1196,3 +1196,8 @@ def update(self, instance: EAPRegistration, validated_data: dict[str, typing.Any
11961196
transaction.on_commit(lambda: send_approved_email.delay(eap_registration_id))
11971197

11981198
return updated_instance
1199+
1200+
1201+
class EAPOptionsSerializer(serializers.Serializer):
1202+
sector_ap_codes = serializers.DictField(child=serializers.ListField(child=serializers.CharField()))
1203+
approach_ap_codes = serializers.DictField(child=serializers.ListField(child=serializers.CharField()))

eap/views.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from drf_spectacular.utils import OpenApiParameter, extend_schema
66
from rest_framework import mixins, permissions, response, status, viewsets
77
from rest_framework.decorators import action
8+
from rest_framework.generics import GenericAPIView
89

910
from eap.filter_set import (
1011
EAPRegistrationFilterSet,
@@ -32,6 +33,7 @@
3233
EAPFileInputSerializer,
3334
EAPFileSerializer,
3435
EAPGlobalFilesSerializer,
36+
EAPOptionsSerializer,
3537
EAPRegistrationSerializer,
3638
EAPShareUserSerializer,
3739
EAPStatusSerializer,
@@ -512,3 +514,15 @@ def retrieve(self, request, *args, **kwargs):
512514
)
513515
serializer = EAPGlobalFilesSerializer({"url": request.build_absolute_uri(static(self.template_map[template_type]))})
514516
return response.Response(serializer.data)
517+
518+
519+
class EAPOptionsView(GenericAPIView):
520+
permission_classes = [permissions.IsAuthenticated, DenyGuestUserPermission]
521+
serializer_class = EAPOptionsSerializer
522+
523+
def get(self, request, *args, **kwargs):
524+
data = {
525+
"sector_ap_codes": PlannedOperation.Sector.get_sector_ap_codes(),
526+
"approach_ap_codes": EnablingApproach.Approach.get_approach_ap_codes(),
527+
}
528+
return response.Response(self.get_serializer(data).data)

main/urls.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,8 @@
222222
url(r"^api/v2/brief", Brief.as_view()),
223223
url(r"^api/v2/erutype", ERUTypes.as_view()),
224224
url(r"^api/v2/export-eru-readiness", deployment_views.ExportERUReadinessView.as_view()),
225+
# EAP
226+
url(r"^api/v2/eap/options/", eap_views.EAPOptionsView.as_view()),
225227
url(r"^api/v2/recentaffected", RecentAffecteds.as_view()),
226228
url(r"^api/v2/fieldreportstatus", FieldReportStatuses.as_view()),
227229
url(r"^api/v2/primarysector", ProjectPrimarySectors.as_view()),

0 commit comments

Comments
 (0)