diff --git a/addressbook/api/v1/services.py b/addressbook/api/v1/services.py index e77574b0..7aa79cb8 100644 --- a/addressbook/api/v1/services.py +++ b/addressbook/api/v1/services.py @@ -9,7 +9,7 @@ PERSON_CONTACTS_EXCLUDE_STRINGS, PERSON_CONTACTS_TO_TAKE, ) -from addressbook.utils import get_personale_matricola +from addressbook.utils import get_personale_data from django.db.models import CharField, Q, Value from django.http import Http404 from structures.api.v1.serializers import StructuresSerializer @@ -366,7 +366,7 @@ def getPersonale(personale_id, full=False): Q(didatticacopertura__aa_off_id=datetime.datetime.now().year - 1) & ~Q(didatticacopertura__stato_coper_cod='R') ) else: - personale_id = get_personale_matricola(personale_id) + personale_id = get_personale_data(personale_id)['matricola'] query = Personale.objects.filter( Q(flg_cessato=0) | Q(didatticacopertura__aa_off_id=datetime.datetime.now().year) & ~Q(didatticacopertura__stato_coper_cod='R') | diff --git a/addressbook/utils.py b/addressbook/utils.py index 43a8517f..f69e76e9 100644 --- a/addressbook/utils.py +++ b/addressbook/utils.py @@ -9,9 +9,9 @@ ) -def get_personale_matricola(personale_id): +def get_personale_data(personale_id, field_to_retrieve='matricola'): if personale_id[len(personale_id) - 2:] == "==": - return decrypt(personale_id) + return {'matricola': decrypt(personale_id)} personale_model = apps.get_model("addressbook.Personale") personalecontatti_model = apps.get_model("addressbook.PersonaleContatti") @@ -22,7 +22,7 @@ def get_personale_matricola(personale_id): if not contatto: raise Http404 personale = ( - personale_model.objects.filter(id_ab=contatto.id_ab).values("matricola").first() + personale_model.objects.filter(id_ab=contatto.id_ab).values(field_to_retrieve).first() ) if not personale: raise Http404 diff --git a/laboratories/api/v1/services.py b/laboratories/api/v1/services.py index 383c6217..efb6f255 100644 --- a/laboratories/api/v1/services.py +++ b/laboratories/api/v1/services.py @@ -1,5 +1,5 @@ from django.db.models import Q -from addressbook.utils import append_email_addresses, get_personale_matricola +from addressbook.utils import append_email_addresses, get_personale_data from laboratories.models import ( LaboratorioAltriDipartimenti, LaboratorioAttivita, @@ -35,7 +35,7 @@ def getLaboratoriesList( is_active=True, ): if teacher: - teacher = get_personale_matricola(teacher) + teacher = get_personale_data(teacher)['matricola'] query_search = Q() query_ambito = Q() diff --git a/teachers/api/v1/services.py b/teachers/api/v1/services.py index fb540224..4ed7229b 100644 --- a/teachers/api/v1/services.py +++ b/teachers/api/v1/services.py @@ -5,7 +5,7 @@ PERSON_CONTACTS_EXCLUDE_STRINGS, PERSON_CONTACTS_TO_TAKE, ) -from addressbook.utils import append_email_addresses, get_personale_matricola +from addressbook.utils import append_email_addresses, get_personale_data from cds.models import DidatticaCopertura from django.db.models import Q from django.http import Http404 @@ -45,7 +45,7 @@ class ServiceDocente: @staticmethod def getAllResearchGroups(search, teacher, department, cod): if teacher: - teacher = get_personale_matricola(teacher) + teacher = get_personale_data(teacher)['matricola'] query_search = Q() query_cod = Q() @@ -141,7 +141,7 @@ def getAllResearchGroups(search, teacher, department, cod): @staticmethod def getResearchLines(teacher_id, only_active=True): - teacher_id = get_personale_matricola(teacher_id) + teacher_id = get_personale_data(teacher_id)['matricola'] query_is_active_app = ( Q(ricercadocentelineaapplicata__ricerca_linea_applicata__visibile=True) @@ -788,7 +788,7 @@ def teachingCoveragesList(search, regdid, dip, role, cds, year): @staticmethod def getAttivitaFormativeByDocente(teacher, year, yearFrom, yearTo): - teacher = get_personale_matricola(teacher) + teacher = get_personale_data(teacher)['matricola'] if year: query = DidatticaCopertura.objects.filter( @@ -863,7 +863,7 @@ def getAttivitaFormativeByDocente(teacher, year, yearFrom, yearTo): @staticmethod def getDocenteInfo(teacher, use_this_id=False): if not use_this_id: - teacher = get_personale_matricola(teacher) + teacher = get_personale_data(teacher)['matricola'] query = Personale.objects.filter( Q(fl_docente=1, flg_cessato=0) @@ -1003,7 +1003,7 @@ def getDocenteInfo(teacher, use_this_id=False): @staticmethod def getDocenteMaterials(user, teacher, search=None): - teacher = get_personale_matricola(teacher) + teacher = get_personale_data(teacher)['matricola'] query_search = Q() query_is_active = Q(attivo=True) @@ -1051,7 +1051,7 @@ def getDocenteMaterials(user, teacher, search=None): @staticmethod def getDocenteNews(user, teacher, search=None): - teacher = get_personale_matricola(teacher) + teacher = get_personale_data(teacher)['matricola'] query_search = Q() query_is_active = Q(attivo=True) @@ -1112,7 +1112,7 @@ def getPublicationsList( teacherid=None, search=None, year=None, pub_type=None, structure=None ): if teacherid: - teacherid = get_personale_matricola(teacherid) + teacherid = get_personale_data(teacherid, 'cod_fis')['cod_fis'] query_search = Q() query_year = Q() @@ -1128,7 +1128,7 @@ def getPublicationsList( if pub_type is not None: query_type = Q(collection_id__community_id__community_id=pub_type) if teacherid: - query_teacher = Q(pubblicazioneautori__ab__matricola=teacherid) + query_teacher = Q(pubblicazioneautori__codice_fiscale=teacherid) if structure: query_structure = Q(pubblicazioneautori__ab__cd_uo_aff_org=structure) query = ( diff --git a/teachers/api/v1/views.py b/teachers/api/v1/views.py index da931047..d28fefef 100644 --- a/teachers/api/v1/views.py +++ b/teachers/api/v1/views.py @@ -158,7 +158,7 @@ class ApiPublicationsList(ApiEndpointList): def get_queryset(self): request = self.request - teacherid = self.kwargs.get("teacherid") or "" + teacherid = self.kwargs.get("teacherid", "") search = request.query_params.get("search") year = request.query_params.get("year") pub_type = request.query_params.get("type")