Skip to content

Commit

Permalink
fix: refactor addressbook.utils.get_personale_matricola
Browse files Browse the repository at this point in the history
  • Loading branch information
francesco-filicetti committed Dec 11, 2024
1 parent 608c758 commit 08d19a4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 17 deletions.
4 changes: 2 additions & 2 deletions addressbook/api/v1/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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') |
Expand Down
6 changes: 3 additions & 3 deletions addressbook/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions laboratories/api/v1/services.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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()
Expand Down
18 changes: 9 additions & 9 deletions teachers/api/v1/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand All @@ -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 = (
Expand Down
2 changes: 1 addition & 1 deletion teachers/api/v1/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 08d19a4

Please sign in to comment.