Skip to content

Commit

Permalink
feat: cds added ApiCdsMorphList
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinaPiaImbrogno committed Dec 11, 2024
1 parent e0b9b71 commit 608c758
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
30 changes: 27 additions & 3 deletions cds/api/v1/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
DidatticaRegolamentoAltriDati,
DidatticaTestiAf,
DidatticaTestiRegolamento,
DidatticaCdsCollegamento,
)


Expand Down Expand Up @@ -426,7 +427,8 @@ def getContacts(cdscod):
years = [last_year, current_year]
query = (
DidatticaCopertura.objects.filter(
Q(personale__flg_cessato=0, personale__fl_docente=1) | ~Q(stato_coper_cod='R'),
Q(personale__flg_cessato=0, personale__fl_docente=1)
| ~Q(stato_coper_cod="R"),
cds_cod=cdscod,
aa_off_id__in=years,
)
Expand All @@ -446,6 +448,26 @@ def getContacts(cdscod):
).values("dip_url")
return query

@staticmethod
def getPreviousCdsCods(cds_cod):
cds = DidatticaCds.objects.filter(cds_cod=cds_cod).order_by("-cds_id").first()
if cds is None:
raise Http404

previous_cds_cod_list = []
current_cds = cds
while current_cds:
try:
collegamento = DidatticaCdsCollegamento.objects.get(cds=current_cds)
predecessor = collegamento.cds_prec
previous_cds_cod_list.append(predecessor.cds_cod)

current_cds = predecessor
except DidatticaCdsCollegamento.DoesNotExist:
break

return previous_cds_cod_list


class ServiceDidatticaAttivitaFormativa:
@staticmethod
Expand Down Expand Up @@ -624,8 +646,10 @@ def getAllActivities(
if teacher_code:
query_teacher_code = Q(personale_id__matricola__exact=teacher_code)

coperture = DidatticaCopertura.objects.filter(query_teacher_code).exclude(stato_coper_cod='R').values(
"af_id"
coperture = (
DidatticaCopertura.objects.filter(query_teacher_code)
.exclude(stato_coper_cod="R")
.values("af_id")
)

query_coperture = Q(af_id__in=coperture) | Q(af_master_id__in=coperture)
Expand Down
5 changes: 5 additions & 0 deletions cds/api/v1/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
ApiStudyActivityDetail,
ApiStudyPlanActivitiesList,
ApiStudyPlanDetail,
ApiCdsMorphList
)

app_name = "apiv1"
Expand All @@ -23,6 +24,10 @@
path("cds/<int:regdidid>/studyplans/<int:studyplanid>/", ApiStudyPlanDetail.as_view(), name="studyplan-detail"),
path("cds/<int:regdidid>/studyplans/<int:studyplanid>/activities/", ApiStudyPlanActivitiesList.as_view(), name="studyplan-activities"),
path("cds/<int:regdidid>/studyplans/<int:studyplanid>/activities/<int:studyactivityid>/", ApiStudyActivityDetail.as_view(), name="studyactivity-info"), # TODO same as studyactivity-detail


path("cds-morph/<str:cds_cod>/", ApiCdsMorphList.as_view(), name="cds-morph"),

path("cds-areas/", ApiCdsAreasList.as_view(), name="cds-areas"),
path("activities/", ApiAllStudyActivitiesList.as_view(), name="activities"),
path("activities/<int:studyactivityid>/", ApiStudyActivityDetail.as_view(), name="studyactivity-detail"), # TODO same as studyactivity-info
Expand Down
16 changes: 16 additions & 0 deletions cds/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
from generics.utils import decrypt
from generics.views import ApiEndpointDetail, ApiEndpointList, ApiEndpointListSupport
from organizational_area.models import OrganizationalStructureOfficeEmployee
from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import permissions
from rest_framework.schemas.openapi_agid import AgidAutoSchema


from cds.settings import OFFICE_CDS, OFFICE_CDS_DOCUMENTS, OFFICE_CDS_TEACHING_SYSTEM

Expand Down Expand Up @@ -208,3 +213,14 @@ class ApiSortingContacts(ApiEndpointList):
def get_queryset(self):
cdscod = self.kwargs["cdscod"]
return ServiceDidatticaCds.getContacts(cdscod)


class ApiCdsMorphList(APIView):
permission_classes = [permissions.AllowAny]
schema = AgidAutoSchema(tags=["api"])

description = "Retrieves a list of CDS_COD which, starting from the given one, contains all the previous CDS_COD."

def get(self, request, *args, **kwargs):
cds_cod = kwargs.get("cds_cod", None)
return Response(ServiceDidatticaCds.getPreviousCdsCods(cds_cod))

0 comments on commit 608c758

Please sign in to comment.