annuaire-eleves/fiches/utils.py

24 lines
575 B
Python
Raw Normal View History

from .management.commands._ldap import ClipperLDAP
2021-02-06 12:34:02 +01:00
def get_ldap_infos(clipper_login):
ldap = ClipperLDAP()
try:
res = ldap.search("(uid={})".format(clipper_login))
except Exception:
return None
2021-02-06 12:34:02 +01:00
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"))
2021-02-06 12:34:02 +01:00
return {
"name": ldap.extract_ldap_info(res, "cn"),
"promo": promo,
"dept": dept,
}