Skip to content

Commit

Permalink
fix: addressbook detail roles
Browse files Browse the repository at this point in the history
  • Loading branch information
francesco-filicetti committed Nov 13, 2024
1 parent 6f3f641 commit cabae02
Showing 1 changed file with 53 additions and 42 deletions.
95 changes: 53 additions & 42 deletions addressbook/api/v1/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ def getPersonale(personale_id, full=False):
"profilo",
"ds_profilo",
"ds_profilo_breve",
)
).first()

ruoli = (
PersonaleAttivoTuttiRuoli.objects.filter(matricola=personale_id)
Expand Down Expand Up @@ -490,52 +490,63 @@ def getPersonale(personale_id, full=False):
d_data["dt_rap_ini"] = r[6]

roles.append(d_data)

if not roles:
roles = [{"matricola": query["matricola"],
"cd_ruolo": query["cd_ruolo"],
"ds_ruolo": query["ds_ruolo_locale"],
"priorita": 1,
"cd_uo_aff_org": None,
"ds_aff_org": None,
"cd_tipo_nodo": None,
"sede": None}]

roles.sort(key=lambda x: x["priorita"])

already_taken_contacts = []
for q in query:
for c in PERSON_CONTACTS_TO_TAKE:
q[c] = []
for c in contacts:
if not c["personalecontatti__contatto"]:
continue
res = [
word
for word in PERSON_CONTACTS_EXCLUDE_STRINGS
if (word.lower() in c["personalecontatti__contatto"].lower())
]
if (
not bool(res)
and c["personalecontatti__contatto"].lower()
not in already_taken_contacts
):
q[c["personalecontatti__cd_tipo_cont__descr_contatto"]].append(
c["personalecontatti__contatto"]
)
already_taken_contacts.append(
c["personalecontatti__contatto"].lower()
)

if len(functions) == 0:
q["Functions"] = None
else:
q["Functions"] = functions
for c in PERSON_CONTACTS_TO_TAKE:
query[c] = []
for c in contacts:
if not c["personalecontatti__contatto"]:
continue
res = [
word
for word in PERSON_CONTACTS_EXCLUDE_STRINGS
if (word.lower() in c["personalecontatti__contatto"].lower())
]
if (
not bool(res)
and c["personalecontatti__contatto"].lower()
not in already_taken_contacts
):
query[c["personalecontatti__cd_tipo_cont__descr_contatto"]].append(
c["personalecontatti__contatto"]
)
already_taken_contacts.append(
c["personalecontatti__contatto"].lower()
)

if len(roles) == 0:
q["Roles"] = []
else:
q["Roles"] = roles

q["cop_teacher"] = False
if not q["fl_docente"]:
query_teacher = Personale.objects.filter(
Q(didatticacopertura__aa_off_id=datetime.datetime.now().year)
| Q(didatticacopertura__aa_off_id=datetime.datetime.now().year - 1),
didatticacopertura__af__isnull=False,
matricola__exact=personale_id,
).exists()
if query_teacher:
q["cop_teacher"] = True
if len(functions) == 0:
query["Functions"] = None
else:
query["Functions"] = functions

if len(roles) == 0:
query["Roles"] = []
else:
query["Roles"] = roles

query["cop_teacher"] = False
if not query["fl_docente"]:
query_teacher = Personale.objects.filter(
Q(didatticacopertura__aa_off_id=datetime.datetime.now().year)
| Q(didatticacopertura__aa_off_id=datetime.datetime.now().year - 1),
didatticacopertura__af__isnull=False,
matricola__exact=personale_id,
).exists()
if query_teacher:
query["cop_teacher"] = True

if not query:
raise Http404
Expand Down

0 comments on commit cabae02

Please sign in to comment.