annuaire-eleves/fiches/utils.py

23 lines
575 B
Python

from .management.commands._ldap import ClipperLDAP
def get_ldap_infos(clipper_login):
ldap = ClipperLDAP()
try:
res = ldap.search("(uid={})".format(clipper_login))
except Exception:
return None
if not res:
return None
if len(res) != 1:
raise RuntimeError("LDAP returned too many results: {}".format(res))
(res,) = res
promo, dept = ldap.parse_dept(ldap.extract_ldap_info(res, "homeDirectory"))
return {
"name": ldap.extract_ldap_info(res, "cn"),
"promo": promo,
"dept": dept,
}